News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Force background erase of a static control

Started by jj2007, October 28, 2011, 09:27:14 PM

Previous topic - Next topic

jj2007

Quote from: dedndave on October 29, 2011, 07:33:41 PM
and - what do you do for WM_ERASEBKGND ?
if it does not exit with the correct return value or does not go to DefWindowProc, you may have troubles

Not handled...

ToutEnMasm


Perhaps that the icon format is not supported by the static control.
Find a function who translate it in a bitmap format (I know none) and all will work as other formats(jpg..).

jj2007

Yves,
  CASE WM_PAINT
invoke GetClientRect, hWnd, addr rc
invoke MoveWindow, hStatic, 0, 0, rc.right, rc.bottom, 1
ImgPaint hStatic, 0, "\masm32\RichMasm\icons\Bell.ico"

... works just fine. The problem is transparency, see below. Workaround is FillRect but I was hoping for another solution...

dedndave

i like it   :bg

there is another way to go....
pick an icon that has no transparency or modify the icon by filling it in
one way to do that is to put the icon on the desired background, then copy it to a bitmap

dedndave

i am a little confused as to how you created the static control, however   :P
if you used the pre-defined system class, it should have a background color, defined by the class 'static'
for example, when an icon is placed in a MessageBox, it uses a static control
that class has a WNDCLASSEX.hbrBackground member that i believe is COLOR_BTNFACE+1

qWord

Static controls have the class style CS_PARENTDC. If you do not clip the statics region while drawing, you will paint over the controls content. The Window-style WS_CLIPCHILDREN should help in this case...
FPU in a trice: SmplMath
It's that simple!

jj2007

There is nothing strange in the creation of the static except that I saved a WM_CREATE handler. And the children are clipped, too...
LOCAL msg:MSG, wcex:WNDCLASSEX
call ClearLocVars ; zero WNDCLASSEX
ebxNull equ <ebx>
xor ebx, ebx ; ebxNull
lea esi, wcex
wc equ <[esi.WNDCLASSEX]>
m2m wc.cbSize, WNDCLASSEX
m2m wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
m2m wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszClassName, Chr$("MB GUI")
mov wc.hInstance, rv(GetModuleHandle, ebxNull)
mov wc.hIcon, rv(LoadIcon, eax, IDI_APPLICATION) ; eax=hInstance
mov wc.hIconSm, eax
mov wc.hCursor, rv(LoadCursor, ebxNull, IDC_ARROW)
invoke RegisterClassEx, esi
invoke CreateWindowEx, WS_EX_CLIENTEDGE,
wc.lpszClassName, ebxNull,
WS_CAPTION or WS_THICKFRAME or WS_CLIPCHILDREN or WS_VISIBLE,
-127, -127, ebxNull, ebxNull,\ ; for now, outside of visible screen
ebxNull, ebxNull, wc.hInstance, ebxNull
invoke CreateWindowEx, ebxNull, Chr$("static"), ebxNull,
WS_CHILD or WS_VISIBLE, ebxNull, ebxNull, ebxNull, ebxNull,
eax, 123, wc.hInstance, ebxNull ; eax=retval cwex main, 123=IdStatic
mov hStatic, eax
add esi, wc.cbSize ; lea esi, msg but one byte shorter ;-)
.Repeat
invoke GetMessage, esi, ebxNull, ebxNull, ebxNull
.Break .if !eax
; invoke TranslateMessage, esi
invoke DispatchMessage, esi
.Until 0

qWord

Quote from: jj2007 on October 30, 2011, 05:17:00 PM
invoke GetMessage, esi, ebxNull, ebxNull, ebxNull
.Break .if !eax

:naughty:
Quote.Break .if !eax || eax == -1
:toothy
FPU in a trice: SmplMath
It's that simple!

jj2007


dedndave

 :lol
i think he is pulling your leg

try this
        invoke CreateWindowEx, ebxNull, Chr$("static"), ebxNull,
                WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS, ebxNull, ebxNull, ebxNull, ebxNull,
                eax, 123, wc.hInstance, ebxNull ; eax=retval cwex main, 123=IdStatic


on an unrelated note, you can use CW_USEDEFAULT,SW_HIDE to hide the window until later   :P
        invoke CreateWindowEx,WS_EX_CLIENTEDGE,wc.lpszClassName, ebxNull,
                WS_CAPTION or WS_THICKFRAME or WS_CLIPCHILDREN,
                CW_USEDEFAULT,SW_HIDE, ebxNull, ebxNull,\ ; hidden for now
                ebxNull, ebxNull, wc.hInstance, ebxNull

jj2007

Quote from: dedndave on October 30, 2011, 08:18:59 PM
try this
        invoke CreateWindowEx, ebxNull, Chr$("static"), ebxNull,
                WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS, ebxNull, ebxNull, ebxNull, ebxNull,
                eax, 123, wc.hInstance, ebxNull ; eax=retval cwex main, 123=IdStatic

No success. But I found a workaround (edi=hStatic):

      invoke InvalidateRect, edi, 0, 0   ; prepare for painting (erase background won't work)
      sub esp, PAINTSTRUCT   ; create a local ps
      invoke BeginPaint, edi, esp
      invoke GdipCreateFromHDC, eax, esi  ; create graphics object
      
invoke SetWindowText, edi, 0   ; this one does erase the background, hooray!
      sub esp, RECT   ; create a slot of paras for GdipDrawImageRectI
      invoke GetClientRect, edi, esp   ; use full control
      push [ebx]   ; imageObj
      push [esi]   ; graphicsObj; now stretch or draw image - see GdiPlus error codes
      call GdipDrawImageRectI   ; invoke GdipDrawImageRectI, [esi], [ebx], [eax.RECT.left, top, right, bottom]
      invoke GdipDeleteGraphics, [esi]   ; release graphics object
      invoke EndPaint, edi, esp
      add esp, PAINTSTRUCT   ; release local ps


:bg

An additional flag will be needed, because while this is needed for transparent icons, it is absolutely awful for big JPGs.

MichaelW

GetMessage returns -1 if there is an error, but I can't see needing the check this once you app is debugged.
eschew obfuscation

dedndave

WM_CTLCOLORSTATIC:
SetBkColor
mov eax,hBrush
ret

:P

jj2007

Dave,

In case that was an invitation to handle this message: It never arrives without the SetWindowText.

:wink

dedndave

well - i am still sceptical about the Invalidate call inside WM_PAINT   :P

but, that was the solution to NoCforMe's checkbox problem in the other thread - thought it may be helpful, here