|
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 ...
|
|
|
|
|
How about CTLCOLOR_STATIC?
> 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 <
|
|
|
|
|
It was go with CTLCOLOR_EDIT , but only when I type letters into combo control , when not the background color remain white ...
|
|
|
|
|
I just realized that you are hancling the control-color message in the combo box itself, not in its parent. Did you try with ON_WM_CTLCOLOR_REFELECT or ON_WM_CTLCOLOR?
> 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 <
|
|
|
|
|
You have to subclass the edit control of the combo box, since a combo box is a combined control. Here is an article[^] from Microsoft support describing how to do so.
|
|
|
|
|
I do what they said to , I put the change background code , but in vain ... still don't function ...
|
|
|
|
|
I've just tried it with an MFC dialog application. It's not perfect because the color change doesn't "stick" when the edit control has the focus but it comes back when you tab away from the combo box. You'd need to do some more work to make it work the way you want when the edit control has the focus, but this should give you a starting point.
The class that I derived from CComboBox is named CColorEditCombo . In the Visual Studio designer I added a CComboBox control to the dialog window. With the ClassWizard I added a CComboBox control variable named m_ctlComboColorEdit . Then in the header file for the dialog class I changed the declaration for this variable to the following:
CColorEditCombo m_ctlComboColorEdit;
This associates that control with the new CColorEditCombo class rather than the parent CComboBox class. In the class file for CColorEditCombo I added a handler for the WM_CTLCOLOR message as follows:
HBRUSH CColorEditCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
if (m_edit.GetSafeHwnd() == NULL)
{
m_edit.SubclassWindow(pWnd->GetSafeHwnd());
}
pDC->SetBkColor(RGB(255, 255, 0));
m_brush.DeleteObject();
m_brush.CreateSolidBrush(RGB(255, 255, 0));
hbr = (HBRUSH) m_brush.GetSafeHandle();
return hbr;
case CTLCOLOR_LISTBOX:
if (m_listBox.GetSafeHwnd() == NULL)
{
m_listBox.SubclassWindow(pWnd->GetSafeHwnd());
}
}
return hbr;
}
Note the member variable named m_brush . This has to be declared in the header file for the CColorEditCombo class as a CBrush object. It should be deleted in the class destructor as well as just before the CreateSolidBrush statement shown above.
If you'd like, I can send you the solution for the very simple MFC dialog application I put together as a test to make sure this procedure works. You'll have to give me your email address and tell me which version of Visual Studio you are using.
modified on Wednesday, October 27, 2010 1:52 PM
|
|
|
|
|
I want to thank you for your solution , I will try it , and let you know if I did it ! I use VC6 .
|
|
|
|