InsidePropPage.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /////////////////////////////////////////////////////////////////////////////
  2. // InsidePropPage.cpp | Implementation of the TCInsidePropPage class.
  3. #include "InsidePropPage.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // TCInsidePropPage
  6. /////////////////////////////////////////////////////////////////////////////
  7. // Group=Construction
  8. /////////////////////////////////////////////////////////////////////////////
  9. // {group:Construction}
  10. // Constructs an instance of this class.
  11. TCInsidePropPage::TCInsidePropPage()
  12. {
  13. }
  14. /////////////////////////////////////////////////////////////////////////////
  15. // Description: Creates an embedded property page as a child window.
  16. //
  17. // Call this method to create an embedded property page as a child window of
  18. // the specified parent window. The /idPosCtrl/ parameter is used to specify
  19. // an existing child window that is used to position and, optionally, size
  20. // the embedded property page. This allows, for example, the layout of a
  21. // dialog/property page to be designed in an editor such as Developer Studio,
  22. // with the embedded property page represented by a static frame or rectangle
  23. // control. The ID of the static control can then be specified in the call to
  24. // Create, which will use the control to position the embedded property page.
  25. //
  26. // Parameters:
  27. // hwndParent - Specifies the parent window of the embedded property page.
  28. // pPageSite - Specifies the *IPropertyPageSite* interface pointer to be
  29. // set on the embedded property page.
  30. // idPosCtrl - Specifies an existing child window of /hwndParent/ that is
  31. // used to position, and optionally, size the embedded property page.
  32. // clsid - Specifies the component object CLSID of the property page to be
  33. // created and embedded within /hwndParent/.
  34. // bVisible - Specifies if the embedded property page should initially be
  35. // made visible. A value of *true* indicates to make the page immediately
  36. // visible, while *false* indicates that the page will initially be hidden.
  37. // bSizeToCtrl - When *true*, the embedded property page will be made the
  38. // same size as the control specified in /idPosCtrl/. Otherwise,
  39. // *false* specifies that the page will be the size indicated by its
  40. // *IPropertyPage::GetPageInfo* method.
  41. // bDelCtrl - When *true*, the child window identified by /idPosCtrl/ will
  42. // be destroyed after it is used to position the embedded property page.
  43. // Otherwise, *false* indicates that the positioning window will remain in
  44. // existence, but will be hidden. When only one property page is to be
  45. // created at the position of the control, this will usually be *true*, since
  46. // the positioning window would no longer be needed. When a /group/ of
  47. // property pages is to be create in the same position, however, this
  48. // parameter should be *false* so that the window can be used repeatedly for
  49. // positioning each page of the group.
  50. //
  51. // Return Value: *true* if the child property page was created, otherwise
  52. // *false*.
  53. //
  54. // See Also: TCInsidePropertyPage::m_pPageSite,
  55. // TCPropertyPageSite::Page_Create, CWindowImpl::Create
  56. bool TCInsidePropPage::Create(HWND hwndParent, IPropertyPageSite* pPageSite,
  57. UINT idPosCtrl, REFCLSID clsid, bool bVisible, bool bSizeToCtrl,
  58. bool bDelCtrl)
  59. {
  60. // Attempt to find the specified control in the specified parent
  61. HWND hwndPos = ::GetDlgItem(hwndParent, idPosCtrl);
  62. // Fail if the parent window does not have the specified control
  63. if (!hwndPos)
  64. {
  65. assert(false);
  66. return false;
  67. }
  68. // Create the property page
  69. HRESULT hr = Page_Create(clsid);
  70. if (FAILED(hr))
  71. {
  72. assert(false);
  73. return false;
  74. }
  75. // Get the rectangle of the positioning window
  76. RECT rc;
  77. ::GetWindowRect(hwndPos, &rc);
  78. ::MapWindowPoints(NULL, hwndParent, LPPOINT(&rc), 2);
  79. if (!bSizeToCtrl)
  80. {
  81. rc.right = rc.left + GetSize().cx;
  82. rc.bottom = rc.top + GetSize().cy;
  83. }
  84. // Determine the styles of the window
  85. DWORD dwStyle = WS_CHILD | WS_GROUP | DS_CONTROL;
  86. if (bVisible)
  87. dwStyle |= WS_VISIBLE;
  88. DWORD dwExStyle = WS_EX_CONTROLPARENT;
  89. // Create the window
  90. HWND hwnd = CWindowImpl<TCInsidePropPage>::Create(hwndParent, rc, NULL,
  91. dwStyle, dwExStyle, idPosCtrl);
  92. if (!hwnd)
  93. return false;
  94. // Position the page window in front of the positioning window
  95. ::SetWindowPos(hwnd, hwndPos, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  96. // Show the property page
  97. _VERIFYE(SUCCEEDED(hr = Page_Show()));
  98. if (FAILED(hr))
  99. return false;
  100. // Delete the positioning window, if specified, otherwise hide it
  101. if (bDelCtrl)
  102. ::DestroyWindow(hwndPos);
  103. else
  104. ::ShowWindow(hwndPos, SW_HIDE);
  105. // Save the page site interface pointer
  106. m_pPageSite = pPageSite;
  107. // Indicate success
  108. return true;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Group=Overrides
  112. /////////////////////////////////////////////////////////////////////////////
  113. // Delegates to the corresponding *IPropertyPageSite* interface method of
  114. // m_pPageSite, if not *NULL*. Otherwise, the method of the base class,
  115. // TCPropertyPageSite, is called.
  116. //
  117. // Parameters:
  118. // dwFlags - See TCPropertyPageSite::OnStatusChange.
  119. //
  120. // Return Value: See TCPropertyPageSite::OnStatusChange.
  121. //
  122. // See Also: TCInsidePropPage::Create, TCInsidePropPage::m_pPageSite,
  123. // TCPropertyPageSite::OnStatusChange
  124. HRESULT TCInsidePropPage::OnStatusChange(DWORD dwFlags)
  125. {
  126. // Delegate to property page site, if set
  127. if (NULL != m_pPageSite)
  128. return m_pPageSite->OnStatusChange(dwFlags);
  129. // Perform default processing
  130. return TCPropertyPageSite::OnStatusChange(dwFlags);
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. // Delegates to the corresponding *IPropertyPageSite* interface method of
  134. // m_pPageSite, if not *NULL*. Otherwise, the method of the base class,
  135. // TCPropertyPageSite, is called.
  136. //
  137. // Parameters:
  138. // pLocaleID - See TCPropertyPageSite::OnGetLocaleID.
  139. //
  140. // Return Value: See TCPropertyPageSite::OnGetLocaleID.
  141. //
  142. // See Also: TCInsidePropPage::Create, TCInsidePropPage::m_pPageSite,
  143. // TCPropertyPageSite::OnGetLocaleID
  144. HRESULT TCInsidePropPage::OnGetLocaleID(LCID* pLocaleID)
  145. {
  146. // Delegate to property page site, if set
  147. if (NULL != m_pPageSite)
  148. return m_pPageSite->GetLocaleID(pLocaleID);
  149. // Perform default processing
  150. return TCPropertyPageSite::OnGetLocaleID(pLocaleID);
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // Delegates to the corresponding *IPropertyPageSite* interface method of
  154. // m_pPageSite, if not *NULL*. Otherwise, the method of the base class,
  155. // TCPropertyPageSite, is called.
  156. //
  157. // Parameters:
  158. // ppUnk - See TCPropertyPageSite::OnGetPageContainer.
  159. //
  160. // Return Value: See TCPropertyPageSite::OnGetPageContainer.
  161. //
  162. // See Also: TCInsidePropPage::Create, TCInsidePropPage::m_pPageSite,
  163. // TCPropertyPageSite::OnGetPageContainer
  164. HRESULT TCInsidePropPage::OnGetPageContainer(IUnknown** ppUnk)
  165. {
  166. // Delegate to property page site, if set
  167. if (NULL != m_pPageSite)
  168. return m_pPageSite->GetPageContainer(ppUnk);
  169. // Perform default processing
  170. return TCPropertyPageSite::OnGetPageContainer(ppUnk);
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. // Delegates to the corresponding *IPropertyPageSite* interface method of
  174. // m_pPageSite, if not *NULL*. Otherwise, the method of the base class,
  175. // TCPropertyPageSite, is called.
  176. //
  177. // Parameters:
  178. // pMsg - See TCPropertyPageSite::OnTranslateAccelerator.
  179. //
  180. // Return Value: See TCPropertyPageSite::OnTranslateAccelerator.
  181. //
  182. // See Also: TCInsidePropPage::Create, TCInsidePropPage::m_pPageSite,
  183. // TCPropertyPageSite::OnTranslateAccelerator
  184. HRESULT TCInsidePropPage::OnTranslateAccelerator(MSG* pMsg)
  185. {
  186. // Delegate to property page site, if set
  187. if (NULL != m_pPageSite)
  188. return m_pPageSite->TranslateAccelerator(pMsg);
  189. // Perform default processing
  190. return TCPropertyPageSite::OnTranslateAccelerator(pMsg);
  191. }
  192. /////////////////////////////////////////////////////////////////////////////
  193. // Return Value: Returns *FALSE*, since an embedded property page is a
  194. // modeless child control.
  195. BOOL TCInsidePropPage::OnIsModal()
  196. {
  197. return FALSE;
  198. }
  199. /////////////////////////////////////////////////////////////////////////////
  200. // Return Value: Returns the m_hWnd member variable of the base class,
  201. // CWindow.
  202. HWND TCInsidePropPage::OnGetWindow()
  203. {
  204. return m_hWnd;
  205. }
  206. /////////////////////////////////////////////////////////////////////////////
  207. // Group=Message Handlers
  208. /////////////////////////////////////////////////////////////////////////////
  209. // Description: Directs window messages to the TCPropertyPageSite base class.
  210. //
  211. // Thie message handler allows the TCPropertyPageSite base class the first
  212. // chance of handling all window messages.
  213. //
  214. // Parameters: See TCPropertyPageSite::OnPageSiteWndMsg
  215. //
  216. // Return Value: See TCPropertyPageSite::OnPageSiteWndMsg
  217. //
  218. // See Also: TCPropertyPageSite::OnPageSiteWndMsg
  219. LRESULT TCInsidePropPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam,
  220. BOOL& bHandled)
  221. {
  222. LRESULT lResult = 0;
  223. bHandled = OnPageSiteWndMsg(uMsg, wParam, lParam, &lResult);
  224. return lResult;
  225. }