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.

247 lines
5.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: dlg.cxx
  7. //
  8. // Contents: Implementation of modeless dialog base class
  9. //
  10. // Classes: CDlg
  11. //
  12. // History: 4-22-1997 DavidMun Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "headers.hxx"
  16. #pragma hdrstop
  17. //+--------------------------------------------------------------------------
  18. //
  19. // Member: CDlg::CDlg
  20. //
  21. // Synopsis: ctor
  22. //
  23. // History: 4-22-1997 DavidMun Created
  24. //
  25. //---------------------------------------------------------------------------
  26. CDlg::CDlg():
  27. m_hwnd(NULL)
  28. {
  29. }
  30. //+--------------------------------------------------------------------------
  31. //
  32. // Member: CDlg::~CDlg
  33. //
  34. // Synopsis: dtor
  35. //
  36. // History: 4-22-1997 DavidMun Created
  37. //
  38. //---------------------------------------------------------------------------
  39. CDlg::~CDlg()
  40. {
  41. }
  42. //+--------------------------------------------------------------------------
  43. //
  44. // Member: CDlg::_DoModalDlg
  45. //
  46. // Synopsis: Create the dialog and return its window handle
  47. //
  48. // Arguments: [hwndParent] - handle to owner window of dialog to create
  49. // [idd] - resource id of dialog template
  50. //
  51. // Returns: Dialog's return code
  52. //
  53. // History: 04-22-1997 DavidMun Created
  54. //
  55. //---------------------------------------------------------------------------
  56. INT_PTR
  57. CDlg::_DoModalDlg(
  58. HWND hwndParent,
  59. INT idd)
  60. {
  61. INT iResult = (INT)DialogBoxParam(GetModuleHandle(NULL),
  62. MAKEINTRESOURCE(idd),
  63. hwndParent,
  64. CDlg::_DlgProc,
  65. (LPARAM) this);
  66. return iResult;
  67. }
  68. //+--------------------------------------------------------------------------
  69. //
  70. // Member: CDlg::_DoModelessDlg
  71. //
  72. // Synopsis: Create the dialog and return its window handle
  73. //
  74. // Arguments: [hwndParent] - handle to owner window of dialog to create
  75. // [idd] - resource id of dialog template
  76. //
  77. // Returns: Dialog window handle, or NULL on failure
  78. //
  79. // History: 4-22-1997 DavidMun Created
  80. //
  81. //---------------------------------------------------------------------------
  82. HWND
  83. CDlg::_DoModelessDlg(
  84. HWND hwndParent,
  85. INT idd)
  86. {
  87. HWND hwnd;
  88. hwnd = CreateDialogParam(GetModuleHandle(NULL),
  89. MAKEINTRESOURCE(idd),
  90. hwndParent,
  91. CDlg::_DlgProc,
  92. (LPARAM) this);
  93. return hwnd;
  94. }
  95. //+--------------------------------------------------------------------------
  96. //
  97. // Member: CDlg::_DlgProc
  98. //
  99. // Synopsis: Dispatch selected messages to derived class
  100. //
  101. // Arguments: standard windows dialog
  102. //
  103. // Returns: standard windows dialog
  104. //
  105. // History: 4-22-1997 DavidMun Created
  106. //
  107. //---------------------------------------------------------------------------
  108. INT_PTR CALLBACK
  109. CDlg::_DlgProc(
  110. HWND hwnd,
  111. UINT message,
  112. WPARAM wParam,
  113. LPARAM lParam)
  114. {
  115. BOOL fReturn = TRUE;
  116. CDlg *pThis = (CDlg *)GetWindowLongPtr(hwnd, DWLP_USER);
  117. switch (message)
  118. {
  119. case WM_INITDIALOG:
  120. {
  121. HRESULT hr = S_OK;
  122. //
  123. // pThis isn't valid because we haven't set DWLP_USER yet. Make
  124. // it valid.
  125. //
  126. pThis = (CDlg*) lParam;
  127. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) pThis);
  128. pThis->m_hwnd = hwnd;
  129. bool fInitResult = true;
  130. hr = pThis->_OnInit(&fInitResult);
  131. fReturn = fInitResult;
  132. //
  133. // If the initialization failed do not allow the dialog to start.
  134. //
  135. if (FAILED(hr))
  136. {
  137. DestroyWindow(hwnd);
  138. }
  139. break;
  140. }
  141. case WM_COMMAND:
  142. fReturn = pThis->_OnCommand(wParam, lParam);
  143. break;
  144. case WM_SIZE:
  145. fReturn = pThis->_OnSize(wParam, lParam);
  146. break;
  147. case WM_GETMINMAXINFO:
  148. fReturn = pThis->_OnMinMaxInfo((LPMINMAXINFO) lParam);
  149. break;
  150. case WM_NOTIFY:
  151. fReturn = pThis->_OnNotify(wParam, lParam);
  152. break;
  153. case WM_DESTROY:
  154. //
  155. // It's possible to get a WM_DESTROY message without having gotten
  156. // a WM_INITDIALOG if loading a dll that the dialog needs (e.g.
  157. // comctl32.dll) fails, so guard pThis access here.
  158. //
  159. if (pThis)
  160. {
  161. pThis->_OnDestroy();
  162. pThis->m_hwnd = NULL;
  163. }
  164. break;
  165. case WM_HELP:
  166. case WM_CONTEXTMENU:
  167. pThis->_OnHelp(message, wParam, lParam);
  168. break;
  169. default:
  170. fReturn = FALSE;
  171. break;
  172. }
  173. return fReturn;
  174. }
  175. //+--------------------------------------------------------------------------
  176. //
  177. // Member: CDlg::_GetChildWindowRect
  178. //
  179. // Synopsis: Init *[prc] with the window rect, in client coordinates, of
  180. // child window [hwndChild].
  181. //
  182. // Arguments: [hwndChild] - child window for which to retrieve rect
  183. // [prc] - pointer to rect struct to receive info
  184. //
  185. // Modifies: *[prc]
  186. //
  187. // History: 07-21-1998 DavidMun Created
  188. //
  189. //---------------------------------------------------------------------------
  190. void
  191. CDlg::_GetChildWindowRect(
  192. HWND hwndChild,
  193. RECT *prc)
  194. {
  195. GetWindowRect(hwndChild, prc);
  196. ScreenToClient(m_hwnd, (LPPOINT) &prc->left);
  197. ScreenToClient(m_hwnd, (LPPOINT) &prc->right);
  198. }