borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (API CALLS IN VB)Next Topic (Api functions?) New Topic New Poll Post Reply
AndreaVB Forum : API : How to process WM_CTLCOLORBTN?
Poster Message
toughcoder
Level: Guest


icon How to process WM_CTLCOLORBTN?

Greetings every1,
I wanted to change the face color of the buttons in my application. So i tried using the SetSysColors API. What it did was change the face color of other applications also. I read on the MSDN site that  WM_CTLCOLORBTN can b caught for processing the background & text color of a button. Can any1 show me how to do this with a simple example. Thanx in advance...

18-08-2004 at 08:57 PM
| Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: How to process WM_CTLCOLORBTN?

1. Create a UserControl and subclass a Windows BUTTON window.
2. Intercept the WM_CTLCOLORBTN message in your WndProc procedure.
3. Using the hdcButton and hwndButton values provided in the
WM_CTLCOLORBUTTON message, use the SetTextColor API to set the foreground
color of the button.
4. You may want to use the OleTranslateColor API from the OLE_COLOR value
stored in your Foreground property to a COLORREF Windows color value.

14-02-2005 at 08:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
mnbvcx
Level: Trainee

Registered: 31-08-2005
Posts: 1
icon 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

31-08-2005 at 04:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : How to process WM_CTLCOLORBTN?
Previous Topic (API CALLS IN VB)Next Topic (Api functions?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder