The MASM Forum

General => The Campus => Topic started by: asmcoder on December 12, 2013, 06:49:18 PM

Title: HELP static color
Post by: asmcoder on December 12, 2013, 06:49:18 PM

       .elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDC_BTN1
invoke SendMessage,hwnd_static,WM_SETTEXT,0,offset text1
; invoke UpdateWindow,hwnd_static
; invoke InvalidateRect,hwnd_static,0,TRUE
.endif

.elseif eax==WM_CTLCOLORSTATIC

mov eax,lParam ;hwnd
.if eax==hwnd_static
invoke SetTextColor,wParam,0FFh
invoke SetBkMode,wParam,TRANSPARENT
invoke GetStockObject,NULL_BRUSH
ret
.endif



Hi, all
I am trying to change the static color,
when i click the button, a new text show, but the pre text still exist.
i tried UpdateWindow and InvalidateRect, but they don't work.
Title: Re: HELP static color
Post by: jj2007 on December 12, 2013, 08:00:41 PM
User LTGRAY_BRUSH, or create your own.

EDIT: invoke GetSysColorBrush,COLOR_BTNFACE is a perfect solution :t
Title: Re: HELP static color
Post by: asmcoder on December 12, 2013, 08:13:37 PM
Thanks jj , but the LTGRAY_BRUSH don't match the background color
Title: Re: HELP static color
Post by: asmcoder on December 12, 2013, 08:17:31 PM
got it. :biggrin:
         invoke SetTextColor,wParam,0FFh
         invoke SetBkMode,wParam,TRANSPARENT   
         invoke GetSysColorBrush,COLOR_BTNFACE
Title: Re: HELP static color
Post by: dedndave on December 12, 2013, 10:07:02 PM
i would put the GetSysColorBrush(COLOR_BTNFACE) call in WM_INITDIALOG
and store the HBRUSH in a global variable, something like hbrStaticBg
    .if eax==WM_INITDIALOG
        invoke  GetDlgItem,hWin,IDC_STC1
        mov     hwnd_static,eax
        invoke  GetSysColorBrush,COLOR_BTNFACE
        mov     hbrStaticBg,eax


then, for WM_CTLCOLORSTATIC...
    .elseif eax==WM_CTLCOLORSTATIC
        mov     eax,lParam                                   ;hwnd
        .if eax==hwnd_static
            invoke  SetTextColor,wParam,0FFh
            invoke  SetBkMode,wParam,TRANSPARENT
            mov     eax,hbrStaticBg
        .else
            mov     eax,FALSE
        .endif
        ret
Title: Re: HELP static color
Post by: fearless on December 13, 2013, 02:55:41 AM
Im assuming this is on Windows 7/Vista or above.

I ran into similar issues with Send WM_SETTEXT, SetDlgItemText and tried various things like InvalidateRect, UpdateWindow etc.

The only solution i found that works is to hide and show the control - it then repaints it without the previous text underneath it

            invoke SendMessage,hwnd_static,WM_SETTEXT,0,offset text1
            Invoke ShowWindow, hwnd_static, SW_HIDE
            Invoke ShowWindow, hwnd_static, SW_SHOW


From what i can remember (been a while since i looked into the issue), and i cant remember the sources i found that relate to this (think it was in relation to listviews not displaying properly under win7 - seemed to be a lot of posts on various forums in relation to this issue, and i had a similar issue), but from what i recall it is to do with the Windows Presentation layer in Vista/7/8 etc that the common controls and other bits of win32 api that use it, call or are managed by that now instead. So you get a kind of buffering/queued update - if you minimize/maximise the main window the control probably will refresh, other times it would do it if you left it long enough, but trying to force it to update with SetDlgItemText, WM_SETTEXT only overwrites the old text. Windows XP isnt affected by this. Im running Win7 64bit - cant say for sure if this is the same on a Win7 32bit version or not. Vista and Win8 prob gonna be the same.

So if that helps. Ill try and dig out some references to the issue if i can. Maybe http://blogs.msdn.com/b/oldnewthing/ has something about the issue.
Title: Re: HELP static color
Post by: dedndave on December 13, 2013, 04:33:06 AM
you might try SetWindowPos