The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: JayPee on February 28, 2009, 10:06:42 PM

Title: Changing colour in a static box
Post by: JayPee on February 28, 2009, 10:06:42 PM
Hi

I am trying to change the background and text colour in a static box, the problem I have is all the static boxes change to the same colour. I have tried using a handle for the static box but it only makes things worse.

can someone please tell me where I have gone wrong.

Thank you in advance


Start:

Invoke GetModuleHandle, NULL
Mov [hInstance], Eax
Invoke InitCommonControls
Invoke DialogBoxParam, [hInstance], IDD_DLG, NULL, Addr DlgProc, NULL
Invoke CreateStatusWindow, WS_CHILD Or WS_VISIBLE, NULL, [hInstance], 200
Invoke ExitProcess, 0

DlgProc Frame hWnd, uMsg, wParam, lParam

Mov Eax, [hWnd]
Mov [hMain], Eax
Invoke GetDlgItem, [hWnd], 1002
Mov D[hTime], Eax
                Cmp D[uMsg], WM_CTLCOLORSTATIC
            Jne > WMpaint
                Invoke SetTextColor, [wParam], 0000FF00H
Invoke SetBkColor, [wParam], 00000000H
                Invoke GetStockObject, HOLLOW_BRUSH
Ret

WMpaint:
Cmp D[uMsg], WM_PAINT
Jne > Initdialog
                Invoke BeginPaint, [hWnd], Addr ps
                Invoke EndPaint, [hWnd], Addr ps
                Jmp > Init_Error

Initdialog:
Cmp D[uMsg], WM_INITDIALOG
        Jnz > Set_Timer]/code]
Title: Re: Changing colour in a static box
Post by: PBrennick on February 28, 2009, 10:51:48 PM
It is because G-d knows what the value of wParam is. Normally you need to issue the WM_CTLCOLORSTATIC message in the dialog procedure and process it in a subclass preocedure. You get the handle of the dialogbox and subclass it. That way you can control the value of wParam. Download Sudoku and look how I am doing it in an about box. WM_PAINT is unnecessary BTW>

Paul
Title: Re: Changing colour in a static box
Post by: Bill Cravener on March 01, 2009, 09:05:26 AM
   .elseif uMsg == WM_CTLCOLORSTATIC
            invoke GetDlgItem,hWin,1002
            .if eax == lParam
                invoke GetStockObject,HOLLOW_BRUSH
                ret
            .endif
            ret

Title: Re: Changing colour in a static box
Post by: PBrennick on March 01, 2009, 12:26:42 PM
Hi Bill,
and where does the value of lparam get set? That is what I mean by the subclassing. Doing that, YOU can set those values.

Paul
Title: Re: Changing colour in a static box
Post by: Bill Cravener on March 01, 2009, 01:59:23 PM
Hi Paul,

JayPee asked:
QuoteI am trying to change the background and text colour in a static box, the problem I have is all the static boxes change to the same colour.

That is how I deal with setting static controls to custom colors. A static control sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message the parent window can use the specified device context handle to set the text and background colors of the static control.

Each static control sends a WM_CTLCOLORSTATIC message to the window proc upon its creation. So simply retrieve the handle to the control whose color you wish to change each time each control sends its WM_CTLCOLORSTATIC message to the window proc until lparam matches the handle returned from GetDlgItem then pass on the brush value retrieved by the GetStockObject call.

WM_CTLCOLORSTATIC message information link: http://msdn.microsoft.com/en-us/library/bb787524(VS.85).aspx
Title: Re: Changing colour in a static box
Post by: BATSoftware on March 01, 2009, 03:25:53 PM
I use the method CycleSadles uses. Infact you should store the font/brush handles of all interested controls during WM_INITDIALOG processing. Use the stored handles during WM_CTL* processing. If you store both font and brush handles, you can also change the font during WM_CTL* processing. This method works for any control that issues WM_CTL* messages to the parent window. The extended controls have various behaviors and sometimes require specialized processing since they do not necessarily generate WM_CTL* messages.
Title: Re: Changing colour in a static box
Post by: Bill Cravener on March 01, 2009, 03:46:08 PM
Here attached is a simple example on changing the colors of three static text contols.

[attachment deleted by admin]
Title: Re: Changing colour in a static box
Post by: PBrennick on March 01, 2009, 09:35:50 PM
I like it. Easier to use.

Paul
Title: Re: Changing colour in a static box
Post by: JayPee on March 03, 2009, 08:16:12 AM
Hi Paul & Bill

Thanks very much for your help, your sample code work out very well and made what appaered to a complicated procedure very simple indeed. Thank you

John
Title: Re: Changing colour in a static box
Post by: Bill Cravener on March 03, 2009, 09:52:46 AM
You're welcome JayPee.  :wink
Title: Re: Changing colour in a static box
Post by: elmo on June 26, 2011, 04:04:24 AM
I'm sorry but I found nothing from google.
I want to get the text Color or background color of STATIC..

I have Static., It's background color is black. but the following API give me FFFFFFFFh. FFFFFFFFh is for white(not black).
      invoke GetBkColor,hLabel
      invoke MessageBox,0,hex$(eax),SADD("hLabel background color"),MB_OK
So, it's wrong.

How?
Title: Re: Changing colour in a static box
Post by: Gunner on June 26, 2011, 04:25:53 AM
GetBkColor needs a hDC not a handle to a control