News:

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

Changing colour in a static box

Started by JayPee, February 28, 2009, 10:06:42 PM

Previous topic - Next topic

JayPee

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]
Greetings From New Zealand
(Land of the Long White Cloud)

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

Bill Cravener

   .elseif uMsg == WM_CTLCOLORSTATIC
            invoke GetDlgItem,hWin,1002
            .if eax == lParam
                invoke GetStockObject,HOLLOW_BRUSH
                ret
            .endif
            ret

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

Bill Cravener

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
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

BATSoftware

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.

Bill Cravener

Here attached is a simple example on changing the colors of three static text contols.

[attachment deleted by admin]
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

PBrennick

The GeneSys Project is available from:
The Repository or My crappy website

JayPee

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
Greetings From New Zealand
(Land of the Long White Cloud)

Bill Cravener

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

elmo

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?
be the king of accounting programmer world!

Gunner

GetBkColor needs a hDC not a handle to a control
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com