Featured post
winapi - Static Control Background Color with C++ -
i creating basic gui windows api , have run issue. starts main window opens custom background color set (rgb(230,230,230))
. displays text in upper left corner static control.
settingstext = createwindow("static", "settings", ss_left | ws_child, 12, 20, 100, 20, hwnd, null, proginstance, null); showwindow(settingstext, 1);
this works, when text displayed need way change background of match main window or else looks doesn't blend in.
my question is, how do this? use method below , works, wanted know, there way permanently set background color somehow, right after createwindow
function static control without changing system colors, , have apply 1 control , not sends wm_ctlcolorstatic
message. have experimented around using getdc
function , setbkcolor
function outside of message loop nothing works.
case wm_ctlcolorstatic: { hdc hdcstatic = (hdc) wparam; settextcolor(hdcstatic, rgb(0,0,0)); setbkcolor(hdcstatic, rgb(230,230,230)); return (int_ptr)createsolidbrush(rgb(230,230,230)); }
i want because...
- i don't want fill message loop functions need called every time window repaints.
- have changes apply static control.
i thankful provided, @ least pointing me in right direction, thanks.
for static text controls there's no permanent way set text color or background. if want apply changes single static control; still have handle wm_ctlcolorstatic notification message in parent dlgproc when control drawn.
static hbrush hbrush = createsolidbrush(rgb(230,230,230)); case wm_ctlcolorstatic: { if (settingstext == (hwnd)lparam) //or if handle unavailable you, ctrl id dword ctrlid = getdlgctrlid((hwnd)lparam); //window control id if (ctrlid == idc_static1) //if desired control { hdc hdcstatic = (hdc) wparam; settextcolor(hdcstatic, rgb(0,0,0)); setbkcolor(hdcstatic, rgb(230,230,230)); return (int_ptr)hbrush; } }
if you're looking make control's background transparent on parent dialog use setbkmode(hdcstatic, transparent)
.
- Get link
- X
- Other Apps
Comments
Post a Comment