News:

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

Font and Color

Started by Shooter, December 29, 2010, 04:45:35 PM

Previous topic - Next topic

Gunner

Quote from: Shooter on December 29, 2010, 11:32:11 PM
I looked up GetStockObject, but didn't really get why it's needed in my case, nor did I find how to use it for what I want to achieve. Perhaps that's because I don't understand it's use here just yet.

Got any advice?

Well, it is not needed, you can use CreateSolidBrush to create a brush of the color you want....  and what they both do is return a colored brush the os uses to paint the background
BUT if you use CreateSolidBrush, you have to delete it on WM_CLOSE with DeleteObject

WM_CTLCOLORSTATIC Notification

Return Value

If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control.

~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

COLOR_WINDOW+1

there is a list of EQUates starting with "COLOR_" in windows.inc
you can use it directly but, for some reason that i haven't figured out, you always have to add 1

Shooter

BINGO!!! WE HAVE A WINNER! NULL_BRUSH to the rescue! lol
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

jj2007

Quote from: Shooter on December 29, 2010, 11:49:47 PM
BINGO!!! WE HAVE A WINNER! NULL_BRUSH to the rescue! lol

Try changing your text several times...

Shooter

Quote from: jj2007 on December 29, 2010, 11:50:52 PM
Try changing your text several times...

What, like one color per second or something?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

jj2007

Not the colour, the text. NULL_BRUSH means that your background will never be painted, After a while, it looks ugly. My example works fine.

dedndave

what he's telling you is - that method is not stable

Shooter

Quote from: jj2007 on December 29, 2010, 11:54:50 PM
Not the colour, the text. NULL_BRUSH means that your background will never be painted, After a while, it looks ugly. My example works fine.

Quote from: dedndave on December 29, 2010, 11:55:08 PM
what he's telling you is - that method is not stable

So if I had a static text that changes a lot, there would be bits of color left over from the previous text if the new text didn't cover it up?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

it may be best to try it out
not that it is a good thing - but it may help you understand the mechanics

i am working on a little program
i can grab different colors for foreground and background
if i want different background colors in different places, i can do that
and it seems to work well

all the colors are handled with these 4 functions

GetStockObject
SetTextColor
SetBkColor
SetBkMode

and - i could also use this
Quotethere is a list of EQUates starting with "COLOR_" in windows.inc
you can use them directly but, for some reason that i haven't figured out, you always have to add 1
example:
COLOR_WINDOW+1

Shooter

Quote from: dedndave on December 30, 2010, 12:04:28 AM
GetStockObject
SetTextColor
SetBkColor
SetBkMode

Currently, this is how I'm driving the text color (I haven't tried moving this into the "If Screen Saver is On... change color" yet):
.elseif eax==WM_CTLCOLORSTATIC
invoke GetDlgItem,hWin,IDC_STC6
.if eax==lParam
            invoke SetBkMode,wParam,TRANSPARENT
            invoke SetTextColor,wParam,Red
            invoke GetStockObject,NULL_PEN
ret
.endif
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

GetStockObject returns a handle to the requested object in EAX
you aren't doing anything with that handle
and, before you return, i think you want EAX to be 0

Gunner

No, if you return 0 in eax for WM_CTLCOLORSTATIC that is the same a NULL_BRUSH
You have to return a valid handle to a brush so the OS can paint the background...
What he has is the correct way
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

thanks Rob - my bad
i thought WndProc had to return 0 for handled messages
i am a n00b, but i am learning

Shooter

Quote from: Gunner on December 30, 2010, 12:23:29 AM
No, if you return 0 in eax for WM_CTLCOLORSTATIC that is the same a NULL_BRUSH
You have to return a valid handle to a brush so the OS can paint the background...
What he has is the correct way

I have to admit, I'm lost as to the purpose of GetStockObject, let alone why in that example you gave me it's at the end before returning. I do however know that if it's omitted, nothing changes.

Nevermind, I get it now:
QuoteThe WM_CTLCOLORSTATIC message is sent to the parent window of a static control when the control is about to be drawn. By responding to this message, the parent window can use the given device context handle to set the text and background colors of the static control.
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Gunner

Quote from: dedndave on December 30, 2010, 12:25:23 AM
i am a n00b, but i am learning

http://www.urbandictionary.com/define.php?term=n00bs
That does not sound like you Dave  :P

Gotta check messages to see what they need to have in eax when done processing... TRUE, FALSE, hBrush, breakfast....etc  :bg
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com