Further issues with WinGet/SetTransColor()
Issue #59
closed
I'm really getting lost - after this next post I'm going to take a break from it for a couple of hours. I'm not seeing the forest for the trees. The code below works until I hit the hotkey, then Keysharp freezes up entirely and I have to kill Keysharp.exe to get out.
pos := ""
TransColor := ""
window := ""
title := ""
guiobj := Null
MyGui := Gui(, "Help the primate!")
MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below).
MyGui.SetFont("s32") ; Set a large font size (32-point).
CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSetTransColor(MyGui.BackColor " 150", MyGui)
MyGui.Show("x0 y400 NoActivate") ; NoActivate avoids deactivating the currently active window.
Sleep(2000)
Trans := WinGetTransColor(MyGui)
MsgBox(Trans)
MsgBox(MyGui.Hwnd)
^!#g:: ; Press Win+G to show the current settings of the window under the mouse.
{
global
pos := MouseGetPos()
window := pos["Win"]
MsgBox(window)
;title := "ahk_id " window
;MsgBox(title)
;guiobj := GuiFromHwnd(window)
;MsgBox(IsObject(guiobj))
;TransColor := WinGetTransColor(guiobj)
;MsgBox(TransColor)
}
This doesn't crash, but the last message box after I hit the hotkey does not display.
MyGui := Gui(, "Help the primate!")
MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below).
MyGui.SetFont("s32") ; Set a large font size (32-point).
CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSetTransColor(MyGui.BackColor " 150", MyGui)
MyGui.Show("x0 y400 NoActivate") ; NoActivate avoids deactivating the currently active window.
Sleep(2000)
Trans := WinGetTransColor(MyGui)
MsgBox(Trans)
MsgBox(MyGui.Hwnd)
^!#g:: ; Press Win+G to show the current settings of the window under the mouse.
{
pos := MouseGetPos()
window := pos["Win"]
MsgBox(window)
title := "ahk_id " window
MsgBox(title)
;guiobj := GuiFromHwnd(window)
; MsgBox(IsObject(guiobj))
TransColor := WinGetTransColor(title)
MsgBox(TransColor)
}
- I'll have to experiment to see if WinGetTransColor actually works on WinTitle. I'm expecting it doesn't.
- I'm losing it here. This works.
MyGui := Gui(, "Help the primate!") MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item. MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below). MyGui.SetFont("s32") ; Set a large font size (32-point). CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window. ; Make all pixels of this color transparent and make the text itself translucent (150): WinSetTransColor(MyGui.BackColor " 150", MyGui) MyGui.Show("x0 y400 NoActivate") ; NoActivate avoids deactivating the currently active window. Sleep(2000) Trans := WinGetTransColor(MyGui.Title) MsgBox(Trans) MsgBox(MyGui.Hwnd)
- In other words, using MyGui.Title for the WinTitle param. Now to try composing the title.
MyGui := Gui(, "Help the primate!") MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item. MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below). MyGui.SetFont("s32") ; Set a large font size (32-point). CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window. ; Make all pixels of this color transparent and make the text itself translucent (150): WinSetTransColor(MyGui.BackColor " 150", MyGui) MyGui.Show("x0 y400 NoActivate") ; NoActivate avoids deactivating the currently active window. Sleep(2000) Trans := WinGetTransColor("ahk_id " MyGui.Hwnd) MsgBox(Trans) MsgBox(MyGui.Hwnd)
So this works. Wonder if the trouble was calling from a hotkey?
- Maybe. The following also crashes Keysharp when the hotkey is pressed, no matter where the mouse is at the time.
MyGui := Gui(, "Help the primate!")
MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below).
MyGui.SetFont("s32") ; Set a large font size (32-point).
CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSetTransColor(MyGui.BackColor " 150", MyGui)
MyGui.Show("x0 y400") ; NoActivate avoids deactivating the currently active window.
Sleep(2000)
MyObj := GuiFromHwnd(MyGui.Hwnd)
Trans := WinGetTransColor(MyObj)
MsgBox(Trans)
MsgBox(MyGui.Hwnd)
^!#g:: ; Press Win+G to show the current settings of the window under the mouse.
{
pos := MouseGetPos()
window_id := pos["Win"]
MsgBox(window_id)
title := "ahk_id " window_id
MsgBox(title)
TransColor := WinGetTransColor("ahk_id " title)
MsgBox(TransColor)
}
I'm going to remove the TransColor stuff and see if that at least keeps it from crashing.
- It does. This works no matter where the mouse is when I hit the hot key.
MyGui := Gui(, "Help the primate!")
MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below).
MyGui.SetFont("s32") ; Set a large font size (32-point).
CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSetTransColor(MyGui.BackColor " 150", MyGui)
MyGui.Show("x0 y400") ; NoActivate avoids deactivating the currently active window.
Sleep(2000)
MyObj := GuiFromHwnd(MyGui.Hwnd)
Trans := WinGetTransColor(MyObj)
MsgBox(Trans)
MsgBox(MyGui.Hwnd)
^!#g:: ; Press Win+G to show the current settings of the window under the mouse.
{
pos := MouseGetPos()
window_id := pos["Win"]
MsgBox(window_id)
title := "ahk_id " window_id
MsgBox(title)
}
Comments (4)
-
reporter -
The following code works. Marking as resolved and closing.
MyGui := Gui(, "Help the primate!") MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item. MyGui.BackColor := "EEAA99" ; Can be any RGB color (it will be made transparent below). MyGui.SetFont("s32") ; Set a large font size (32-point). CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYYY") ; XX & YY serve to auto-size the window. ; Make all pixels of this color transparent and make the text itself translucent (150): WinSetTransColor(MyGui.BackColor " 150", MyGui) MyGui.Show("x0 y400 NoActivate") ; NoActivate avoids deactivating the currently active window. Sleep(2000) ^!#g:: { ;global pos := MouseGetPos() window := pos["Win"] MsgBox(window) Trans := WinGetTransColor(MyGui) MsgBox(Trans, "Trans Color") MsgBox(MyGui.Hwnd, "Hwnd") } !Esc::ExitApp()
-
- changed status to resolved
Resolved.
-
- changed status to closed
Closed.
- Log in to comment
This had nothing to do with WinGet/SetTransColor(). Instead, it was entirely due to not properly finding windows under the mouse cursor, when the cursor was over a child control of the window.
I think my fix works, so please test again.