|
Well, at least you're getting a handle on things. Gives a good feeling though, doesn't it.
Regards,
Bram van Kampen
|
|
|
|
|
I have a structure:
typedef struct{
unsigned short Id : 8;
unsigned short Name: 8;
unsigned short Length: 11;
unsigned short Value: 5;
} MyStruct;
I also have an array of bytes (unsigned char):
I want to stick that structure into the first four bytes in the array.
Array[0] = MyStruct->Id;
Array[1] = MyStruct->Name;
...then what?
How can I divide the last two values and put them into the [2] and [3] position in the byte array?
|
|
|
|
|
|
Please note sizes are identical. Methods
(1) quick & dirty: copy memory
MyStruct m;
unsigned char a[4];
memcpy(a, &m, sizeof(a));
(2) perhaps more elegant: use union
typedef union
{
MyStruct m;
unsigned char a[4];
}MyUnion;
MyUnion mu;
unsigned char array[4];
for (i=0; i<4; i++)
{
array[i]=mu.a[i];
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It looks like the memcpy might work. I didn't really want to go the route of using a Union.
I was actually looking for a method to do this using bit shifting.
Something like...
unsigned char NewChar = MyStruct->Length << 8;
which would put the 8 leftmost bits in Length into the NewChar, which you could put into Array[2];
but then, how do I get the other three bits from Length and merge them with the 5 bits from MyStruct->Value?
I kind of know what I want to do it, but I don't know exactly how, what commands to use or what I'm doing.
|
|
|
|
|
Just for the academy (since memcpy is more concise and probably faster).
MyStruct m;
unsigned char a[4];
a[2] = (unsigned char) m.Length;
a[3] = (m.Length >> 8) | (m.Value << 3);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Cool.
That's what I was looking for originally. But the memcpy works.
THANKS!
|
|
|
|
|
|
"how to set background color ?"
Hi ,
U can handle WM_CTLCOLORDLG to change the background color of the dialog.
In the link u have given, the code is not returning the handle to the new bursh u want to set for the dialog. See what msdn says
"OnCtlColor must return a handle to the brush that is to be used for painting the control background".
In the code u r returning the default brush handle. so that may the problem of not changineg the background color.
and change your code like this
<br />
if(nCtlColor == CTLCOLOR_DLG)<br />
{<br />
hbr = CreateSolidBrush(RGB(2,22,222));<br />
}<br />
thanks
Nitheesh
modified on Friday, April 11, 2008 10:58 AM
|
|
|
|
|
Dear Nitheesh,
I am still not able to change the background color after I tried the code below. As I'm a beginner of c++, would you please point out the deficit or improper use of code. Thank you very much!
HBRUSH CMyAppView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CScrollView::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG)
{
hbr = CreateSolidBrush(RGB(2,22,222));
}
return hbr;
}
Cheers,
john
|
|
|
|
|
You can use ofWM_CTL* for change color of buttons,dialog,static control and....
|
|
|
|
|
Hi All,
I am enumerating the network adapters by using the GetAdaptersInfo() API. But, I am not able to distinguish between the ethernet and wireless network as both the adapters are having the type as MIB_IF_TYPE_ETHERNET. Does anyone have an idea?
Thank you,
AJ
|
|
|
|
|
Looking at the documentation on MSDN GetAdaptersInfo( ) doesn't return that much detail and has been superseded by GetAdaptersAddresses[^] as of Windows XP, however even that only looks like it will differentiate between wired and wireless on Vista and not XP.
Gavin Taylor
|
|
|
|
|
Hi all,
I want to change default blue color of title bar for my SDI window.
I tried painting title bar area through OnNcPaint() but Icon, Caption,Buttons gets disappear, on mouse over buttons appear.
help me with some solution
thanks
|
|
|
|
|
SetSysColor<br />
GetSysColor
Hope it helps.
|
|
|
|
|
Yes it helps for system windows..
in my SDI appln,
CWnd* pWnd = CMainFrame::GetActiveWindow();
pWnd-> doesnt have setsyscolor or getsyscolor.
how could i get these functions to my CMainframe (constructor or create)
i NEED TO CHANGE ACTIVECAPTION/INACTIVECAPTION Colors.
thanks
|
|
|
|
|
It's a api function, just call ::GetSysColor /::SetSysColor .
Use parameters like:
COLOR_GRADIENTACTIVECAPTION<br />
COLOR_GRADIENTINACTIVECAPTION
|
|
|
|
|
AFAIK, if you handle OnNcPaint, you need to do everything (redraw everything )
(but I might be wrong).
|
|
|
|
|
u r right ..if i handle NCPAINT i got to redraw each and evrything in title bar on my own.
Instead iam looking for some solution from which i can change color of Title bar without disturbing caption text,icon,standard buttons.
|
|
|
|
|
Did you search on the codeproject it has good articles.
|
|
|
|
|
yes i searched through and got one MDI application who does exactly what i wanted but he paints customised title bar on exhisting default bar by using subclass technique by Paul DiLascia(MS journal).
my client doesnt allow me to add custom class for this kind of need.
|
|
|
|
|
SDI, can't CMyApp::OnFileNew handle the the click message by the button?
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
m_btnNew.Create(NULL,style,rcDummy,this,ID_FILE_NEW);
m_btnNew.LoadBitmaps(IDB_NEW,IDB_NEW_DOWN);
}
|
|
|
|
|
Hi,
have you mapped the WM_COMMAND to CWinApp::OnFileNew.?
thanks
Nitheesh
|
|
|
|
|
No, I just created a button using ID_FILE_NEW.
|
|
|
|
|
hi,
then u have to map the WM_COMMAND for the Button Id in following way. ON_COMMAND(ID_FILE_NEW,CWinApp::OnFileNew)
thanks
Nitheesh
|
|
|
|