Lexikos
Joined: 17 Oct 2006 Posts: 2364 Location: Australia, Qld
|
Posted: Thu Feb 14, 2008 9:25 am Post subject: Menu, Tray, MainWindow does not enable menu items. |
|
|
According to the manual,
| Code: | Menu, Tray, MainWindow
| should enable the menu items under "View".
| Quote: | MainWindow: This command affects compiled scripts only. It allows the script's main window to be opened via the tray icon, which is otherwise impossible. It also enables the items in the main window's View menu such as "Lines most recently executed", which allows viewing of the script's source code and other info. MenuName must be TRAY.
| The following script, compiled with v1.0.47.05, enables the main window but does not enable those menu items:
| Code: | #Persistent
Menu, Tray, MainWindow
| Sending the relevant messages does work:
| Code: | SendMessage, WM_COMMAND:=0x111, ID_VIEW_LINES:=65406,,, ahk_class AutoHotkey
| (This works only because Menu, Tray, MainWindow has been used.)
Analysis of the AutoHotkey source code reveals:
- g_AllowMainWindow, which exists only for compiled scripts, defaults to false.
- Menu, Tray, MainWindow sets g_AllowMainWindow = true.
- The menu items are disabled by CreateWindows() if g_AllowMainWindow = false.
- CreateWindows() is called only once, before the script starts and gets a chance to change g_AllowMainWindow.
- The menu items are never explicitly enabled after being created.
The menu items can be enabled manually:
| Code: | ; Find this script's main window.
DetectHiddenWindows, On
Process, Exist
main_window := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
DetectHiddenWindows, Off
; Get the View menu.
menu_bar := DllCall("GetMenu", "uint", main_window)
menu_view := DllCall("GetSubMenu", "uint", menu_bar, "int", 1)
; Enable the View menu items.
Loop, 4
DllCall("EnableMenuItem", "uint", menu_view, "uint", 65405+A_Index, "uint", 0)
/*
#define ID_VIEW_LINES 65406
#define ID_VIEW_VARIABLES 65407
#define ID_VIEW_HOTKEYS 65408
#define ID_VIEW_KEYHISTORY 65409
*/
|
|
|