PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/source/application.h

https://github.com/zhanglei17/ahkdll
C Header | 106 lines | 55 code | 11 blank | 40 comment | 10 complexity | ecb3dd772342c6eb78b9f1efe0c2c9f5 MD5 | raw file
  1. /*
  2. AutoHotkey
  3. Copyright 2003-2009 Chris Mallett (support@autohotkey.com)
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. */
  13. #ifndef application_h
  14. #define application_h
  15. #include "defines.h"
  16. // Callers should note that using INTERVAL_UNSPECIFIED might not rest the CPU at all if there is
  17. // already at least one msg waiting in our thread's msg queue:
  18. // Use some negative value unlikely to ever be passed explicitly:
  19. #define INTERVAL_UNSPECIFIED (INT_MIN + 303)
  20. #define NO_SLEEP -1
  21. enum MessageMode {WAIT_FOR_MESSAGES, RETURN_AFTER_MESSAGES, RETURN_AFTER_MESSAGES_SPECIAL_FILTER};
  22. bool MsgSleep(int aSleepDuration = INTERVAL_UNSPECIFIED, MessageMode aMode = RETURN_AFTER_MESSAGES);
  23. // This macro is used to Sleep without the possibility of a new hotkey subroutine being launched.
  24. // Timed subroutines will also be prevented from running while it is enabled.
  25. // It should be used when an operation needs to sleep, but doesn't want to be interrupted (suspended)
  26. // by any hotkeys the user might press during that time. Reasons why the caller wouldn't want to
  27. // be suspended:
  28. // 1) If it's doing something with a window -- such as sending keys or clicking the mouse or trying
  29. // to activate it -- that might get messed up if a new hotkey fires in the middle of the operation.
  30. // 2) If its a command that's still using some of its parameters that might reside in the deref buffer.
  31. // In this case, the launching of a new hotkey would likely overwrite those values, causing
  32. // unpredictable behavior.
  33. #define SLEEP_WITHOUT_INTERRUPTION(aSleepTime) \
  34. {\
  35. g_AllowInterruption = FALSE;\
  36. MsgSleep(aSleepTime);\
  37. g_AllowInterruption = TRUE;\
  38. }
  39. // Have this be dynamically resolved each time. For example, when MsgSleep() uses this
  40. // while in mode WAIT_FOR_MESSSAGES, its msg loop should use this macro in case the
  41. // value of g_AllowInterruption changes from one iteration to the next. Thankfully,
  42. // MS made WM_HOTKEY have a very high value, so filtering in this way should not exclude
  43. // any other important types of messages:
  44. #define MSG_FILTER_MAX (IsInterruptible() ? 0 : WM_HOTKEY - 1)
  45. #ifndef MINIDLL
  46. #define INTERRUPTIBLE_IN_EMERGENCY (g_AllowInterruption && !g_MenuIsVisible)
  47. #else
  48. #define INTERRUPTIBLE_IN_EMERGENCY (g_AllowInterruption)
  49. #endif
  50. // Do a true Sleep() for short sleeps on Win9x because it is much more accurate than the MsgSleep()
  51. // method on that OS, at least for when short sleeps are done on Win98SE:
  52. #define DoWinDelay \
  53. if (::g->WinDelay > -1)\
  54. {\
  55. if (::g->WinDelay < 25 && g_os.IsWin9x())\
  56. Sleep(::g->WinDelay);\
  57. else\
  58. MsgSleep(::g->WinDelay);\
  59. }
  60. #define DoControlDelay \
  61. if (g->ControlDelay > -1)\
  62. {\
  63. if (g->ControlDelay < 25 && g_os.IsWin9x())\
  64. Sleep(g->ControlDelay);\
  65. else\
  66. MsgSleep(g->ControlDelay);\
  67. }
  68. ResultType IsCycleComplete(int aSleepDuration, DWORD aStartTime, bool aAllowEarlyReturn);
  69. // These should only be called from MsgSleep() (or something called by MsgSleep()) because
  70. // we don't want to be in the situation where a thread launched by CheckScriptTimers() returns
  71. // first to a dialog's message pump rather than MsgSleep's pump. That's because our thread
  72. // might then have queued messages that would be stuck in the queue (due to the possible absence
  73. // of the main timer) until the dialog's msg pump ended.
  74. bool CheckScriptTimers();
  75. #define CHECK_SCRIPT_TIMERS_IF_NEEDED if (g_script.mTimerEnabledCount && CheckScriptTimers()) return_value = true; // Change the existing value only if it returned true.
  76. #ifndef MINIDLL
  77. void PollJoysticks();
  78. #define POLL_JOYSTICK_IF_NEEDED if (Hotkey::sJoyHotkeyCount) PollJoysticks();
  79. #endif
  80. bool MsgMonitor(HWND aWnd, UINT aMsg, WPARAM awParam, LPARAM alParam, MSG *apMsg, LRESULT &aMsgReply);
  81. void InitNewThread(int aPriority, bool aSkipUninterruptible, bool aIncrementThreadCountAndUpdateTrayIcon
  82. , ActionTypeType aTypeOfFirstLine);
  83. void ResumeUnderlyingThread(LPTSTR aSavedErrorLevel);
  84. BOOL IsInterruptible();
  85. VOID CALLBACK MsgBoxTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  86. VOID CALLBACK AutoExecSectionTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  87. VOID CALLBACK UninterruptibleTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  88. #ifndef MINIDLL
  89. VOID CALLBACK InputTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  90. #endif
  91. VOID CALLBACK RefreshInterruptibility(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  92. #endif