| 4581 | ///////////////// |
| 4582 | |
| 4583 | LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) |
| 4584 | { |
| 4585 | int i; |
| 4586 | |
| 4587 | // Detect Explorer crashes so that tray icon can be recreated. I think this only works on Win98 |
| 4588 | // and beyond, since the feature was never properly implemented in Win95: |
| 4589 | static UINT WM_TASKBARCREATED = RegisterWindowMessage("TaskbarCreated"); |
| 4590 | |
| 4591 | TRANSLATE_AHK_MSG(iMsg, wParam) |
| 4592 | |
| 4593 | switch (iMsg) |
| 4594 | { |
| 4595 | case WM_COMMAND: |
| 4596 | if (HandleMenuItem(LOWORD(wParam), INT_MAX)) // It was handled fully. INT_MAX says "no gui window". |
| 4597 | return 0; // If an application processes this message, it should return zero. |
| 4598 | break; // Otherwise, let DefWindowProc() try to handle it (this actually seems to happen normally sometimes). |
| 4599 | |
| 4600 | case AHK_NOTIFYICON: // Tray icon clicked on. |
| 4601 | { |
| 4602 | switch(lParam) |
| 4603 | { |
| 4604 | // Don't allow the main window to be opened this way by a compiled EXE, since it will display |
| 4605 | // the lines most recently executed, and many people who compile scripts don't want their users |
| 4606 | // to see the contents of the script: |
| 4607 | case WM_LBUTTONDOWN: |
| 4608 | if (g_script.mTrayMenu->mClickCount != 1) // Activating tray menu's default item requires double-click. |
| 4609 | break; // Let default proc handle it (since that's what used to happen, it seems safest). |
| 4610 | //else fall through to the next case. |
| 4611 | case WM_LBUTTONDBLCLK: |
| 4612 | if (g_script.mTrayMenu->mDefault) |
| 4613 | HANDLE_USER_MENU(g_script.mTrayMenu->mDefault->mMenuID, -1) |
| 4614 | #ifdef AUTOHOTKEYSC |
| 4615 | else if (g_script.mTrayMenu->mIncludeStandardItems && g_AllowMainWindow) |
| 4616 | ShowMainWindow(); |
| 4617 | // else do nothing. |
| 4618 | #else |
| 4619 | else if (g_script.mTrayMenu->mIncludeStandardItems) |
| 4620 | ShowMainWindow(); |
| 4621 | // else do nothing. |
| 4622 | #endif |
| 4623 | return 0; |
| 4624 | case WM_RBUTTONDOWN: |
| 4625 | g_script.mTrayMenu->Display(false); |
| 4626 | return 0; |
| 4627 | } // Inner switch() |
| 4628 | break; |
| 4629 | } // case AHK_NOTIFYICON |
| 4630 | |
| 4631 | case AHK_DIALOG: // User defined msg sent from our functions MsgBox() or FileSelectFile(). |
| 4632 | { |
| 4633 | // Always call this to close the clipboard if it was open (e.g. due to a script |
| 4634 | // line such as "MsgBox, %clipboard%" that got us here). Seems better just to |
| 4635 | // do this rather than incurring the delay and overhead of a MsgSleep() call: |
| 4636 | CLOSE_CLIPBOARD_IF_OPEN; |
| 4637 | |
| 4638 | // Ensure that the app's top-most window (the modal dialog) is the system's |
| 4639 | // foreground window. This doesn't use FindWindow() since it can hang in rare |
| 4640 | // cases. And GetActiveWindow, GetTopWindow, GetWindow, etc. don't seem appropriate. |
nothing calls this directly
no test coverage detected