Code: Select all
; Windows 8.1 64 bit - Autohotkey v1.1.27.04 32-bit Unicode
#NoEnv
SetBatchLines, -1 ; in order to make the window docking smoother
SetWinDelay, -1 ; in order to make the window docking smoother
global menuItems := [] ; an arry in which will be store all AHKID of menu items (in fact GUI)
global xmin := 248, ymin := 28 ; the coordinates (relative to the window) from which the menu will be added
f := Func("WinActive").bind("A") ; dummy
Loop, 3
Menu, menu1, Add, func %a_index%, % f
; creation of the 'menun items'
DetectHiddenWindows, On
Loop, 2 {
Gui, New, +LastFound +AlwaysOnTop -Caption -Border +HWNDID
menuItems[ ID ] := "ahk_id " . ID
Gui, Color, white
Gui, Add, Text, gf, function %a_index%
Gui, Show, Hide
WinSet, TransColor, white ; make the backgroundof the GUI (set to be white) transparent
Gui, Show, AutoSize h20 Minimize NA
}
DetectHiddenWindows, Off
run, notepad,,, PID
WinWaitActive, ahk_pid %PID%
global AHKID := "ahk_id " . HWND:=WinExist(lastFoundWindow:="")
for ID in menuItems
Gui, %ID%:+Owner%HWND% ; make the 'menu items' owned by notepad
machineCodeAddress := RegisterCallback("PIDOnLocationChange") ; machine-code address that will be called by the hook below
hWinEventHook := SetWinEventHook(0x800B, 0x800B, 0, machineCodeAddress, PID, 0, 0) ; EVENT_OBJECT_LOCATIONCHANGE := "0x800B" (https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066(v=vs.85).aspx)
PIDOnLocationChange(0, 0, 1)
OnExit, handleExit
WinWaitClose
handleExit:
UnhookWinEvent(hWinEventHook)
ExitApp
f() {
Menu, menu1, Show
}
PIDOnLocationChange(__hWinEventHook, __event, __hwnd) { ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd373885(v=vs.85).aspx
if not (__hwnd) ; if EVENT_OBJECT_LOCATIONCHANGE event has been generated by a change of location, shape, or size of the window object itself (no the caret etc.)
return
WinGetPos, __x, __y, __w, __h, % AHKID
__xmin := __x + xmin, __ymin := __y + ymin
__δh := 0
for __ID, __AHKID in menuItems {
WinMove, % __AHKID,, % __xmin + ((a_index-1) * __δh), % __ymin ; arrange menu items side by side...
WinGetPos, __mx,, __mw,, % __AHKID
__δh := __mw + 5 ; ...with a margin of 5px
}
}
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
}