Code: Select all
#NoEnv
#SingleInstance, Force
Msgbox, Press F1 in an edit box to insert symbol.`nThe first menu is Menu,,Show, second is ShowMenu(), not working as desired
CoordMode, Mouse, Screen
Menu, Symbol, Add, Ø, Send
Menu, Symbol, Add, °, Send
Menu, Symbol, Add, ×, Send
Return
F1::
;Menu, Symbol, Show
hLast := DllCall("GetForegroundWindow")
ShowMenu(MenuGetHandle("Symbol"), False, A_ScreenWidth/2, A_ScreenHeight/2, 0x14 )
;Loop
;WinGet, Ex, ExStyle, % "ahk_id " (hndNext:= GetAltTabWindows()[A_Index])
;Until !(Ex & 0x8000088) ;WS_EX_TOPMOST, WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE
;WinActivate % "ahk_id " hndNext
;WinActivate % "ahk_id " GetAltTabWindows().1
Return
Send:
DllCall("SetForegroundWindow","Ptr",hLast)
Send, {%A_ThisMenuItem%}
Return
ShowMenu(hMenu, MenuLoop:=0, X:=0, Y:=0, Flags:=0) { ; Ver 0.61 by SKAN on D39F/D39G
Local ; @ tiny.cc/showmenu
If (hMenu="WM_ENTERMENULOOP")
Return True
Fn := Func("ShowMenu").Bind("WM_ENTERMENULOOP"), n := MenuLoop=0 ? 0 : OnMessage(0x211,Fn,-1)
DllCall("SetForegroundWindow","Ptr",A_ScriptHwnd)
R := DllCall("TrackPopupMenu", "Ptr",hMenu, "Int",Flags, "Int",X, "Int",Y, "Int",0
, "Ptr",A_ScriptHwnd, "Ptr",0, "UInt"), OnMessage(0x211,Fn, 0)
DllCall("PostMessage", "Ptr",A_ScriptHwnd, "Int",0, "Ptr",0, "Ptr",0)
Return R
}
GetAltTabWindows() { ; teadrinker https://www.autohotkey.com/boards/viewtopic.php?p=344440#p344440
AltTabList := []
WinGet, list, List
Loop % list
if IsAltTabWindow(list%A_Index%)
AltTabList.Push(list%A_Index%)
Return AltTabList
}
IsAltTabWindow(hWnd) {
static GA_ROOTOWNER := 3, WS_EX_APPWINDOW := 0x40000, WS_EX_TOOLWINDOW := 0x80, DWMWA_CLOAKED := 14
if !DllCall("IsWindowVisible", "Ptr", hWnd)
Return false
hOwner := DllCall("GetAncestor", "Ptr", hWnd, "UInt", GA_ROOTOWNER, "Ptr")
hPopup := DllCall("GetLastActivePopup", "Ptr", hOwner, "Ptr")
if (hOwner = hWnd && hPopup != hWnd)
Return false
WinGet, exStyles, ExStyle, ahk_id %hWnd%
;if (exStyles & WS_EX_TOOLWINDOW) && !(exStyles & WS_EX_APPWINDOW)
if (exStyles & 0x8000088) ; WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE
Return false
DllCall("DwmApi\DwmGetWindowAttribute", "Ptr", hWnd, "UInt", DWMWA_CLOAKED, "UIntP", cloaked, "UInt", 4)
Return !cloaked
}
/*
AltTabWindows() { ;ophthalmos, iseahound
static WS_EX_TOPMOST := 0x8 ; sets the Always On Top flag
static WS_EX_APPWINDOW := 0x40000 ; provides a taskbar button
static WS_EX_TOOLWINDOW := 0x80 ; removes the window from the alt-tab list
static GW_OWNER := 4
AltTabList := {}
windowList := ""
DetectHiddenWindows, Off ; makes DllCall("IsWindowVisible") unnecessary
WinGet, windowList, List ; gather a list of running programs
Loop, %windowList%
{
ownerID := windowID := windowList%A_Index%
Loop { ;If the window we found is opened by another application or "child", let's get the hWnd of the parent
ownerID := Format("0x{:x}", DllCall("GetWindow", "UInt", ownerID, "UInt", GW_OWNER))
} Until !Format("0x{:x}", DllCall("GetWindow", "UInt", ownerID, "UInt", GW_OWNER))
ownerID := ownerID ? ownerID : windowID
; only windows that are not removed from the Alt+Tab list, AND have a taskbar button, will be appended to our list.
If (Format("0x{:x}", DllCall("GetLastActivePopup", "UInt", ownerID)) = windowID)
{
WinGet, es, ExStyle, ahk_id %windowID%
If (!((es & WS_EX_TOOLWINDOW) && !(es & WS_EX_APPWINDOW)) && !IsInvisibleWin10BackgroundAppWindow(windowID))
AltTabList.Push(windowID)
}
}
; UNCOMMENT THIS FOR TESTING
;WinGetClass, class1, % "ahk_id" AltTabList[1]
;WinGetClass, class2, % "ahk_id" AltTabList[2]
;WinGetClass, classF, % "ahk_id" AltTabList.pop()
;msgbox % "Number of Windows: " AltTabList.length() "`nFirst windowID: " class1 "`nSecond windowID: " class2 "`nFinal windowID: " classF
return AltTabList
}
IsInvisibleWin10BackgroundAppWindow(hWindow) {
result := 0
VarSetCapacity(cloakedVal, A_PtrSize) ; DWMWA_CLOAKED := 14
hr := DllCall("DwmApi\DwmGetWindowAttribute", "Ptr", hWindow, "UInt", 14, "Ptr", &cloakedVal, "UInt", A_PtrSize)
if !hr ; returns S_OK (which is zero) on success. Otherwise, it returns an HRESULT error code
result := NumGet(cloakedVal) ; omitting the "&" performs better
return result ? true : false
}
/*
DWMWA_CLOAKED: If the window is cloaked, the following values explain why:
1 The window was cloaked by its owner application (DWM_CLOAKED_APP)
2 The window was cloaked by the Shell (DWM_CLOAKED_SHELL)
4 The cloak value was inherited from its owner window (DWM_CLOAKED_INHERITED)
*/