Hey guys,

I have a dialog, which i load with CreateDialogParam(). On that dialog, i have 5 edit boxes. In my dlgProc, i intercept the WM_CTLCOLOREDIT message so that i can set the backcolor of the edit boxes (each one is set to a different color). This is the segment of code i use to set the color:


invoke CreateSolidBrush, ;esi points at a RGB'd dword
mov dlgProcBrush, eax ;save the brush handle, so i can destroy it later
ret ;exit function, with brush handle in eax


all this is working okay. The problem is, after i handle the WM_CTLCOLOREDIT for the last edit box, i keep on receiving zillions more of the same message for the very same edit box, this ends up producing a very bad flicker on that edit box while the dialog is showing. This doesn't affect any of the other edit boxes, just the last one painted. What is happening here? Is there a 'gotcha' that i am missing?


This one has got me stuck, i appreciate any suggestions :)
Posted on 2001-10-19 06:34:30 by sluggy
Hi sluggy

In a dialog I set the color of some static boxes and use this.



.elseif uMsg==WM_CTLCOLORSTATIC
invoke GetWindowLong,lParam,GWL_ID
.if eax>=IDC_STCEDTCOL1 && eax<=IDC_STCKEYCOL9
sub eax,IDC_STCEDTCOL1
shl eax,2
add eax,offset lColorArray
mov eax,dword ptr [eax]
invoke CreateSolidBrush,eax
ret
.endif
mov eax,FALSE
ret
.else
mov eax,FALSE
ret
.endif



Maybe I am wrong but I expect the brush to be destroyed.

KetilO
Posted on 2001-10-19 06:56:55 by KetilO
And a litte RadASM project.

KetilO
Posted on 2001-10-19 07:31:11 by KetilO
Hi ketilO,

my code looks very similar to yours, i index into an array holding colors, the index depends on what edit box sent the message. The only difference was, i was also sending a WM_SETTEXT directly to the edit box in the WM_CTLCOLOREDIT handler (so there was one letter per edit box); as soon as i stopped sending the WM_SETTEXT message the flicker stopped, problem solved ;)


Maybe I am wrong but I expect the brush to be destroyed.

According to the doco, the system doesn't destroy the handle, it is up to the user to do that, which is why i keep a copy of it in a global variable, if the variable is not null it must contain a handle that i need to send to DestroyObject().

Thanks for the answer :)
Posted on 2001-10-19 07:31:21 by sluggy
Hi Sluggy

What was I thinking, surely you are right. The WM_CTLCOLOREDIT is sent whenever the edit box needs to be painted, so setting the text within the event is not a good idea.

KetilO
Posted on 2001-10-19 07:41:26 by KetilO