c++ - Can't change background of window -


i develop win32 app , create color chooser using this example. update if statement this change background of app when user click "ok" in color dialog box, nothing change. mistake?

if (choosecolor(&cc) == true) {     hbrush hbrush = createsolidbrush(cc.rgbresult);     rgbcurrent = cc.rgbresult;     setclasslongptr(hwnd, gclp_hbrbackground, (long)hbrush); } 

the following code work.

first, setclasslongptr() returns previous value, is, in case, hbrush set window class(hwnd). should delete object avoid memory leak.

after that, calling invalidaterect() brings color change effect. because newly created brush used when window needs repainted.

invalidaterect() sends wm_erasebkgnd window.

if (choosecolor(&cc) == true) {     hbrush hbrush = createsolidbrush(cc.rgbresult);     hbrush holdbrush = (hbrush)setclasslongptr(hwnd, gclp_hbrbackground, (long_ptr)hbrush);      deleteobject(holdbrush);     invalidaterect(hwnd, null, 1); } 

Comments