Window made with CreateWindowEx triggers tray menu hotkeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
MiM
Posts: 61
Joined: 20 Apr 2021, 04:31

Window made with CreateWindowEx triggers tray menu hotkeys

Post by MiM » 02 Jul 2023, 09:40

As title says,

Code: Select all

#Persistent
#SingleInstance,  Force

WinClass := "MyClass"
Func     := "MyWndProc"
pWndProc := RegisterCallback(Func, "F")
hCursor  := DllCall("LoadCursor", "UInt", 0, "Int", 32512, "UInt")
vPIs64   := (A_PtrSize=8), vSize := (vPIs64?80:48)
VarSetCapacity(WNDCLASSEX, vSize, 0)
NumPut(vSize, WNDCLASSEX, 0, "UInt")               ;cbSize
NumPut(3, WNDCLASSEX, 4, "UInt")                   ;style
NumPut(pWndProc, WNDCLASSEX, 8, "Ptr")             ;lpfnWndProc
NumPut(0, WNDCLASSEX, vPIs64?16:12, "Int")         ;cbClsExtra
NumPut(0, WNDCLASSEX, vPIs64?20:16, "Int")         ;cbWndExtra
NumPut(0, WNDCLASSEX, vPIs64?24:20, "Ptr")         ;hInstance
NumPut(0, WNDCLASSEX, vPIs64?32:24, "Ptr")         ;hIcon
NumPut(hCursor, WNDCLASSEX, vPIs64?40:28, "Ptr")   ;hCursor
NumPut(16, WNDCLASSEX, vPIs64?48:32, "Ptr")        ;hbrBackground
NumPut(0, WNDCLASSEX, vPIs64?56:36, "Ptr")         ;lpszMenuName
NumPut(&WinClass, WNDCLASSEX, vPIs64?64:40, "Ptr") ;lpszClassName
NumPut(0, WNDCLASSEX, vPIs64?72:44, "Ptr")         ;hIconSm
DllCall("RegisterClassEx", Ptr, &WNDCLASSEX, "UShort")

WinTitle := "MyTitle"
WinStyle :=  0x10000000 ; WS_VISIBLE
WinExStyle := 0
GuiX := 0
GuiY := 0
GuiW := 400
GuiH := 300
HwndParent := 0, hMenu := 0, hInstance := 0, lpParam := 0

Global GuiHwnd := DllCall("CreateWindowEx"
                , "UInt", WinExStyle
                , "Str" , WinClass
                , "Str" , WinTitle
                , "UInt", WinStyle
                , "Int" , GuiX
                , "Int" , GuiY
                , "Int" , GuiW
                , "Int" , GuiH
                , "Ptr" , HwndParent
                , "Ptr" , hMenu
                , "Ptr" , hInstance
                , "Ptr" , lpParam
                , "Ptr" , 0)
Return

MyWndProc(Hwnd, Msg, wParam, lParam) {
  Return DllCall("DefWindowProc", "Ptr", Hwnd, "UInt", Msg, "UPtr", wParam, "Ptr", lParam)
}
while a window created with CreateWindowEx is active, keys trigger tray menu items, F1 launches autohotkey.chm, Ctrl+R reloads script, etc.

These hotkeys are located in AutoHotkey.rc ~

Code: Select all

IDR_MENU_MAIN MENU 
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&Reload Script\tCtrl+R",      ID_FILE_RELOADSCRIPT
        MENUITEM "&Edit Script\tCtrl+E",        ID_FILE_EDITSCRIPT
        MENUITEM "&Window Spy",                 ID_FILE_WINDOWSPY
        MENUITEM SEPARATOR
        MENUITEM "&Pause Script\tPause",        ID_FILE_PAUSE
        MENUITEM "&Suspend Hotkeys",            ID_FILE_SUSPEND
        MENUITEM SEPARATOR
        MENUITEM "E&xit (Terminate Script)",    ID_FILE_EXIT
    END
    POPUP "&View"
    BEGIN
        MENUITEM "&Lines most recently executed\tCtrl+L", ID_VIEW_LINES
        MENUITEM "&Variables and their contents\tCtrl+V", ID_VIEW_VARIABLES
        MENUITEM "&Hotkeys and their methods\tCtrl+H", ID_VIEW_HOTKEYS
        MENUITEM "&Key history and script info\tCtrl+K", ID_VIEW_KEYHISTORY
        MENUITEM SEPARATOR
        MENUITEM "&Refresh\tF5",                ID_VIEW_REFRESH
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&User Manual",            ID_HELP_USERMANUAL
        MENUITEM "&Web Site",                   ID_HELP_WEBSITE
    END
END

Code: Select all

IDR_ACCELERATOR1 ACCELERATORS
BEGIN
VK_F1, ID_HELP_USERMANUAL, VIRTKEY, NOINVERT
"H", ID_VIEW_HOTKEYS, VIRTKEY, CONTROL, NOINVERT
"K", ID_VIEW_KEYHISTORY, VIRTKEY, CONTROL, NOINVERT
"L", ID_VIEW_LINES, VIRTKEY, CONTROL, NOINVERT
VK_F5, ID_VIEW_REFRESH, VIRTKEY, NOINVERT
"V", ID_VIEW_VARIABLES, VIRTKEY, CONTROL, NOINVERT
VK_PAUSE, ID_FILE_PAUSE, VIRTKEY, NOINVERT
"E", ID_FILE_EDITSCRIPT, VIRTKEY, CONTROL, NOINVERT
"R", ID_FILE_RELOADSCRIPT, VIRTKEY, CONTROL, NOINVERT
END
I've compiled ahk with \t<hotkey> and the accelerators removed and it solves my issue but obviously it breaks stuff like refreshing the Script lines most recently executed window.
(and yes, i know they're not all tray menu options but i don't know how to explain it better)


Oh and F1 also triggers LaunchAutoHotkeyHelp in script2.cpp so i comment out case ID_HELP_USERMANUAL: as well.

Windows created with standard Gui commands obviously don't have this issue so maybe i'm using CreateWindowEx wrong?

Return to “Ask for Help (v1)”