I play poker, and I'm trying to create a very basic gui that attaches to my poker client window and covers up my account balance with a solid box. I'm using the code from this post.
Code: Select all
#NoEnv
#SingleInstance force
SetWorkingDir % A_ScriptDir
SendMode, Input
if not A_IsAdmin
Run *RunAs "%A_ScriptFullPath%"
SetWinDelay, -1
WinWaitActive, Ignition Casino - Poker Lobby
WinGet, PID, PID, % "ahk_id " . owner:=WinExist() ; if all parameters are omitted, WinExist returns the ID the Last Found Window if it still exist; WinWait set the Last Found Window
GUI, +ToolWindow +Owner%owner% +Hwndowned -Caption
/*
+ToolWindow > no taskbar button
+Owner%owner% > make the GUI owned by the window whose ID is the one stored in the variable 'owner'
+Hwndowned > stores the ID of the GUI in 'owned'
*/
global ownerAhkId := "ahk_id " . owner, ownedAhkId := "ahk_id " . owned
GUI, Show, w75 h50 x100 y100
hWinEventHook := SetWinEventHook("0x800B", "0x800B", 0, RegisterCallback("OnLocationChangeMonitor"), PID, 0, 0) ; register a event hook function for EVENT_OBJECT_LOCATIONCHANGE := "0x800B"
OnLocationChangeMonitor(0, 0, 1)
OnExit, handleExit ; specifies a subroutine or callback function to run automatically when the script exits...
WinWaitClose % ownerAhkId ; ... or until the owner window does not exist
handleExit:
UnhookWinEvent(hWinEventHook) ; removes the event hook function created by SetWinEventHook before exiting the script
ExitApp
OnLocationChangeMonitor(_hWinEventHook, _event, _hwnd) { ; https msdn.microsoft.com /en-us/library/windows/desktop/dd373885(v=vs.85).aspx Broken Link for safety
_listLines := A_ListLines
ListLines, Off
if not (_hwnd) ; if the system sent the EVENT_OBJECT_LOCATIONCHANGE event for the caret: https msdn.microsoft.com /en-us/library/windows/desktop/dd318066(v=vs.85).aspx Broken Link for safety
return
WinGetPos, _x, _y,,, % ownerAhkId
WinMove, % ownedAhkId,, % _x, % _y ; set the position of the window owned by owner
ListLines % _listLines ? "On" : "Off"
}
SetWinEventHook(_eventMin, _eventMax, _hmodWinEventProc, _lpfnWinEventProc, _idProcess, _idThread, _dwFlags) {
DllCall("CoInitialize", "Uint", 0)
return DllCall("SetWinEventHook"
, "Uint", _eventMin
, "Uint", _eventMax
, "Ptr", _hmodWinEventProc
, "Ptr", _lpfnWinEventProc
, "Uint", _idProcess
, "Uint", _idThread
, "Uint", _dwFlags)
} ; cf. https://autohotkey.com/boards/viewtopic.php?t=830
UnhookWinEvent(_hWinEventHook) {
_v := DllCall("UnhookWinEvent", "Ptr", _hWinEventHook)
DllCall("CoUninitialize")
return _v
} ; cf. https://autohotkey.com/boards/viewtopic.php?t=830
Any help would be much appreciated. Thanks so much!