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.

215 lines
6.7 KiB

  1. // File: GenWindow.h
  2. #ifndef _GenWINDOW_H_
  3. #define _GenWINDOW_H_
  4. #include "Referenc.h"
  5. // Minimal interface for windows to talk to each other
  6. interface DECLSPEC_UUID("{9B677AA6-ACA3-11d2-9C97-00C04FB17782}")
  7. IGenWindow : public IUnknown
  8. {
  9. public:
  10. // Retrieve the desired size of a window so parents can layout their
  11. // children in an abstract manner
  12. virtual void GetDesiredSize(
  13. SIZE *psize // The returned desired size
  14. ) = 0;
  15. // Method to call when the desired size for a GenWindow changes
  16. virtual void OnDesiredSizeChanged() = 0;
  17. // Get the background brush to use
  18. virtual HBRUSH GetBackgroundBrush() = 0;
  19. // Get the palette the app is using
  20. virtual HPALETTE GetPalette() = 0;
  21. // Get the LPARAM of user data
  22. virtual LPARAM GetUserData() = 0;
  23. // Sends the registered c_msgFromHandle message to the hwnd. The hwnd
  24. // should return an IGenWindow* from that message
  25. static IGenWindow *FromHandle(
  26. HWND hwnd // The hwnd to get the IGenWindow* from
  27. );
  28. protected:
  29. // Registered message for retrieving the IGenWindow*
  30. static const DWORD c_msgFromHandle;
  31. } ;
  32. // Generic window class. Override the ProcessMessage method to add your own
  33. // functionality
  34. class DECLSPEC_UUID("{CEEA6922-ACA3-11d2-9C97-00C04FB17782}")
  35. CGenWindow : REFCOUNT, public IGenWindow
  36. {
  37. public:
  38. typedef void (*InvokeProc)(CGenWindow *pWin, WPARAM wParam);
  39. // Default constructor; inits a few intrinsics
  40. CGenWindow();
  41. // Create the window, analagous to Win32's CreateWindowEx. Only the
  42. // class name is missing, since CGenWindow works only for its own window
  43. // class
  44. BOOL Create(
  45. HWND hWndParent, // Window parent
  46. LPCTSTR szWindowName, // Window name
  47. DWORD dwStyle, // Window style
  48. DWORD dwEXStyle, // Extended window style
  49. int x, // Window pos: x
  50. int y, // Window pos: y
  51. int nWidth, // Window size: width
  52. int nHeight, // Window size: height
  53. HINSTANCE hInst, // The hInstance to create the window on
  54. HMENU hmMain=NULL, // Window menu
  55. LPCTSTR szClassName=NULL // The class name to use
  56. );
  57. // Create a child window, analagous to Win32's CreateWindowEx. The class
  58. // name is missing, since CGenWindow works only for its own window class.
  59. // Size and pos are also missing since most children will get layed out by
  60. // their parent.
  61. BOOL Create(
  62. HWND hWndParent, // Window parent
  63. INT_PTR nId=0, // ID of the child window
  64. LPCTSTR szWindowName=TEXT(""), // Window name
  65. DWORD dwStyle=0, // Window style; WS_CHILD|WS_VISIBLE will be added to this
  66. DWORD dwEXStyle=WS_EX_CONTROLPARENT // Extended window style
  67. );
  68. // Return the HWND
  69. inline HWND GetWindow()
  70. {
  71. return(m_hwnd);
  72. }
  73. // Override if you want to layout your window in a specific way when it
  74. // resizes.
  75. // Making this public so it can be forced on a window.
  76. virtual void Layout()
  77. {
  78. }
  79. // begin IGenWindow interface
  80. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID iid, LPVOID *pObj);
  81. virtual ULONG STDMETHODCALLTYPE AddRef(void) { return(REFCOUNT::AddRef()); }
  82. virtual ULONG STDMETHODCALLTYPE Release(void) { return(REFCOUNT::Release()); }
  83. virtual void GetDesiredSize(SIZE *ppt);
  84. // Forward the notification to the parent
  85. virtual void OnDesiredSizeChanged();
  86. // Get the background brush to use; use parent's by default
  87. virtual HBRUSH GetBackgroundBrush();
  88. // Get the palette the app is using
  89. virtual HPALETTE GetPalette();
  90. // Get the LPARAM of user data
  91. virtual LPARAM GetUserData();
  92. // end IGenWindow interface
  93. void SetUserData(LPARAM lUserData) { m_lUserData = lUserData; }
  94. // Set the global Hot control
  95. static void SetHotControl(CGenWindow *pHot);
  96. // Do a layout on this window at some time soon
  97. void ScheduleLayout();
  98. // Invoke on a posted message
  99. BOOL AsyncInvoke(InvokeProc proc, WPARAM wParam);
  100. // Set the tooltip for this window
  101. void SetTooltip(LPCTSTR pszTip);
  102. // Set the text of this window for accessibilty
  103. void SetWindowtext(LPCTSTR pszTip);
  104. // Remove the tooltip for this window
  105. void RemoveTooltip();
  106. // Get the standard palette for drawing
  107. static HPALETTE GetStandardPalette();
  108. // Delete the standard palette for drawing
  109. static void DeleteStandardPalette();
  110. // Get the standard palette for drawing
  111. static HBRUSH GetStandardBrush();
  112. // Delete the standard palette for drawing
  113. static void DeleteStandardBrush();
  114. protected:
  115. // Virtual destructor so clients can provide specific destruction code
  116. // This is protected to indicate that only Release should call it, not
  117. // creators of this object. I'd rather make it private, but then extenders
  118. // would not work.
  119. virtual ~CGenWindow();
  120. // The virtual window procedure. Override this to add specific behavior.
  121. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  122. // Set this control to be hot
  123. virtual void SetHot(BOOL bHot);
  124. // Is this control currently hot
  125. virtual BOOL IsHot();
  126. // Get the info necessary for displaying a tooltip
  127. virtual void GetSharedTooltipInfo(TOOLINFO *pti);
  128. private:
  129. // The current hot control
  130. static CGenWindow *g_pCurHot;
  131. // The standard palette
  132. static HPALETTE g_hPal;
  133. // Whether we actually need a palette or not
  134. static BOOL g_bNeedPalette;
  135. // The standard background brush
  136. static HBRUSH g_hBrush;
  137. // The single list of tooltip windows
  138. static class CTopWindowArray *g_pTopArray;
  139. // Stuff nobody should ever do
  140. CGenWindow(const CGenWindow& rhs);
  141. CGenWindow& operator=(const CGenWindow& rhs);
  142. // The window class name
  143. static const LPCTSTR c_szGenWindowClass;
  144. // Initalizes the window class
  145. static BOOL InitWindowClass(LPCTSTR szClassName, HINSTANCE hThis);
  146. // The real window procedure that sets up the "this" pointer and calls
  147. // ProcessMessage
  148. static LRESULT CALLBACK RealWindowProc(
  149. HWND hWnd,
  150. UINT message,
  151. WPARAM wParam,
  152. LPARAM lParam
  153. );
  154. // WM_NCCREATE handler. Stores away the "this" pointer.
  155. static BOOL OnNCCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct);
  156. // The hwnd associated with this object
  157. HWND m_hwnd;
  158. // A single LPARAM so no need to extend just to add a little data
  159. LPARAM m_lUserData;
  160. // WM_SIZE handler. Calls the Layout function.
  161. void OnSize(HWND hwnd, UINT state, int cx, int cy);
  162. // WM_ERASEBKGND handler. Clears the window.
  163. BOOL OnEraseBkgnd(HWND hwnd, HDC hdc);
  164. // WM_MOUSEMOVE handler; sets the Hot control
  165. void OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags);
  166. // clears the Hot tracking
  167. void OnMouseLeave();
  168. // Tells the parent to layout
  169. void OnShowWindow(HWND hwnd, BOOL fShow, int fnStatus);
  170. // Returns TRUE if the TT exists
  171. BOOL InitToolInfo(TOOLINFO *pti, LPTSTR pszText=NULL);
  172. } ;
  173. #endif // _GENWINDOW_H_