|
Hello Friends
I am creating a win32 based application. Creating A Dialog with TabControl and Buttons using BS_OWNERDRAW as i want to set the color of button.
On WM_DRAWITEM, I implemented a function to set the color of button[ by getting all dc and rect of button and then fillrect).
So,when I open the Dialog, it is showing Initial Color Fine.
Now,I want to change the colors of button when I change the Tab. But,I am not able to find the Event or same WM_DRAWITEM will change button color on changing tab.
So,On Tab change,button colors remain same. How can I change the button color on Tab change.
Thanks & Regards
Yogesh
|
|
|
|
|
The right message (to handle) for changing button's color is WM_CTLCOLORBTN
|
|
|
|
|
But when this message(WM_CTLCOLORBTN) will be called ?
How can I handle this ?
Need little explanation.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
It will be sent to the parent window (in your case the dialog) just before the button is painted. So handle it in your dialog's DlgProc function by creating a brush in the background color that you want, casting it to BOOL and returning it. See MSDN for details.
http://msdn.microsoft.com/en-us/library/aa930774.aspx[^]
|
|
|
|
|
I took HBRUSH as Global variable and then how it will be responsible for drawing all buttons and with different color.
Here is WM_DRAWITEM:
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpDrawItemStruct = (DRAWITEMSTRUCT*)lParam;
switch (lpDrawItemStruct->itemAction)
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
{
int ndxColor = 0 ;
switch (lpDrawItemStruct->CtlID)
{
case IDC_btnPantone1 : ndxColor = 0 ; break ;
case IDC_btnPantone2 : ndxColor = 1 ; break ;
case IDC_btnPantone3 : ndxColor = 2 ; break ;
case IDC_btnPantone4 : ndxColor = 3 ; break ;
case IDC_btnPantone5 : ndxColor = 4 ; break ;
case IDC_btnPantone6 : ndxColor = 5 ; break ;
case IDC_btnPantone7 : ndxColor = 6 ; break ;
default : break ;
}
switch (lpDrawItemStruct->CtlID)
{
case IDC_btnPantone1 :
case IDC_btnPantone2 :
case IDC_btnPantone3 :
case IDC_btnPantone4 :
case IDC_btnPantone5 :
case IDC_btnPantone6 :
case IDC_btnPantone7 :
DrawButtonColor (ndxColor, lpDrawItemStruct) ;
break ;
default : break ;
}
}
default:
return DefWindowProc (hwndDlg, msg, wParam, lParam);
break;
break;
}
return TRUE;
}
case WM_CTLCOLORBTN :
{
SetBkColor((HDC)wParam, RGB(0,0,255));
return (BOOL)g_hBrush;
}
it is not changing .
Or m wrong somewhere ?
|
|
|
|
|
No need to use SetBkColor(). Windows uses the returned brush to paint the background.
Check the color used for g_hBrush.
|
|
|
|