The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: LAS3R on January 06, 2005, 11:47:56 AM

Title: Change color of dialogs background!
Post by: LAS3R on January 06, 2005, 11:47:56 AM
I tried search for it here but didn't find what i wanted so i ask here instead, feel free to flame but don't expect me to reply!

i want my Dialogs background to be black and text white but can't get it to work, tried CreateBrush or what ever name was and still no luck!  :(

if u know howto do it please post so here or just modify my source and upload it! i'm getting nuts and really want those colors, myself i totally given up howto make it work, source i post here don't contain any code whatever about changing color, so feel free to modify it, it's open source :P!  :U



[attachment deleted by admin]
Title: Re: Change color of dialogs background!
Post by: donkey on January 06, 2005, 12:13:28 PM
Hi,

To change the color of a dialog you process the WM_CTLCOLORDLG message and return a brush handle in EAX. For black you would normally use a stock object, it has the advantage that it does not have to be deleted with DeleteObject...

; message loop (DlgProc)
cmp [uMsg], WM_CTLCOLORDLG
jne NextMessage
    invoke GetStockObject, BLACK_BRUSH
    ret


If you decide on a color that is not stock do not create a brush in the message loop, as you are responsible for deleting it, rather create it once and just return the handle. This will not color the non-client area of the dialog, that is a bit more complicated and would require processing the WM_NCPAINT message.
Title: Re: Change color of dialogs background!
Post by: petezl on January 06, 2005, 01:51:46 PM
Donkey,
I've used any colour before while avoiding any additional WM_PAINT message. although it will obviously be limiting and neccesary to include it to change the text colour. Is there anyting I've overlooked with this?


.data
BlackColourBrush equ 000000h
.data?
hBlackColourBrush dd ?

; message loop (DlgProc)

.if uMsg == WM_INITDIALOG
invoke CreateSolidBrush,BlackColourBrush
mov hBlackColourBrush,eax

.elseif uMsg == WM_CTLCOLORDLG
mov eax,hBlackColourBrush
ret

.elseif uMsg == WM_CLOSE
;Always delete what you created
invoke DeleteObject,hBlackColourBrush

Peter
Title: Re: Change color of dialogs background!
Post by: LAS3R on January 06, 2005, 11:03:40 PM
Ok thx for that code, both worked fine, i'm real happy but still one thing don't get to work hehe, yep it's time for....

NOOB QUESTION ROUND 2!

found out sofar that line should be like this

invoke SetBkMode, hdc, TRANSPARENT

but what heck is hdc, can't find anything that will work!
Title: Re: Change color of dialogs background!
Post by: donkey on January 07, 2005, 12:33:07 AM
The hDC is a handle to a "device context", it is a structure that describes to Windows the capabilities and drawing requirements for a particular peice of hardware like a printer or in this case the screen. Windows uses the hDC to draw through in order to allow for different display hardware using the same software. In order to get the DC handle, you have simply to ask for it with :

invoke GetDC, [hwnd] ; get the DC handle for this window
mov [hdc], eax

Because when you use GetDC, Windows internally modifies many things in order to draw, like color depth, resolution etc... you must release it when you are through. Only a limited number of hDC's are available at a time and they are system wide, that is you are getting it from a limited pool. In order to free up an hDC you must always release it when you are done with :

invoke ReleaseDC, [hwnd], [hdc]

The last thing to worry about is if the message already passes the hDC, in most messages that paint it is passed in the message parameters. For example in WM_CTLCOLORDLG it is passed in wParam. In cases where the hDC is passed as part of the message you should not release it as Windows will do it for you.
Title: Re: Change color of dialogs background!
Post by: jimh on January 07, 2005, 01:20:02 AM
...and to expand on Donkey's answer for when you get around to handling the WM_PAINT message...

If GetUpdateRect returns TRUE, then you have an area that needs to be updated, so you should use the BeginPaint/EndPaint function pair to get the hDC with which you'll paint your window.

Things BeginPaint does:
    - Hides the caret for painting (if necessary)
    - Erases the background of the area to be drawn on in the window class background color
    - Returns a safe hDC for you to use
    - Sends WM_ERASEBACKGROUND to your window (if necessary)
    - Sets the clipping region to just the area that needs to be drawn on

and EndPaint cleans all that up for you after you're done drawing on your window. You don't even need to delete the hDC returned from BeginPaint because EndPaint will do it.
Title: Re: Change color of dialogs background!
Post by: LAS3R on January 07, 2005, 12:22:06 PM
Thx for reply, atleast something happend, my buttons disapear and can't move my window anymore when tried codes above!

Title: Re: Change color of dialogs background!
Post by: six_L on January 07, 2005, 02:39:56 PM
LAS3R,
here a code written by comrade. it maybe give you some references
Please help me to figure out my question about topic "ports".

:boohoo:
regards

[attachment deleted by admin]