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.

268 lines
6.1 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) const
  60. {
  61. INT_PTR iResult = 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_DRAWITEM:
  154. fReturn = pThis->_OnDrawItem(wParam, lParam);
  155. break;
  156. case WM_CTLCOLORSTATIC:
  157. fReturn = static_cast<ULONG>(pThis->_OnStaticCtlColor((HDC) wParam, (HWND) lParam));
  158. break;
  159. case WM_SYSCOLORCHANGE:
  160. pThis->_OnSysColorChange();
  161. break;
  162. /*
  163. case WM_SETFOCUS:
  164. pThis->_OnSetFocus((HWND)wParam);
  165. break;
  166. */
  167. case WM_DESTROY:
  168. //
  169. // It's possible to get a WM_DESTROY message without having gotten
  170. // a WM_INITDIALOG if loading a dll that the dialog needs (e.g.
  171. // comctl32.dll) fails, so guard pThis access here.
  172. //
  173. if (pThis)
  174. {
  175. pThis->_OnDestroy();
  176. pThis->m_hwnd = NULL;
  177. }
  178. break;
  179. case WM_HELP:
  180. case WM_CONTEXTMENU:
  181. pThis->_OnHelp(message, wParam, lParam);
  182. break;
  183. default:
  184. fReturn = FALSE;
  185. break;
  186. }
  187. return fReturn;
  188. }
  189. #define VERIFY(x) x
  190. //+--------------------------------------------------------------------------
  191. //
  192. // Member: CDlg::_GetChildWindowRect
  193. //
  194. // Synopsis: Init *[prc] with the window rect, in client coordinates, of
  195. // child window [hwndChild].
  196. //
  197. // Arguments: [hwndChild] - child window for which to retrieve rect
  198. // [prc] - pointer to rect struct to receive info
  199. //
  200. // Modifies: *[prc]
  201. //
  202. // History: 07-21-1998 DavidMun Created
  203. //
  204. //---------------------------------------------------------------------------
  205. void
  206. CDlg::_GetChildWindowRect(
  207. HWND hwndChild,
  208. RECT *prc)
  209. {
  210. VERIFY(GetWindowRect(hwndChild, prc));
  211. VERIFY(MapWindowPoints(NULL, m_hwnd, (LPPOINT) prc, 2));
  212. }