c++ - Change text color on button push WIN32 -
how change text color edit box on button push? (win32/c++). know how change text font (i.e. use in wm_command
, sendmessage()
wm_setfont
).
on changing text color think need interaction betweenwm_command
, wm_ctlcoloredit
, , sendmessage()
don't know kind of parameter . thank you.
i've figured how on single button. 1 more question please. if use code above 3 different buttons, doesn't behave expected . there snippet :
case idc_button3: textflagred = textflagred; textflagblue = !textflagblue; textflaggreen = !textflaggreen; invalidaterect(textarea2, null, true); break; case idc_button4: textflaggreen = textflaggreen; textflagblue = !textflagblue; textflagred = !textflagred; invalidaterect(textarea2, null, true); break; case idc_button5: textflagblue = textflagblue; textflagred = !textflagred; textflaggreen = !textflaggreen; invalidaterect(textarea2, null, true); break;
and in wm_ctlcolorstatic
if (textflagred && (hwnd)lparam == textarea2) { hbrush hbr = (hbrush) defwindowproc(hwnd, message, wparam, lparam); settextcolor((hdc) wparam, rgb(255, 0, 0)); return (bool) hbr; } else if (textflagblue && (hwnd)lparam == textarea2) { hbrush hbr = (hbrush) defwindowproc(hwnd, message, wparam, lparam); settextcolor((hdc) wparam, rgb(0, 0, 255)); return (bool) hbr; } else if (textflaggreen && (hwnd)lparam == textarea2) { hbrush hbr = (hbrush) defwindowproc(hwnd, message, wparam, lparam); settextcolor((hdc) wparam, rgb(0, 255, 0)); return (bool) hbr; } break;
always blue color.
you need to
a) global boolean indicate if colour needs chaanged (say beditred
)
b) on button push: set/toggle beditred
, invalidate edit box invalidaterect(hwndedit, null, true)
c) handle `wm_ctlcoloredit' message in dialog proc:
case wm_ctlcoloredit: if (beditred && (hwnd)lparam == hwndedit) { hbrush hbr = (hbrush) defwindowproc(hdlg, imessage, wparam, lparam); settextcolor((hdc) wparam, rgb(255, 0, 0)); return (bool) hbr; } return false;
Comments
Post a Comment