mnbvcx Level: Trainee
 Registered: 31-08-2005 Posts: 1
|
URGENT: How to change the color of a owner drawn button
HI all.. i am trying to change the background colour of a button.. for this first i destroyed that button and again calling the WM_CREATE function.. i read that whenever we call WM_CREATE function it implicitly calls the WM_DRAWITEM so that it will redraw the button.. but in practical its not happening.. only for the first timeWM_CREATE is calling that WM_DRAWITEM and in all the other cases its just calling that WM_CREATE function ..for ur easy understanding i am giving the piece of code here...
case WM_CHAR
{
switch(wParam)
{
case 0x01: // 1 from keyboard
hl[1]=1; // var for chging the color of btn
DestroyWindow(hWndButton101);
SendMessage(hWnd,WM_CREATE,0,0);
case 0x02:
// sme other conidtions
.. like this i have so many cases for each input frm keyboard
}
}
in WM_CREATE:
{
it creates buttons by using CreateWindow();
}
its working fine
in WM_DRAWITEM:
{
i put a condition that
if(hl[1]==1)
SetBkColor(hdc,rgb(10,10,10));
else
SetBkColor(hdc,rgb(256,240,240));
}
for the first time i press 1 then its working fine.. but when i press 2 its not highlighting the second button.. i followed the same procedure for case 0x02 also in the WM_CHAR.. but its just calling that WM_CREATE but not WM_DRAWITEM.. so what i have to do to change the background color of the button...
in this meanwhile i came across through WM_CTLCOLORBTN..
so i put this in my code..
case WM_CTLCOLORBTN:
{
switch(wParam)
{
case IDC_OWNERDRAWN:
{
if(hl[1]==1)
{
SetBkColor(hdc,rgb(10,10,10));
hl[1]=0;
}
else
SetBkColor(hdc,rgb(240,240,240);
}
like tis rmng cases....
}
}
its calling this WM_CTLCOLORBTN every time.. even i put msg boxes for every time the ctrl enters into it.. when i press 1 from keyboard.. its entering into the switch and cheking that case.. but then its showing that First-Chance Exception... i am not understanding wt i have to do for changing the color of a button... could any one give the proper suggestion.. in this program all are ownerdrawn buttons...
plz reply me immediately..
thank u in advance
|