Code: Select all
if (A_PtrSize = 8)
throw "Please run the script using 32-bit AutoHotkey"
SetWorkingDir, %A_ScriptDir%
Run, Notepad,,, pid
WinWait, % "ahk_pid " pid
hWnd := WinExist()
AppendMenu(hWnd, 1000, "Click Me")
hook1 := new HookMsg(hWnd, 0x111)
OnMessage(0x111, "WM_COMMAND")
Return
WM_COMMAND(wParam, lParam, msg, hwnd) {
If (wParam=1000)
MsgBox, Clicked
}
AppendMenu(hWnd, ItemID, ItemName) {
hMenu := DllCall("GetMenu", "Ptr", hWnd, "Ptr")
DllCall("AppendMenu", "Ptr", hMenu, "UInt", 0x0, "UPtr", ItemID, "Str", ItemName)
DllCall("DrawMenuBar", "Ptr", hWnd)
}
class HookMsg
{
__New(hWnd, MsgNumber)
{
; hook.dll -- https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=7166
dll:=A_MyDocuments "\AutoHotkey\Lib\Plugins\hook.dll"
if !FileExist(dll)
throw "hook.dll is missing"
static _ := DllCall("LoadLibrary", "Str",A_MyDocuments "\AutoHotkey\Lib\Plugins\hook.dll", "Ptr")
static WH_CALLWNDPROC := 4
, WH_GETMESSAGE := 3
, UM_ADDMESSAGE := (WM_USER := 1024) + 0x100
this.hWnd := hWnd
this.iThreadIdTarget := DllCall("GetWindowThreadProcessId", "Ptr", this.hWnd, "Ptr", 0)
hook := DllCall("hook\InstallFilterDLL", "Int", WH_CALLWNDPROC, "Int", this.iThreadIdTarget, "Ptr", this.hWnd) ; 0 = Ok
hookG := DllCall("hook\InstallFilterDLL", "Int", WH_GETMESSAGE, "Int", this.iThreadIdTarget, "Ptr", this.hWnd) ; 0 = Ok
DllCall("SendMessage", "Ptr", this.hWnd, "UInt", UM_ADDMESSAGE, "UPtr", MsgNumber, "Ptr", A_ScriptHwnd, "Ptr")
}
__Delete()
{
DllCall("hook\UnInstallFilterDLL", "Int", this.iThreadIdTarget, "Ptr", this.hWnd, "Ptr", A_ScriptHwnd)
}
}
------------------------------------------
dll:=A_MyDocuments "\AutoHotkey\Lib\Plugins\hook.dll"
static _ := DllCall("LoadLibrary", "Str",A_MyDocuments "\AutoHotkey\Lib\Plugins\hook.dll", "Ptr") ;'; works
static _ := DllCall("LoadLibrary", "Str",dll, "Ptr") ;'; not works
static _ := DllCall("LoadLibrary", "Str",%dll%, "Ptr") ;'; not works
------------------------------------------
why?