The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RHL on March 20, 2012, 12:20:43 AM

Title: How to change color to a window?
Post by: RHL on March 20, 2012, 12:20:43 AM
Hello all, well looking for a way but still I find nothing :/
I want change the colour background of a windows, how to do?
thanks
Title: Re: How to change color to a window?
Post by: dedndave on March 20, 2012, 12:43:47 AM
what kind of window ?
for a "normal" window, you can set the background color in the WNDCLASSEX structure

attached is a simple window with a red background
there are a few ways to get a background brush
in this case, i used CreateSolidBrush
when you do it that way, the brush handle should be deleted with DeleteObject when you're done using it

i also included a text file that describes most of the ways to get a background color/handle
(ignore the 4 equates at the beginning of the file - those were for a program i wrote   :P )
Title: Re: How to change color to a window?
Post by: RHL on March 20, 2012, 02:18:14 AM
which is complicated  :(
is a window made ​​of a .res I think it's normal, and I wanted to do it in runtime
is I want to do a loop that change color every few seconds
Title: Re: How to change color to a window?
Post by: dedndave on March 20, 2012, 02:36:46 AM
nah - lol
it isn't that bad, once you get the basics

but - for now, let's play with a dialog box, which i think is what you are talking about...

in the DlgProc, you can answer the WM_CTLCOLORDLG message to change the background color
however, that message is only received whenever windows needs to redraw part or all of the dialog background

to force it to update, you can use InvalidateRect or InvalidateRgn and UpdateWindow
Title: Re: How to change color to a window?
Post by: dedndave on March 20, 2012, 02:48:00 AM
i notice that you have been shy about playing with CreateWindowEx   :P
as i said, it isn't that bad
1) you need a WndProc - very much like a DlgProc
2) you register the window class, using RegisterClassEx and a WNDCLASSEX structure
- in some cases, you can use a pre-defined system class and skip this step
3) use CreateWindowEx to create the window
-  here, you can use the style and extended style flags to make different types of windows
4) a message loop to dispatch messages

Iczelion's tutorials take you through this stuff   :U

after dinner, i will play with some code to change the background color of a dialog box   :bg
Title: Re: How to change color to a window?
Post by: RHL on March 20, 2012, 03:19:28 AM
okay... I try dedndave ^^'
thanks, also I hope you also share your code to learn from you  :bg
Title: Re: How to change color to a window?
Post by: P1 on March 20, 2012, 03:20:57 AM
Quote from: RHL on March 20, 2012, 02:18:14 AM
which is complicated  :(
is a window made ​​of a .res I think it's normal, and I wanted to do it in runtime
is I want to do a loop that change color every few seconds
I suggest that would be an option.

It could trigger epileptic attack for some users.

Regards,  P1   :8)
Title: Re: How to change color to a window?
Post by: RHL on March 20, 2012, 03:26:57 AM
hahaha
I am new in ASM I have four months since I started  :(
also C/C++.  all autodidact because I have not money to pay for professional studies
Title: Re: How to change color to a window?
Post by: dedndave on March 20, 2012, 04:06:57 AM
that's ok..
i came from 16-bit DOS days - lol
when i started, i played with 32-bit console programs for about 6 months before i started messing with GUI's   :P

give this program a try...
i even set the static text background color to match the dialog
Title: Re: How to change color to a window?
Post by: RHL on March 20, 2012, 04:13:12 AM
dedndave very thanks dude  :clap:
I will study your code
Title: Re: How to change color to a window?
Post by: dedndave on March 20, 2012, 04:13:54 AM
 :U

not a big deal...
but, i had the manifest file commented out in the resource file for some testing
if you want to see the button with UxTheme, uncomment the manifest line and run the batch to rebuild