MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / ShowMainWindow

Function ShowMainWindow

Source/script2.cpp:5188–5288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5186
5187
5188ResultType ShowMainWindow(MainWindowModes aMode, bool aRestricted)
5189// Always returns OK for caller convenience.
5190{
5191 // 32767 might be the limit for an edit control, at least under Win95.
5192 // Later maybe use the EM_REPLACESEL method to avoid this limit if the
5193 // OS is WinNT/2k/XP:
5194 char buf_temp[32767] = "";
5195 bool jump_to_bottom = false; // Set default behavior for edit control.
5196 static MainWindowModes current_mode = MAIN_MODE_NO_CHANGE;
5197
5198#ifdef AUTOHOTKEYSC
5199 // If we were called from a restricted place, such as via the Tray Menu or the Main Menu,
5200 // don't allow potentially sensitive info such as script lines and variables to be shown.
5201 // This is done so that scripts can be compiled more securely, making it difficult for anyone
5202 // to use ListLines to see the author's source code. Rather than make exceptions for things
5203 // like KeyHistory, it seems best to forbit all information reporting except in cases where
5204 // existing info in the main window -- which must have gotten their via an allowed command
5205 // such as ListLines encountered in the script -- is being refreshed. This is because in
5206 // that case, the script author has given de facto permission for that loophole (and it's
5207 // a pretty small one, not easy to exploit):
5208 if (aRestricted && !g_AllowMainWindow && (current_mode == MAIN_MODE_NO_CHANGE || aMode != MAIN_MODE_REFRESH))
5209 {
5210 SendMessage(g_hWndEdit, WM_SETTEXT, 0, (LPARAM)
5211 "Script info will not be shown because the \"Menu, Tray, MainWindow\"\r\n"
5212 "command option was not enabled in the original script.");
5213 return OK;
5214 }
5215#endif
5216
5217 // If the window is empty, caller wants us to default it to showing the most recently
5218 // executed script lines:
5219 if (current_mode == MAIN_MODE_NO_CHANGE && (aMode == MAIN_MODE_NO_CHANGE || aMode == MAIN_MODE_REFRESH))
5220 aMode = MAIN_MODE_LINES;
5221
5222 switch (aMode)
5223 {
5224 // case MAIN_MODE_NO_CHANGE: do nothing
5225 case MAIN_MODE_LINES:
5226 Line::LogToText(buf_temp, sizeof(buf_temp));
5227 jump_to_bottom = true;
5228 break;
5229 case MAIN_MODE_VARS:
5230 g_script.ListVars(buf_temp, sizeof(buf_temp));
5231 break;
5232 case MAIN_MODE_HOTKEYS:
5233 Hotkey::ListHotkeys(buf_temp, sizeof(buf_temp));
5234 break;
5235 case MAIN_MODE_KEYHISTORY:
5236 g_script.ListKeyHistory(buf_temp, sizeof(buf_temp));
5237 break;
5238 case MAIN_MODE_REFRESH:
5239 // Rather than do a recursive call to self, which might stress the stack if the script is heavily recursed:
5240 switch (current_mode)
5241 {
5242 case MAIN_MODE_LINES:
5243 Line::LogToText(buf_temp, sizeof(buf_temp));
5244 jump_to_bottom = true;
5245 break;

Callers 3

script.cppFile · 0.85
MainWindowProcFunction · 0.85
HandleMenuItemFunction · 0.85

Calls 3

SetForegroundWindowExFunction · 0.85
ListVarsMethod · 0.80
ListKeyHistoryMethod · 0.80

Tested by

no test coverage detected