Link to home
Start Free TrialLog in
Avatar of andla
andla

asked on

Cant make the WM_CTLCOLORBTN to work. Please help.

#include "windows.h"

 

   BOOL WINAPI MainDlgProc( HWND, UINT, WPARAM, LPARAM );


 

   int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd,
                         int nShow )
   {                                    
             DialogBox( hInstance, MAKEINTRESOURCE( 10000 ), NULL, (DLGPROC)MainDlgProc );
      return( FALSE );
   }


 HBRUSH kulle,drulle;
   BOOL WINAPI MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
   {


      switch( msg )
      {
         case WM_INITDIALOG:      
                               {
             
                                     
                                          

                                    kulle=CreateSolidBrush( RGB( 0, 128, 128 ));
                                    drulle=CreateSolidBrush( RGB( 0, 0, 228 ));
                                          
                  
            return( TRUE );
                         }


        case WM_CTLCOLOREDIT:

                               SetTextColor( (HDC)wParam, RGB( 155, 55, 255 ) );
                              SetBkColor( (HDC)wParam, RGB( 55, 55, 255 ) );
            
      ;
                               return( (BOOL)kulle );
                               
                         case WM_CTLCOLORBTN:

                               if( GetWindowLong( (HWND)lParam, GWL_ID ) == 101 )  
            {
                                     
               SetBkColor( (HDC)wParam, RGB( 0, 25, 255 ) );      
               SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
            
              return( (BOOL)drulle );
            }
                              if( GetWindowLong( (HWND)lParam, GWL_ID ) == 102 )    
            {
               SetBkColor( (HDC)wParam, RGB( 0, 125, 255 ) );      
               SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );        
                                           return( (BOOL)drulle );
            }
                              return((BOOL)drulle );
                        break;

         case WM_COMMAND:
            if( wParam == IDCANCEL )
            {
               if( kulle )        
                                           {
                  DeleteObject( kulle );
                                                      DeleteObject( drulle );
                                           }
               EndDialog( hDlg, TRUE );    
                                           return( TRUE );                              
                                    }
            break;
      }
      return( FALSE );
   }                                                  
---------------------------------------------------
//Resourcefile
10000 DIALOGEX 6, 18, 160, 113
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Color Read-Only Edit Control"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "Button1",101,4,5,34,14,NOT WS_TABSTOP,WS_EX_TRANSPARENT
    EDITTEXT        100,3,24,151,69,ES_AUTOHSCROLL
END
Avatar of nietod
nietod

If you read the documentation for the WM_CTLCOLORBTN message carefully you will find that the brush returned is not used!.  In addition, only the DC's text color is used and it is not used to affect the text in the button  it affects the color of the focus rectangle only.  Thus, the only thing you can do with this message is to set the color of the button's focus rectangle.
The documentation that nietod is referring to:
The text color of a check box or radio button applies to the box or button, its check mark, and the text. The focus rectangle for these buttons remains the system default color (typically black). The text color of a group box applies to the text but not to the line that defines the box. The text color of a push button applies only to its focus rectangle; it does not affect the color of the text.


Avatar of andla

ASKER

What shall i do to change the color of the button backgroung then. I don't like the gray color.

Yours sincerely
Andla :-)
You need to subclass the button and draw it yourself.
ASKER CERTIFIED SOLUTION
Avatar of marvinm
marvinm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial