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.

368 lines
11 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // Dialog class
  4. //
  5. // 10-15-97 sburns
  6. #ifndef DIALOG_HPP_INCLUDED
  7. #define DIALOG_HPP_INCLUDED
  8. // Wraps a Windows dialog box, cracks and demuxes the dialog messages, and
  9. // provides a mechanism for tracking the control IDs that have been touched
  10. // over a given period. Also provides what-is help.
  11. //
  12. // May only be used as a base class.
  13. class Dialog
  14. {
  15. public:
  16. // can't use an enum 'cause the type needs to be DWORD
  17. #define NO_HELP (static_cast<DWORD>(-1))
  18. // Executes the dialog modally via the Win DialogBox API. Blocks until the
  19. // Win EndDialog API is called; returns the value passed to EndDialog.
  20. // Derived classes must call EndDialog in their message processing to
  21. // terminate the execution of the dialog.
  22. //
  23. // parent - handle to the parent window, which will be disabled during
  24. // the execution of the dialog.
  25. INT_PTR
  26. ModalExecute(HWND parent);
  27. INT_PTR
  28. ModalExecute(const Dialog& parent);
  29. // Executes the dialog box modelessly, returning immediately. Derived
  30. // classes should call EndModelessExecution to close a Dialog executing
  31. // modelessly, or, destroy the Dialog instance.
  32. //
  33. // Example:
  34. //
  35. // MyFooDialog* dlg = new MyFooDialog(....);
  36. // dlg->ModlessExecute();
  37. //
  38. // // ... later
  39. //
  40. // dlg->EndModelessExecution();
  41. //
  42. // // or just:
  43. //
  44. // delete dlg;
  45. //
  46. // parent - handle to the parent window of this dialog, for establishing
  47. // z-order.
  48. void
  49. ModelessExecute(HWND parent);
  50. void
  51. ModelessExecute(const Dialog& parent);
  52. // Terminates the modeless execution of a dialog that has been started
  53. // with ModalExecute. It is illegal to call this method before calling
  54. // ModalExecute.
  55. void
  56. EndModelessExecution();
  57. // Returns the window handle of the dialog. This method is only valid
  58. // after the window has been created and initialized by receiving
  59. // WM_INITDIALOG (which will be the case before any virtual message
  60. // handling functions are invoked).
  61. HWND
  62. GetHWND() const;
  63. // Returns the resource ID with which this instance was created.
  64. unsigned
  65. GetResID() const;
  66. // Returns a pointer to the Dialog instance that has been previously
  67. // stashed in the DWL_USER portion of the window structure. This method is
  68. // only valid after the window has been created and initialized by
  69. // receiving WM_INITDIALOG (which will be the case before any virtual
  70. // message handling functions are invoked).
  71. //
  72. // dialog - handle to initialized dialog window.
  73. static
  74. Dialog*
  75. GetInstance(HWND dialog);
  76. protected:
  77. // Constructs a new instance. Declared protected so that this class
  78. // only functions as base class
  79. //
  80. // resID - resource identifier of the dialog template resource.
  81. //
  82. // helpMap - array mapping dialog control IDs to context help IDs. The
  83. // array must be in the following form:
  84. // {
  85. // controlID1, helpID1,
  86. // controlID2, helpID2,
  87. // controlIDn, helpIDn,
  88. // 0, 0
  89. // }
  90. //
  91. // To indicate that a control does not have help, the value of its
  92. // corresponding help ID should be NO_HELP. This array is copied
  93. // by the constructor.
  94. Dialog(
  95. unsigned resID,
  96. const DWORD helpMap[]);
  97. // Destroys an instance. If the ModelessExecute method has been called,
  98. // and the EndModlessExecution method has not yet been called,
  99. // EndModelessExecution is called.
  100. virtual ~Dialog();
  101. // Resets the control ID change map.
  102. void
  103. ClearChanges();
  104. // Marks a control ID as changed. Derived classes should call this from
  105. // their processing of OnCommand or OnNotify as appropriate to indicate
  106. // that a control has changed state. This is useful for keeping track of
  107. // the fields in a database that need to be changed, etc.
  108. //
  109. // controlResID - the resource ID of the control that changed.
  110. void
  111. SetChanged(UINT_PTR controlResID);
  112. // Queries the control ID change map, returning true if the specified
  113. // control ID was previously marked as changed (with SetChanged), false
  114. // if not.
  115. //
  116. // controlResID - the resource ID of the control that changed.
  117. bool
  118. WasChanged(UINT_PTR controlResID) const;
  119. // Returns true if SetChanged was called for any control on the dialog,
  120. // false if not.
  121. bool
  122. WasChanged() const;
  123. // (For debugging) dumps the state of the control ID change map using
  124. // OutputDebugString. For non-debug builds, a no-op.
  125. void
  126. DumpChangeMap() const;
  127. // Invoked upon receipt of WM_DESTROY. The default implementation does
  128. // nothing.
  129. virtual
  130. void
  131. OnDestroy();
  132. // Invoked upon receipt of WM_COMMAND. Derived class' implementation
  133. // should return true they handle the message, false if not. The default
  134. // implementation returns false.
  135. //
  136. // windowFrom - the HWND of the child window (control) that originated the
  137. // message.
  138. //
  139. // controlIDFrom - The resource ID of the child window corresponding to the
  140. // window indicated in the windowFrom parameter.
  141. //
  142. // code - the notification code.
  143. virtual
  144. bool
  145. OnCommand(
  146. HWND windowFrom,
  147. unsigned controlIdFrom,
  148. unsigned code);
  149. // Invoked upon receipt of WM_INITDIALOG, after having set things up such
  150. // that GetHWND and GetInstance will work correctly. The default
  151. // implementation does nothing.
  152. virtual
  153. void
  154. OnInit();
  155. // Invoked upon receipt of any window message that is not dispatched to
  156. // other member functions of this class, including user-defined messages.
  157. // Derived class' implementation should return true they handle the
  158. // message, false if not. The default implementation returns false.
  159. //
  160. // message - the message code passed to the dialog window.
  161. //
  162. // wparam - the WPARAM parameter accompanying the message.
  163. //
  164. // lparam - the LPARAM parameter accompanying the message.
  165. virtual
  166. bool
  167. OnMessage(
  168. UINT message,
  169. WPARAM wparam,
  170. LPARAM lparam);
  171. // Invoked upon receipt of WM_NOTIFY. Derived class' implementation should
  172. // return true they handle the message, false if not. The default
  173. // implementation returns false.
  174. //
  175. // windowFrom - the HWND of the child window (control) that originated the
  176. // message.
  177. //
  178. // controlIDFrom - The resource ID of the child window corresponding to the
  179. // window indicated in the windowFrom parameter.
  180. //
  181. // code - the notification code.
  182. //
  183. // lparam - the LPARAM parameter of the WM_NOTIFY message, which may,
  184. // depending on the window that originated the message, be a pointer to a
  185. // structure indicating other parameters to the notification.
  186. virtual
  187. bool
  188. OnNotify(
  189. HWND windowFrom,
  190. UINT_PTR controlIDFrom,
  191. UINT code,
  192. LPARAM lparam);
  193. // Invoked upon receipt of WM_CTLCOLORDLG. Derived class' implementation
  194. // should return a handle to a brush if they want to paint the dialog's
  195. // background. It is the responsibility of the derived class to destroy
  196. // the brush when it is no longer needed.
  197. // The default implementation returns NULL.
  198. //
  199. // deviceContext - the device context of the dialog box
  200. //
  201. // dialog - the HWND of the dialog box
  202. virtual
  203. HBRUSH
  204. OnCtlColorDlg(
  205. HDC deviceContext,
  206. HWND dialog);
  207. // Invoked upon receipt of WM_CTLCOLORSTATIC. Derived class' implementation
  208. // should return a handle to a brush if they want to paint the dialog's
  209. // background. It is the responsibility of the derived class to destroy the
  210. // brush when it is no longer needed.
  211. // The default implementation returns NULL.
  212. //
  213. // deviceContext - the device context of the dialog box
  214. //
  215. // dialog - the HWND of the dialog box
  216. virtual
  217. HBRUSH
  218. OnCtlColorStatic(
  219. HDC deviceContext,
  220. HWND dialog);
  221. // Invoked upon receipt of WM_CTLCOLOREDIT. Derived class' implementation
  222. // should return a handle to a brush if they want to paint the dialog's
  223. // background. It is the responsibility of the derived class to destroy the
  224. // brush when it is no longer needed.
  225. // The default implementation returns NULL.
  226. //
  227. // deviceContext - the device context of the dialog box
  228. //
  229. // dialog - the HWND of the dialog box
  230. virtual
  231. HBRUSH
  232. OnCtlColorEdit(
  233. HDC deviceContext,
  234. HWND dialog);
  235. // Invoked upon receipt of WM_CTLCOLORLISTBOX. Derived class' implementation
  236. // should return a handle to a brush if they want to paint the dialog's
  237. // background. It is the responsibility of the derived class to destroy the
  238. // brush when it is no longer needed.
  239. // The default implementation returns NULL.
  240. //
  241. // deviceContext - the device context of the dialog box
  242. //
  243. // dialog - the HWND of the dialog box
  244. virtual
  245. HBRUSH
  246. OnCtlColorListbox(
  247. HDC deviceContext,
  248. HWND dialog);
  249. // Invoked upon receipt of WM_CTLCOLORSCROLLBAR. Derived class' implementation
  250. // should return a handle to a brush if they want to paint the dialog's
  251. // background. It is the responsibility of the derived class to destroy the
  252. // brush when it is no longer needed.
  253. // The default implementation returns NULL.
  254. //
  255. // deviceContext - the device context of the dialog box
  256. //
  257. // dialog - the HWND of the dialog box
  258. virtual
  259. HBRUSH
  260. OnCtlColorScrollbar(
  261. HDC deviceContext,
  262. HWND dialog);
  263. // Stores the window handle of the dialog in this instance, so that it can
  264. // be later retrieved by GetHWND. This is typically called by derived
  265. // classes that are doing their own processing of WM_INITDIALOG. This
  266. // function may be legally called only once in the lifetime of any Dialog
  267. // instance.
  268. //
  269. // window - handle to the dialog window.
  270. void
  271. SetHWND(HWND window);
  272. // The window handle of corresponding to this instance. Only valid after
  273. // WM_INITDIALOG has been received.
  274. HWND hwnd;
  275. // accessible to PropertyPage, etc.
  276. static
  277. INT_PTR CALLBACK
  278. dialogProc(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam);
  279. private:
  280. // not implemented: no copying allowed
  281. Dialog(const Dialog&);
  282. const Dialog& operator=(const Dialog&);
  283. typedef
  284. std::map<
  285. UINT_PTR,
  286. bool,
  287. std::less<UINT_PTR>,
  288. Burnslib::Heap::Allocator<bool> >
  289. ChangeMap;
  290. // 'mutable' required for non-const map<>::operator[].
  291. mutable ChangeMap changemap;
  292. DWORD* helpMap;
  293. bool isEnded;
  294. bool isModeless;
  295. unsigned resID;
  296. };
  297. #endif // DIALOG_HPP_INCLUDED