|
What type is the original array?
61, 62 etc. are hexadecimal representations of a, b etc.
The corresponding ascii value is 97, 98 etc.
If you have a numeric array, you could either convert each item to string using ToString and then use Int32::Parse and Console::WriteLine -
foreach (int i in myarray)
{
int ii = int::Parse(i.ToString(), NumberStyles::HexNumber);
Console::WriteLine("{0} {1:X}", Convert::ToChar(ii), ii);
}
|
|
|
|
|
I am trying to learn to write some TCP/IP code and will receive data as just a bunch of bytes. It can be a char array or a byte array. The important part is suffing the data into some type of string so that I can write it to the display. I'll put text in the left 40 characters replacing non-printables with .. and show the data as hex in the right 40 characters. That way the sender can send anyting and I can see that its being sent and received correctly.
I am using a console based project in Visual Studio C++ just to get something going quickly.
Thanks for your time
|
|
|
|
|
If you have a char array, the code that I posted must pretty much work.
|
|
|
|
|
Then I am missing a few things in your post.
foreach (int i in myarray)
{ int ii = int::Parse(i.ToString(), NumberStyles::HexNumber);
Console::WriteLine("{0} {1:X}", Convert::ToChar(ii), ii);
}
Wyere is myarray referenced?
There is an int on the left side of the =.
I would like to put the data into some kind of a string or character variable then send it out.
The WriteLine will send out a new line for each iteration. WriteLine can be changed to Write, but I still want to build an character based variable.
Thanks for your time
|
|
|
|
|
As per your original post you said the program gets an array.
myarray is assumed to be that array.
If you do not have it, you got to create it.
You could create a string variable and use string::Format instead of Console::WriteLine to do what you want to do.
They are very similar.
|
|
|
|
|
Please show me how to fix this fragment so it will compile and run in a console application
Cstring stuff;
for( i = 0, i < 80; i++ )
stuff += char(i);
Console::Writeline( stuff );
Thanks for your time
|
|
|
|
|
You're mixing up stuff here.
CString is an MFC/ATL class and Console::WriteLine is a .Net C++/CLI method.
I'm guessing you're using MFC, in which case you cannot use Console::WriteLine .
Use printf instead like this - printf("%s", stuff);
If you're doing a UNICODE build you must must either use wprintf instead of printf or use printf like so - printf("%S", stuff);
|
|
|
|
|
Yes, I know it does not work. That's why I'm here. Lets try again:
<unknown> show_stuff;
for( i = 0; i < 80; i++)
show_stuff[0] = <some_function>( i );
Console::Writeline( show_stuff );
Please correct my errors and re-write into something that will compile with C++ in a Visual Studio 2008 console application.
Thanks for your time
|
|
|
|
|
char show_stuff[80];
for (int i = 0; i < 80; ++i)
show_stuff[i] = i;
printf("%s\n", show_stuff); This will not give you the desired output as some elements of the array are data that cannot he printed.
|
|
|
|
|
I was hoping to find something more up to date than just an array of bytes. But I'll forget that and forget the CONSOLE::Write() options and just use the concept of:
char some_str[80];
int index = 0;
int low = (int)'A';
int high = (int) 'z';
for( int i = 50; i< 110; i ++ )
{
if( i >= low && i <= high )
some_str[index] = (char) i;
else
some_str[index] = '.';
index ++;
}
some_str[ index ] = 0;
printf( "data: %s", some_str );
Thanks for your time
|
|
|
|
|
You are asking in the wrong forum: C/C++/MFC is for native code. Your code snippet use the .NET Framework then the right forum is Managet C++/CLI
|
|
|
|
|
is this the fastest way to access the RGB values of a pixel of a bitmap file in c#?
the code is below
bm is previously declared Bitmap object.
Collapse
BitmapData bmd=bm.LockBits(new Rectangle(0, 0, 10, 10), System.Drawing.Imaging.ImageLockMode.ReadOnly, bm.PixelFormat);
int PixelSize=4;
for(int y=0; y<bmd.Height; y++)
{
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<bmd.Width; x++)
{
row[x*PixelSize]=255;
}
}
OR is there more faster way exists to access the RGB values of a pixel in C# or in VC++?
if in VC++ we can access the RGB values more faster than this so please help me.
and if the above method is the fastest way and no other faster method exists than this in c# or in VC++ so please comment as well.
thanks
|
|
|
|
|
That is the fastest way, as you access directly to the raw data of the image. Anyway, be aware that you are assuming the bitmap to be 32 bpp; you code will not work properly with 24 bpp, 16 bpp, 8 bpp, grayscale and B/W bitmaps.
|
|
|
|
|
inayathussaintoori wrote: Is this the fastest way
No, it isn't. Calling a property in a for test is a bad idea. And you're in the wrong forum.
|
|
|
|
|
sir in which forum should i post this question?
|
|
|
|
|
Where you have already posted it! I've just seen the same post on the C# forum.
Please, don't cross post; it's too much better to choose the right forum and post a question only once.
|
|
|
|
|
In the C# forum is fine, as you are using C#; and not here, your question does not relate to C/C++/MFC.
|
|
|
|
|
yes you are right and thanks for the comment but i have posted my question in both forums because i was thinking that c++ may have faster way to access the pixels than c#.infact i was confused therefore i had posted in the both forums..
thanks to all of you.
|
|
|
|
|
While talking about bitmap manipulation, you can do almost the same things with C/C++ and C#. Be aware that if an API is not available in C# you can always use the P-Invoke to access it.
|
|
|
|
|
Hi,
Please tell me how can i replace the default list box of a combo box with a custom made one. I have made a subclassed listbox. I want to show this listbox when user clicks on the down arrow of combo box.
Thanks in advance,
John.
|
|
|
|
|
|
Thanks for the link.
I was trying the approach described in the following link
How to subclass CListBox and CEdit inside of CComboBox
I have created an ownerdrawn combobox and subclassed CComboBox and overridded all required methods such as[OnDrawItem,MeasureItem,etc] and WM_CTLCOLOR. I can see the code hits the OnDrawItem,MeasureItem,etc but it is never coming to OnCtlColor.
Can someone help me by pointing out what i am doing wrong?
HBRUSH CComboBoxEx2::OnCtlColor(CDC *pDC,CWnd *pWnd,UINT nCtlColor)<br />
{<br />
<br />
<br />
if (nCtlColor == CTLCOLOR_EDIT)<br />
{<br />
<br />
}<br />
else if (nCtlColor == CTLCOLOR_LISTBOX)<br />
{<br />
<br />
}<br />
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);<br />
return hbr;<br />
<br />
}<br />
<br />
void CComboBoxEx2::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)<br />
{<br />
<br />
}<br />
<br />
void CComboBoxEx2::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)<br />
{<br />
<br />
<br />
CComboBox::DrawItem(lpDrawItemStruct);<br />
}<br />
<br />
void CComboBoxEx2::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)<br />
{<br />
<br />
CComboBox::MeasureItem(lpMeasureItemStruct);<br />
}<br />
<br />
int CComboBoxEx2::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)<br />
{<br />
<br />
<br />
return 0;<br />
}
|
|
|
|
|
How can I change the background color of my CComboBox , but only in the edit area , not dropdown list ?
I have something like :
class CStatusCombo : public CComboBox
and here :
HBRUSH CStatusCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_LISTBOX:
pDC->SetTextColor(RGB(0, 255, 0));
pDC->SetBkColor(RGB(120,120,120));
return (HBRUSH)(m_pEditBkBrush->GetSafeHandle());
}
return hbr;
}
I change background of the list area , not the edit area of the combo ... I would like to change the color of edit area just like the statusbar color ... it could be soemthing like that ?
modified on Saturday, October 23, 2010 2:03 PM
|
|
|
|
|
Doesn't CTLCOLOR_EDIT work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
No , I try but didn't work ...
|
|
|
|