The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Mark Jones on February 02, 2005, 05:42:46 PM

Title: SendDlgItemMessage & button color
Post by: Mark Jones on February 02, 2005, 05:42:46 PM
Hi, I'm a "dangerous novice" at assembler so please bear with me. I'd like to change the background color of a button at runtime. Could this be done with:

Invoke SendDlgItemMessage, hWnd, hButton1, Msg, wParam, lParam

But what would Msg, wParam, and lParam be? The Win32 API only shows the command structure, not any of the parameters.

According to EasyCode, a button background color of mild red is 0x00C5C2E7. A "changed" background color of mild green would be 0x00C7E7C2. Any ideas?

Thanks. :)
Title: Re: SendDlgItemMessage & button color
Post by: petezl on February 02, 2005, 06:52:10 PM
Hi Mark,
The Button color is decided by windows and can't be changed. If you really want to do it then you need to make a custom one yourself which is a bit more involved. :'(
Peter
Title: Re: SendDlgItemMessage & button color
Post by: Relvinian on February 02, 2005, 07:12:35 PM
Mark,

As Petezl pointed out, it is a litle more involved but basicallly you'll need to handle the WM_CTLCOLOR message in your dialog proc to change colors of controls.  Read upon this message in the Windows API help file to get more information about it.

Relvinian
Title: Re: SendDlgItemMessage & button color
Post by: petezl on February 02, 2005, 10:30:02 PM
To add to what Relvinian said, The CTL_COLOR message for Buttons has been discontinued but any of the other controls can use it.
Peter.
Title: Re: SendDlgItemMessage & button color
Post by: Mark Jones on February 03, 2005, 03:50:58 PM
Thanks. :)
Title: Re: SendDlgItemMessage & button color
Post by: Mark Jones on February 04, 2005, 05:59:18 AM
Oh, it looks like Ramon's EasyCode has a built-in proc just for this. Nice!


Invoke SetBackColor, hButton1, 00C7E7C2H ; set button1 background to mild green


Title: Re: SendDlgItemMessage & button color
Post by: petezl on February 04, 2005, 10:51:25 AM
Ah, Now youve got me stumped. The question was in the Campus so I took it that it was Purely masm/ api related. The CTL_COLORBUTTON  message was discontinued after win95 I think. Not an illegal startement but simply gets ignored by the OS. I haven't used easy code so perhaps Ramon could explain how he does it.
In masm you would now have to create a custom control which is extremely flexible or perhaps a system wide hook to trap the button as was shown recently for a MessageBox.
Anyway, I'm glad you succeeded :U
Peter.
Title: Re: SendDlgItemMessage & button color
Post by: Ramon Sala on April 15, 2011, 05:39:49 PM
Hi All,

As petezl and Relvinian say, the CTL_COLORBUTTON doesn't work, so a button just can be colored if it's "owner draw" (the button style has to include BS_OWNERDRAW) and that's exactly what Easy Code (visual projects) do. However, the use of Common Controls (Windows XP and later) makes even more complicated managing buttons and all other controls. Easy Code can internally do this work just in visual projects and just if the "common controls" are not used, that is, without using a "manifest.xml" file which is included by default.

- Open EC, click "New project" and choose the "Visual executable file" option.
- Remove the "Manifest.xml" file from the project explorer.
- Make sure the 'OwnerDraw' property is set to TRUE (it's FALSE by default).
- Now you can change the 'BackColor' and 'ForeColor' properties and see the results.

That way you'll have a button where you can decide colors for background and text, BUT the button WILL NOT HAVE the Windows XP/Vista/7 visual style.

Regards,

Ramon
Title: Re: SendDlgItemMessage & button color
Post by: elmo on April 19, 2011, 11:15:30 AM
I have same problem. but with Static
What I want to do is: I want to change it's Text color when a mouse hover on it.

This what I have done. But it fail.
I have tried to subclass the static too but still fail.
the other source who support this:
http://www.masm32.com/board/index.php?PHPSESSID=fa4590ba57dbaad4bc44088172af0b49&board=1;topic=14241.6

would you like to give me a clue?
sorry for my bad english
thank you

                .elseif uMsg == WM_CREATE
invoke CreateWindowEx,
WS_EX_STATICEDGE,
ADDR STATclass,SADD("this is a link"),
WS_CHILD or WS_VISIBLE or SS_NOTIFY,
500,475,190,20,hWin,27,
400000h,NULL
mov hLabel1,eax
INVOKE SendMessage,hLabel1, WM_SETFONT, hFont, 1
invoke SetClassLong,hLabel1, GCL_HCURSOR, rv(LoadCursor, 0, IDC_HAND)



.elseif uMsg == WM_MOUSEMOVE
invoke GetDlgCtrlID,hLabel1
.if eax==27             ;27 is ID of hLabel1
mov hover,TRUE
.else
mov hover,FALSE
.endif






.elseif uMsg == WM_CTLCOLORSTATIC
mov eax,lParam
.if eax==hLabel1
.if hover == FALSE
invoke SetTextColor, wParam,Red
.endif
.if hover == TRUE
invoke SetTextColor, wParam,Blue
.endif
invoke SetBkMode, wParam, TRANSPARENT
invoke GetSysColorBrush, COLOR_BTNFACE
.endif
ret