| 4068 | ///////////////// |
| 4069 | |
| 4070 | LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) |
| 4071 | { |
| 4072 | // Detect Explorer crashes so that tray icon can be recreated. I think this only works on Win98 |
| 4073 | // and beyond, since the feature was never properly implemented in Win95: |
| 4074 | static UINT WM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); |
| 4075 | |
| 4076 | // See GuiWindowProc() for details about this first section: |
| 4077 | LRESULT msg_reply; |
| 4078 | if (g_MsgMonitor.Count() // Count is checked here to avoid function-call overhead. |
| 4079 | && (!g->CalledByIsDialogMessageOrDispatch || g->CalledByIsDialogMessageOrDispatchMsg != iMsg) // v1.0.44.11: If called by IsDialog or Dispatch but they changed the message number, check if the script is monitoring that new number. |
| 4080 | && MsgMonitor(hWnd, iMsg, wParam, lParam, NULL, msg_reply)) |
| 4081 | return msg_reply; // MsgMonitor has returned "true", indicating that this message should be omitted from further processing. |
| 4082 | g->CalledByIsDialogMessageOrDispatch = false; // v1.0.40.01. |
| 4083 | |
| 4084 | TRANSLATE_AHK_MSG(iMsg, wParam) |
| 4085 | |
| 4086 | switch (iMsg) |
| 4087 | { |
| 4088 | case WM_COMMAND: |
| 4089 | if (HandleMenuItem(hWnd, LOWORD(wParam), NULL)) // It was handled fully. NULL flags it as a non-GUI menu item such as a tray menu or popup menu. |
| 4090 | return 0; // If an application processes this message, it should return zero. |
| 4091 | break; // Otherwise, let DefWindowProc() try to handle it (this actually seems to happen normally sometimes). |
| 4092 | |
| 4093 | case AHK_NOTIFYICON: // Tray icon clicked on. |
| 4094 | { |
| 4095 | switch(lParam) |
| 4096 | { |
| 4097 | // Don't allow the main window to be opened this way by a compiled EXE, since it will display |
| 4098 | // the lines most recently executed, and many people who compile scripts don't want their users |
| 4099 | // to see the contents of the script: |
| 4100 | case WM_LBUTTONDOWN: |
| 4101 | if (g_script.mTrayMenu->mClickCount != 1) // Activating tray menu's default item requires double-click. |
| 4102 | break; // Let default proc handle it (since that's what used to happen, it seems safest). |
| 4103 | //else fall through to the next case. |
| 4104 | case WM_LBUTTONDBLCLK: |
| 4105 | if (g_script.mTrayMenu->mDefault) |
| 4106 | PostMessage(hWnd, WM_COMMAND, g_script.mTrayMenu->mDefault->mMenuID, 0); // WM_COMMAND vs POST_AHK_USER_MENU to support the Standard menu items. |
| 4107 | return 0; |
| 4108 | case WM_RBUTTONUP: |
| 4109 | // v1.0.30.03: |
| 4110 | // Opening the menu upon UP vs. DOWN solves at least one set of problems: The fact that |
| 4111 | // when the right mouse button is remapped as shown in the example below, it prevents |
| 4112 | // the left button from being able to select a menu item from the tray menu. It might |
| 4113 | // solve other problems also, and it seems fairly common for other apps to open the |
| 4114 | // menu upon UP rather than down. Even Explorer's own context menus are like this. |
| 4115 | // The following example is trivial and serves only to illustrate the problem caused |
| 4116 | // by the old open-tray-on-mouse-down method: |
| 4117 | //MButton::Send {RButton down} |
| 4118 | //MButton up::Send {RButton up} |
| 4119 | g_script.mTrayMenu->Display(false); |
| 4120 | return 0; |
| 4121 | } // Inner switch() |
| 4122 | break; |
| 4123 | } // case AHK_NOTIFYICON |
| 4124 | |
| 4125 | case AHK_DIALOG: // User defined msg sent from our functions MsgBox() or FileSelect(). |
| 4126 | { |
| 4127 | // Ensure that the app's top-most window (the modal dialog) is the system's |
nothing calls this directly
no test coverage detected