Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.5 KiB

  1. #ifndef APPLICATION_H
  2. #define APPLICATION_H
  3. #include "stdafx.h"
  4. //
  5. // Application-specific windows message to defer processing of UI.
  6. // wParam -- unused
  7. // lParam -- a pointer to an allocated CUIWorkItem object.
  8. // See document.h for details on the use of this object.
  9. //
  10. #define MYWM_DEFER_UI_MSG (WM_USER+1)
  11. class Application : public CWinApp
  12. {
  13. public:
  14. Application( LPCTSTR lpszAppName = NULL )
  15. : m_dwMainThreadId(0),
  16. m_lMsgProcReentrancyCount(0),
  17. m_fQuit(FALSE),
  18. CWinApp(lpszAppName)
  19. {
  20. InitializeCriticalSection(&m_crit);
  21. }
  22. ~Application()
  23. {
  24. DeleteCriticalSection(&m_crit);
  25. }
  26. virtual BOOL InitInstance();
  27. BOOL
  28. ProcessShellCommand( CNlbMgrCommandLineInfo& rCmdInfo ); // overrides base
  29. afx_msg void OnHelp();
  30. afx_msg void OnAppAbout();
  31. //
  32. // If called in main thread's context:
  33. // Process the msg queue and do background idle work
  34. // Else (some other thread)
  35. // Do nothing
  36. //
  37. void
  38. ProcessMsgQueue();
  39. //
  40. // Get application-wide lock. If main thread, while waiting to get the lock,
  41. // periodically process the msg loop.
  42. //
  43. VOID
  44. Lock();
  45. //
  46. // Get application-wide unlock
  47. //
  48. VOID
  49. Unlock();
  50. BOOL
  51. IsMainThread(void)
  52. {
  53. #if BUGFIX334243
  54. return mfn_IsMainThread();
  55. #else // !BUGFIX334243
  56. return TRUE;
  57. #endif // !BUGFIX334243
  58. }
  59. //
  60. // Returns return TRUE IFF called in the context of ProcessMsgQueue.
  61. //
  62. BOOL
  63. IsProcessMsgQueueExecuting(void)
  64. {
  65. return (m_lMsgProcReentrancyCount > 0);
  66. }
  67. VOID
  68. SetQuit(void)
  69. {
  70. m_fQuit = TRUE;
  71. }
  72. DECLARE_MESSAGE_MAP()
  73. private:
  74. BOOL
  75. mfn_IsMainThread(void)
  76. {
  77. return (GetCurrentThreadId() == m_dwMainThreadId);
  78. }
  79. CSingleDocTemplate *m_pSingleDocumentTemplate;
  80. //
  81. // The thread ID of the main thread -- used to decide if a thread is
  82. // the main application thread.
  83. //
  84. DWORD m_dwMainThreadId;
  85. CRITICAL_SECTION m_crit;
  86. //
  87. // Following keeps count of the number times ProcessMsgQueue is reentered.
  88. // It is incremented/decremented using InterlockedIncrement/Decrement,
  89. // and the lock is NOT held while doing so.
  90. //
  91. LONG m_lMsgProcReentrancyCount;
  92. BOOL m_fQuit;
  93. };
  94. extern Application theApplication;
  95. #endif