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.

398 lines
9.8 KiB

  1. /*+
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. DLG.CPP
  5. Abstract:
  6. C_Dlg implementation
  7. Author:
  8. 990518 dane Created.
  9. 990721 dane Added _THIS_MODULE_ for logging macros.
  10. georgema 000310 updated
  11. Environment:
  12. Win98, Win2000
  13. Revision History:
  14. --*/
  15. #pragma comment(user, "Compiled on " __DATE__ " at " __TIME__)
  16. #pragma comment(compiler)
  17. //////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Include files
  20. //
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. #include <windows.h>
  25. #include <commctrl.h>
  26. #include <tchar.h>
  27. #include "macros.h"
  28. #include <shfusion.h>
  29. #include "Dlg.h"
  30. //////////////////////////////////////////////////////////////////////////////
  31. //
  32. // Static initialization
  33. //
  34. static const char _THIS_FILE_[ ] = __FILE__;
  35. //////////////////////////////////////////////////////////////////////////////
  36. //
  37. // Static member initialization
  38. //
  39. LPCTSTR C_Dlg::SZ_HWND_PROP = _T("hwnd");
  40. //////////////////////////////////////////////////////////////////////////////
  41. //
  42. // C_Dlg
  43. //
  44. // Constructor.
  45. //
  46. // parameters:
  47. // hwndParent parent window for the dialog (may be NULL)
  48. // hInstance instance handle of the parent window (may be NULL)
  49. // lIDD dialog template id
  50. // pfnDlgProc pointer to the function that will process messages for
  51. // the dialog. if it is NULL, the default dialog proc
  52. // will be used.
  53. //
  54. // returns:
  55. // Nothing.
  56. //
  57. //////////////////////////////////////////////////////////////////////////////
  58. C_Dlg::C_Dlg(
  59. HWND hwndParent,
  60. HINSTANCE hInstance,
  61. LONG lIDD,
  62. DLGPROC pfnDlgProc // = NULL
  63. )
  64. : m_hwndParent(hwndParent),
  65. m_hInstance(hInstance),
  66. m_lIDD(lIDD),
  67. m_pfnDlgProc(pfnDlgProc),
  68. m_hwnd(NULL)
  69. {
  70. ASSERT(NULL != SZ_HWND_PROP);
  71. if (NULL == m_pfnDlgProc)
  72. {
  73. // Use the default dialog proc
  74. //
  75. m_pfnDlgProc = C_Dlg::DlgProc;
  76. }
  77. } // C_Dlg::C_Dlg
  78. //////////////////////////////////////////////////////////////////////////////
  79. //
  80. // ~C_Dlg
  81. //
  82. // Destructor.
  83. //
  84. // parameters:
  85. // None.
  86. //
  87. // returns:
  88. // Nothing.
  89. //
  90. //////////////////////////////////////////////////////////////////////////////
  91. C_Dlg::~C_Dlg( )
  92. {
  93. OnShutdown();
  94. } // C_Dlg::~C_Dlg
  95. //////////////////////////////////////////////////////////////////////////////
  96. //
  97. // DoModal
  98. //
  99. // Display the dialog box modally and wait for it to be closed.
  100. //
  101. // parameters:
  102. // lparam user-defined data that will be passed to the dialog
  103. // proc as the lparam of the WM_INITDIALOG message.
  104. //
  105. // returns:
  106. // User-defined result code returned by EndDialog( ).
  107. //
  108. //////////////////////////////////////////////////////////////////////////////
  109. INT_PTR
  110. C_Dlg::DoModal(
  111. LPARAM lparam // = NULL
  112. )
  113. {
  114. INT_PTR nResult = DialogBoxParam(m_hInstance,
  115. MAKEINTRESOURCE(m_lIDD),
  116. m_hwndParent,
  117. m_pfnDlgProc,
  118. lparam
  119. );
  120. // nResult will be 0 or -1 on failure, else will be value assigned from EndDialog()
  121. return nResult;
  122. } // C_Dlg::DoModal
  123. //////////////////////////////////////////////////////////////////////////////
  124. //
  125. // DlgProc
  126. //
  127. // Window procedure for wizard pages. All messages are routed here, then
  128. // dispatched to the appropriate C_Dlg object.
  129. //
  130. // parameters:
  131. // hwndDlg window handle of the page for which the message is
  132. // intended
  133. // uMessage the message
  134. // wparam message-specific data
  135. // lparam message-specific data
  136. //
  137. // returns:
  138. // TRUE if the message was processed
  139. // FALSE otherwise
  140. //
  141. //////////////////////////////////////////////////////////////////////////////
  142. INT_PTR CALLBACK
  143. C_Dlg::DlgProc(
  144. HWND hwndDlg,
  145. UINT uMessage,
  146. WPARAM wparam,
  147. LPARAM lparam
  148. )
  149. {
  150. CHECK_MESSAGE(hwndDlg, uMessage, wparam, lparam);
  151. // Get the pointer to the C_Dlg object corresponding to the hwndDlg
  152. //
  153. C_Dlg* pDlg = NULL;
  154. if (WM_INITDIALOG == uMessage)
  155. {
  156. // For WM_INITDIALOG, the pointer to the dialog object will be in
  157. // the lparam.
  158. //
  159. pDlg = (C_Dlg*) lparam;
  160. }
  161. else
  162. {
  163. // For all other messages, it will be attached to the HWND
  164. //
  165. HRESULT hr = C_Dlg::DlgFromHwnd(hwndDlg, &pDlg);
  166. if (FAILED(hr))
  167. {
  168. return FALSE;
  169. }
  170. ASSERT(NULL != pDlg);
  171. }
  172. // Let the page route application-specific messages
  173. //
  174. if (WM_APP <= uMessage)
  175. {
  176. return pDlg->OnAppMessage(uMessage, wparam, lparam);
  177. }
  178. // Route Windows messages to appropriate handler
  179. //
  180. switch (uMessage)
  181. {
  182. case WM_INITDIALOG:
  183. return pDlg->OnInitDialog(hwndDlg,
  184. (HWND)wparam
  185. );
  186. case WM_HELP:
  187. return pDlg->OnHelpInfo(lparam);
  188. case WM_CONTEXTMENU:
  189. return pDlg->OnContextMenu(wparam,lparam);
  190. case WM_COMMAND:
  191. return pDlg->OnCommand(HIWORD(wparam), LOWORD(wparam), (HWND)lparam);
  192. case WM_NOTIFY:
  193. return RouteNotificationMessage(pDlg, (NMHDR*)lparam);
  194. break;
  195. case WM_DESTROY:
  196. return pDlg->OnDestroyDialog();
  197. break;
  198. default:
  199. // Message was not processed
  200. //
  201. return FALSE;
  202. } // switch (uMessage)
  203. } // C_Dlg::DlgProc
  204. //////////////////////////////////////////////////////////////////////////////
  205. //
  206. // RouteNotificationMessage
  207. //
  208. // Routes notification messages from wizard buttons to the appropriate page
  209. // and handler.
  210. //
  211. // parameters:
  212. // hwndDlg window handle of page to which message is to be sent
  213. // pnmhdr pointer to the NMHDR structure containing info about
  214. // the particular notification
  215. //
  216. // returns:
  217. // TRUE if the message is processed
  218. // FALSE otherwise
  219. //
  220. //////////////////////////////////////////////////////////////////////////////
  221. BOOL
  222. C_Dlg::RouteNotificationMessage(
  223. C_Dlg* pDlg,
  224. NMHDR* pnmhdr
  225. )
  226. {
  227. if (NULL == pDlg)
  228. {
  229. //FIX220699
  230. return FALSE;
  231. //return E_INVALIDARG;
  232. }
  233. // If any specific notifications are to be handled, switch on pnmhdr->code.
  234. //
  235. return pDlg->OnNotify(pnmhdr);
  236. } // C_Dlg::RouteNotificationMessage
  237. //////////////////////////////////////////////////////////////////////////////
  238. //
  239. // LinkHwnd
  240. //
  241. // Store the pointer to this object in a window handle property. This
  242. // provides a way to get to the object when all that is known is the HWND.
  243. // Particularly useful in window procedures.
  244. //
  245. // parameters:
  246. // None.
  247. //
  248. // returns:
  249. // TRUE if the operation is successful
  250. // FALSE otherwise
  251. //
  252. //////////////////////////////////////////////////////////////////////////////
  253. BOOL
  254. C_Dlg::LinkHwnd( )
  255. {
  256. ASSERT(IsWindow(m_hwnd));
  257. if (! IsWindow(m_hwnd))
  258. {
  259. return FALSE;
  260. }
  261. return SetProp(m_hwnd, SZ_HWND_PROP, (HANDLE)this);
  262. } // C_Dlg::LinkHwnd
  263. //////////////////////////////////////////////////////////////////////////////
  264. //
  265. // UnlinkHwnd
  266. //
  267. // Remove the pointer to the associated object from a window handle. The
  268. // pointer must have been set with LinkHwnd( ).
  269. //
  270. // parameters:
  271. // None.
  272. //
  273. // returns:
  274. // TRUE if the window handle is removed and it is a pointer to
  275. // this object
  276. // FALSE otherwise
  277. //
  278. //////////////////////////////////////////////////////////////////////////////
  279. BOOL
  280. C_Dlg::UnlinkHwnd( )
  281. {
  282. ASSERT(IsWindow(m_hwnd));
  283. if (! IsWindow(m_hwnd))
  284. {
  285. return FALSE;
  286. }
  287. C_Dlg* pDlg = (C_Dlg*)RemoveProp(m_hwnd, SZ_HWND_PROP);
  288. ASSERT(this == pDlg);
  289. return (this == pDlg);
  290. } // C_Dlg::UnlinkHwnd
  291. //////////////////////////////////////////////////////////////////////////////
  292. //
  293. // DlgFromHwnd
  294. //
  295. // Retrieves the pointer to the associated object from a window handle. The
  296. // pointer was stored in a property by LinkHwnd( ).
  297. //
  298. // parameters:
  299. // hwnd the window handle containing the pointer
  300. // ppDlg pointer to a buffer that will receive the pointer to
  301. // the C_Dlg object
  302. //
  303. // returns:
  304. // S_OK if the operation is successful
  305. // E_INVALIDARG if hwnd is not a valid window or ppDlg is NULL
  306. // E_POINTER if the retrieved pointer is NULL
  307. //
  308. //////////////////////////////////////////////////////////////////////////////
  309. HRESULT
  310. C_Dlg::DlgFromHwnd(
  311. HWND hwnd,
  312. C_Dlg** ppDlg
  313. )
  314. {
  315. if (! ::IsWindow(hwnd))
  316. {
  317. return (E_INVALIDARG);
  318. }
  319. ASSERT(NULL != ppDlg);
  320. if (NULL == ppDlg)
  321. {
  322. return (E_INVALIDARG);
  323. }
  324. *ppDlg = (C_Dlg*) GetProp(hwnd, SZ_HWND_PROP);
  325. if (NULL == *ppDlg)
  326. {
  327. return (E_POINTER);
  328. }
  329. return (S_OK);
  330. } // C_Dlg::DlgFromHwnd
  331. //
  332. ///// End of file: Dlg.cpp ////////////////////////////////////////////////