News:

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

SendDlgItemMessage & button color

Started by Mark Jones, February 02, 2005, 05:42:46 PM

Previous topic - Next topic

Mark Jones

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. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

petezl

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
Cats and women do as they please
Dogs and men should realise it.

Relvinian

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

petezl

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.
Cats and women do as they please
Dogs and men should realise it.

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

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


"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

petezl

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.
Cats and women do as they please
Dogs and men should realise it.

Ramon Sala

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
Greetings from Catalonia

elmo

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