#SingleInstance Force Gui, Add, Text, cRed -Background, Red Gui, Color, Black Gui, Add, Text, cLime, Lime Gui, Add, Text, , Default Gui, Show, x200 y200 w400 h400
Gui Color question: making the background change behind text
Started by
POINTS
, Feb 14 2006 08:14 AM
6 replies to this topic
I'm basically trying to do the opposite of what this code is doing. I want the background behind the word Red to be black and the rest of the gui to be default. Is there a way to apply the "-Background" command to the main window?
#1
-
Posted 14 February 2006 - 08:14 AM
I tried this:
[EDIT] Updated code for better results, but still an issue when repainting the window. See following messages.
The Colorize function isn't called, unless I perform an action: button click or hotkey press.
And even so, only one static control is changed.
I guess that actually, there is conflict between AutoHotkey's internal handling of this message (which return system default color) and this attempt to take control of this message.
Or maybe I miss something. I let others experiment with this idea...
WM_CTLCOLORSTATIC=0x138 b = 128 g = 255 r = 255 brush := DllCall("CreateSolidBrush" , "UInt", RGB(r, g, b)) OnMessage(WM_CTLCOLORSTATIC, "Colorize") Gui Add, Button, gTest, OK Gui Add, Text, vLabel x70 y30 cBlue, (Dummy Text) Gui Add, Text, vDebug x10 y70 cGrey w180, / Gui Show, w200 h100 GuiControl Text, Label, Colored Text with Background! Return Test: i++ GuiControl Text, Debug, Test %i% Return GuiClose: GuiEscape: ; Probably uneeded as it is released on program exit, but cleaner this way DllCall("DeleteObject" , "UInt", brush) ExitApp Colorize(wParam, lParam, msg, hwnd) { global ; for brush DllCall("SetTextColor" , "UInt", wParam , "UInt", RGB(0, 0, 255)) DllCall("SetBkMode" , "UInt", wParam , "UInt", 1) ; TRANSPARENT Return brush } ; COLORREF = DWORD = UInt, format: 0x00bbggrr (blue green red) RGB(r, g, b) { Return (b << 16) + (g << 8) + r }but it doesn't work well... I was about to write "doesn't work", but I found strange results...
[EDIT] Updated code for better results, but still an issue when repainting the window. See following messages.
The Colorize function isn't called, unless I perform an action: button click or hotkey press.
And even so, only one static control is changed.
I guess that actually, there is conflict between AutoHotkey's internal handling of this message (which return system default color) and this attempt to take control of this message.
Or maybe I miss something. I let others experiment with this idea...
#2
-
Posted 14 February 2006 - 11:35 AM
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
This will get both things to change color.
Thanks for your help, this should do what I need.
d:: Test: i++ GuiControl Text, Debug1, Test %i% GuiControl Text, Debug2, Call %i% Return
Thanks for your help, this should do what I need.
#3
-
Posted 14 February 2006 - 03:33 PM
Oh, no need for action then, the label must be updated after the Show command:
Gui Show, w200 h100
GuiControl Text, Label, One
GuiControl Text, Debug1, Two
GuiControl Text, Debug2, Three
That was the missing link...
[EDIT] Not perfect, each time the window is repainted (eg. going behind another window and coming back to front), it gets again the original color... That's when internal coloring kicks in...
The Label text color goes back to default, you have to set it to the wanted color in the Colorize function with something like:
Of course, you can remove the debug c++ / GuiControl lines from the Colorize function. Just keep the global command.
Oh, I will just update the first post to give correct code to cut & paste...
Gui Show, w200 h100
GuiControl Text, Label, One
GuiControl Text, Debug1, Two
GuiControl Text, Debug2, Three
That was the missing link...
[EDIT] Not perfect, each time the window is repainted (eg. going behind another window and coming back to front), it gets again the original color... That's when internal coloring kicks in...
The Label text color goes back to default, you have to set it to the wanted color in the Colorize function with something like:
DllCall("SetTextColor" , "UInt", wParam , "UInt", RGB(0, 0, 255))You can change the color of only one Text component (or giving different colors per component) by checking its handle (HWND) in the lParam.
Of course, you can remove the debug c++ / GuiControl lines from the Colorize function. Just keep the global command.
Oh, I will just update the first post to give correct code to cut & paste...
#4
-
Posted 14 February 2006 - 03:46 PM
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Actually I need the background behind some images to be black. The problem is that when I reload an image, you can see the default gui color flicker before the image is loaded.
How would we modify your code to work behind images?
How would we modify your code to work behind images?
#5
-
Posted 14 February 2006 - 03:53 PM
You could try putting a Picture control behind the text control as a background. Such an image could probably be a 1-pixel GIF or BMP file consisting of the desired background color. That single pixel should get stretched automatically if you specify a width and height for the Picture control.
There are some tips in the help file about using Picture controls as backgrounds for other controls. It is also planned to have support for custom background colors for individual Text controls someday.
There are some tips in the help file about using Picture controls as backgrounds for other controls. It is also planned to have support for custom background colors for individual Text controls someday.
#6
-
Posted 14 February 2006 - 10:14 PM
Yes, this hack isn't really usable... :-)
I even tried to update the Text string on WM_NCPAINT (or even WM_PAINT), without result.
I can update it with a timer, but this is an overkill, and the text flickers, which is ugly...
So we have to wait for a future release of AutoHotkeys, allowing lot of flashy colored controls, to make your application looks like a baby toy :-)
I joke, but some carefully chosen colored labels can be effective to draw attention of users on some points.
I even tried to update the Text string on WM_NCPAINT (or even WM_PAINT), without result.
I can update it with a timer, but this is an overkill, and the text flickers, which is ugly...
So we have to wait for a future release of AutoHotkeys, allowing lot of flashy colored controls, to make your application looks like a baby toy :-)
I joke, but some carefully chosen colored labels can be effective to draw attention of users on some points.
#7
-
Posted 15 February 2006 - 10:10 AM
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")