c++ - Changing backgound color of a subclassed button in Win32 -


i want change background color of button in runtime.

the problem is, button not have black background code should produce. instead, looks has arrow of drop-down control on it.

what doing wrong here?

first subclassed button:

// hwnd hparent parent window // hinstance hinstance current module hwnd h = createwindow("button", null, ws_child | ws_visible | ss_ownerdraw,                        340, 10, 20, 20,                        hparent, null, hinstance, null);  setwindowsubclass(h, &mywndproc, mybuttonid, null); 

the id defined as:

enum {     mybuttonid = 100, }; 

and subclass procedure:

lresult callback mywndproc (hwnd hwnd, uint msg, wparam wparam, lparam lparam, uint_ptr uidsubclass, dword_ptr dwrefdata) {     if( uidsubclass == mybuttonid )     {         switch( msg )         {         case wm_erasebkgnd:             {                 hdc dc = (hdc)wparam;                 setbkcolor(dc, rgb(127,127,127));                 return 0;             }         }     }     return defsubclassproc(hwnd, msg, wparam, lparam); } 

you did not pass button id createwindow function, button not have id think does.

the setbkcolor not set backgrounds buttons. sets backgrounds subsequent calls textout.

you meant use bs_ownerdraw, not ss_ownerdraw.

when use owner draw style have draw button background , text , border. in parent window handler wm_drawitem. don't need subclass button @ all.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -