AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Menu, Tray, MainWindow does not enable menu items.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Lexikos



Joined: 17 Oct 2006
Posts: 2364
Location: Australia, Qld

PostPosted: Thu Feb 14, 2008 9:25 am    Post subject: Menu, Tray, MainWindow does not enable menu items. Reply with quote

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
*/
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Mon Mar 03, 2008 12:23 am    Post subject: Reply with quote

Thanks for making it really easy Smile. This fix will be in the next release.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group