Source code of Windows XP (NT5)
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.

209 lines
5.9 KiB

  1. #ifndef __VAPPLICATION_HPP
  2. #define __VAPPLICATION_HPP
  3. #ifndef VWCL_WRAP_WINDOWS_ONLY
  4. #include "vPtrArray.hpp"
  5. #endif
  6. #include "vSimpleString.hpp"
  7. // <VDOC<CLASS=VApplication><DESC=Encapsulation of startup code, window handling logic, and support for internationalization><FAMILY=VWCL Core><AUTHOR=Todd Osborne ([email protected])>VDOC>
  8. class VApplication
  9. {
  10. public:
  11. VApplication()
  12. {
  13. // Initialize
  14. m_hInstance = NULL;
  15. m_hResource = NULL;
  16. #ifdef VWCL_INIT_OLE
  17. m_hrOleInitialize = E_UNEXPECTED;
  18. #endif
  19. #ifndef _CONSOLE
  20. #ifndef VWCL_WRAP_WINDOWS_ONLY
  21. m_nCommandShow = 0;
  22. m_nLastKnownMapIndex = -1;
  23. ZeroMemory(&m_CurrentMessage, sizeof(m_CurrentMessage));
  24. #endif
  25. m_hIcon = NULL;
  26. m_pMainWindow = NULL;
  27. #endif
  28. }
  29. virtual ~VApplication()
  30. {
  31. // Verify all allocated maps are gone
  32. #ifndef _CONSOLE
  33. #ifndef VWCL_WRAP_WINDOWS_ONLY
  34. while ( m_listWindowMaps.Size() )
  35. FreeWindowMap((LPVWCL_WINDOW_MAP)m_listWindowMaps[0]);
  36. #endif
  37. #endif
  38. // Free OLE
  39. #ifdef VWCL_INIT_OLE
  40. if ( SUCCEEDED(m_hrOleInitialize) )
  41. OleUninitialize();
  42. #endif
  43. }
  44. #ifndef _CONSOLE
  45. #ifndef VWCL_WRAP_WINDOWS_ONLY
  46. // Allocate and initialize a window map object and add to list of maps
  47. LPVWCL_WINDOW_MAP AllocWindowMap(VWindow* pWindow, HWND hWnd = NULL);
  48. #endif
  49. #endif
  50. // Get / Set the title for this application
  51. LPCTSTR AppTitle(LPCTSTR lpszAppTitle)
  52. { m_strAppTitle.String(lpszAppTitle); return m_strAppTitle.String(); }
  53. LPCTSTR AppTitle()
  54. { return m_strAppTitle.String(); }
  55. // Get / Set the current open file
  56. LPCTSTR CurrentFile()
  57. { return m_strCurrentFile.String(); }
  58. LPCTSTR CurrentFile(LPCTSTR lpszFileName, BOOL bUpdateCaption = TRUE);
  59. #ifndef _CONSOLE
  60. #ifndef VWCL_WRAP_WINDOWS_ONLY
  61. // Setup mappings of VWindow object to Windows window handle, and subclass non-VWCL class windows
  62. BOOL Attach(VWindow* pWindow, HWND hWnd);
  63. // Remove any subclassing from the VWindow object, but do not destroy the window.
  64. // This function has no effect on VWCL registered and instantiated windows
  65. void Detach(VWindow* pWindow);
  66. // Free a window map object and remove from list of maps
  67. void FreeWindowMap(LPVWCL_WINDOW_MAP lpMap);
  68. #endif
  69. // Get command show param (the ShowWindow() API SW_xxx Constant)
  70. int GetCommandShow()
  71. { return m_nCommandShow; }
  72. #ifndef VWCL_WRAP_WINDOWS_ONLY
  73. // Get the message currently being processed
  74. LPMSG GetCurrentMessage()
  75. { return &m_CurrentMessage; }
  76. #endif
  77. #endif
  78. // Get instance handle
  79. HINSTANCE GetInstanceHandle()
  80. { assert(m_hInstance); return m_hInstance; }
  81. #ifndef _CONSOLE
  82. #ifndef VWCL_WRAP_WINDOWS_ONLY
  83. // Return the global WindowProc() procedure used by all VWCL windows
  84. WNDPROC GetWindowProc()
  85. { return WindowProc; }
  86. #endif
  87. // Get / Set icon
  88. HICON Icon()
  89. { return m_hIcon; }
  90. HICON Icon(HICON hIcon)
  91. { m_hIcon = hIcon; return m_hIcon; }
  92. #endif
  93. // Initialize class library, application startup, and register window classes
  94. // The icon and menu names will be used only for main window objects. You can optionally
  95. // provide a background color to use for registered window classes. One function is provided
  96. // for when windowing applications are being built, and others for when a console app is
  97. #ifndef _CONSOLE
  98. BOOL Initialize(HINSTANCE hInstance, int nCommandShow, UINT nIDMenu, UINT nIDIcon, HBRUSH hBackgroundBrush = (HBRUSH)(COLOR_WINDOW + 1));
  99. #else
  100. BOOL Initialize(HINSTANCE hInstance)
  101. {
  102. assert(hInstance);
  103. // Global application object should be uninitialized, you are walking on it!
  104. assert(m_hInstance == NULL);
  105. m_hInstance = hInstance;
  106. // Initialize Component Object Model
  107. #ifdef VWCL_INIT_OLE
  108. m_hrOleInitialize = OleInitialize(NULL);
  109. if ( FAILED(m_hrOleInitialize) )
  110. return FALSE;
  111. #endif
  112. return TRUE;
  113. }
  114. #endif
  115. // Returns TRUE if class library has been initialized (Instance handle set)
  116. BOOL IsInitialized()
  117. { return (m_hInstance) ? TRUE : FALSE; }
  118. #ifndef _CONSOLE
  119. // Get / Set main window pointer
  120. VWindow* MainWindow()
  121. { return m_pMainWindow; }
  122. VWindow* MainWindow(VWindow* pWindow)
  123. { m_pMainWindow = pWindow; return m_pMainWindow; }
  124. #endif
  125. // / Get / Set the resource handle. By default this is the same as instance
  126. HINSTANCE ResourceHandle()
  127. { assert(m_hResource); return m_hResource; }
  128. HINSTANCE ResourceHandle(HINSTANCE hResource)
  129. { assert(hResource); m_hResource = hResource; return m_hResource; }
  130. #ifndef _CONSOLE
  131. #ifndef VWCL_WRAP_WINDOWS_ONLY
  132. // Create a window using specified CREATESTRUCT and call Attach()
  133. // to attach it to a VWindow object, and add to map. All memory
  134. // allocations (AllocWindowMap) will be done for calling code
  135. BOOL VCreateWindow(VWindow* pWindow, LPCREATESTRUCT lpCreateStruct, BOOL bDontCallPostCreateWindow = FALSE);
  136. // Get a VWindow pointer when a HWND is known. Returns NULL on failure
  137. VWindow* VWindowFromHandle(HWND hWnd);
  138. #endif
  139. #endif
  140. protected:
  141. #ifndef _CONSOLE
  142. #ifndef VWCL_WRAP_WINDOWS_ONLY
  143. // Resolves hWnd to VWindow objects and dispatches message
  144. LRESULT HandleMessage(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
  145. // Shared window procedure by all VWindow and derived objects. This function
  146. // simply resolves the global application object and calls VWindow object to handle message
  147. static LRESULT CALLBACK WindowProc(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
  148. #endif
  149. #endif
  150. private:
  151. // Embedded Members
  152. HINSTANCE m_hInstance;
  153. HINSTANCE m_hResource;
  154. VSimpleString m_strAppTitle;
  155. VSimpleString m_strCurrentFile;
  156. #ifdef VWCL_INIT_OLE
  157. HRESULT m_hrOleInitialize;
  158. #endif
  159. #ifndef _CONSOLE
  160. HICON m_hIcon;
  161. int m_nCommandShow;
  162. VWindow* m_pMainWindow;
  163. #ifndef VWCL_WRAP_WINDOWS_ONLY
  164. MSG m_CurrentMessage;
  165. VPtrArray m_listWindowMaps;
  166. int m_nLastKnownMapIndex;
  167. #endif
  168. #endif
  169. };
  170. #endif // __VAPPLICATION_HPP