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.

338 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. StaticOkDialog
  5. Abstract:
  6. This is an abstraction around a simple non-modal dialog
  7. box to make them easier to use.
  8. Author:
  9. Marc Reyhner 7/11/2000
  10. --*/
  11. #include "stdafx.h"
  12. #ifdef TRC_FILE
  13. #undef TRC_FILE
  14. #endif
  15. #define TRC_FILE "rcsokd"
  16. #include "rcontrol.h"
  17. #include "StaticOkDialog.h"
  18. CStaticOkDialog::CStaticOkDialog(
  19. )
  20. /*++
  21. Routine Description:
  22. This is the constructor for CStaticOkDialog. This just initializes
  23. the member variables. Create must be called to create the dialog.
  24. Arguments:
  25. None
  26. Return Value:
  27. None
  28. --*/
  29. {
  30. DC_BEGIN_FN("CStaticOkDialog::CStaticOkDialog");
  31. m_hWnd= NULL;
  32. DC_END_FN();
  33. }
  34. CStaticOkDialog::~CStaticOkDialog(
  35. )
  36. /*++
  37. Routine Description:
  38. This is the destructor for CStaticOkDialog. This will call DestroyWindow
  39. on the dialog if that has not been already done.
  40. Arguments:
  41. None
  42. Return Value:
  43. None
  44. --*/
  45. {
  46. DC_BEGIN_FN("CStaticOkDialog::~CStaticOkDialog");
  47. if (IsCreated()) {
  48. DestroyWindow(m_hWnd);
  49. }
  50. DC_END_FN();
  51. }
  52. BOOL
  53. CStaticOkDialog::Create(
  54. IN HINSTANCE hInstance,
  55. IN WORD resId,
  56. IN OUT HWND parentWnd
  57. )
  58. /*++
  59. Routine Description:
  60. This creates the dialog and displays it.
  61. Arguments:
  62. hInstance - The instance for this module.
  63. resId - The resource id of the dialog template.
  64. parentWnd - Handle to the parent window for the dialog
  65. Return Value:
  66. TRUE - The dialog was created.
  67. FALSE - There was an error creating the dialog.
  68. --*/
  69. {
  70. DC_BEGIN_FN("CStaticOkDialog::Create");
  71. if (IsCreated()) {
  72. DC_END_FN();
  73. return FALSE;
  74. }
  75. m_hWnd = CreateDialog(hInstance,MAKEINTRESOURCE(resId),parentWnd,_DlgProc);
  76. if (m_hWnd) {
  77. SetWindowLongPtr(m_hWnd,GWLP_USERDATA,(LONG)this);
  78. ShowWindow(m_hWnd,SW_SHOW);
  79. SetFocus(m_hWnd);
  80. DC_END_FN();
  81. return TRUE;
  82. } else {
  83. DC_END_FN();
  84. return FALSE;
  85. }
  86. }
  87. INT_PTR CALLBACK
  88. CStaticOkDialog::_DlgProc(
  89. IN OUT HWND hwndDlg,
  90. IN UINT uMsg,
  91. IN WPARAM wParam,
  92. IN LPARAM lParam
  93. )
  94. /*++
  95. Routine Description:
  96. This is the DialogProc for the dialog. If the user hit
  97. the "ok" button we close the dialog. Otherwise we ignore the
  98. message.
  99. Arguments:
  100. hwndDlg - Handle to the dialog.
  101. uMsg - Message that occurred.
  102. wParam - WPARAM for the message.
  103. lParam - LPARAM for the message.
  104. Return Value:
  105. TRUE - We handled the message
  106. FALSE - We didn't handle the message
  107. --*/
  108. {
  109. BOOL retValue = TRUE;
  110. CStaticOkDialog *theClass;
  111. DC_BEGIN_FN("CStaticOkDialog::_DlgProc");
  112. theClass = (CStaticOkDialog*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  113. switch (uMsg) {
  114. case WM_COMMAND:
  115. switch (wParam) {
  116. case IDOK:
  117. if (theClass) {
  118. theClass->OnOk();
  119. }
  120. DestroyWindow(hwndDlg);
  121. break;
  122. }
  123. default:
  124. retValue = FALSE;
  125. }
  126. DC_END_FN();
  127. return retValue;
  128. }
  129. BOOL
  130. CStaticOkDialog::IsCreated(
  131. )
  132. /*++
  133. Routine Description:
  134. This returns whether or not the dialog is a current valid window.
  135. Arguments:
  136. None
  137. Return Value:
  138. TRUE - The dialog has been created.
  139. FALSE - The dialog has not been created or was destroyed.
  140. --*/
  141. {
  142. BOOL result;
  143. DC_BEGIN_FN("CStaticOkDialog::IsCreated");
  144. result = IsWindow(m_hWnd);
  145. DC_END_FN();
  146. return result;
  147. }
  148. VOID
  149. CStaticOkDialog::DestroyDialog(
  150. )
  151. /*++
  152. Routine Description:
  153. This destroys the dialog. You can create it again after this
  154. if you want.
  155. Arguments:
  156. None
  157. Return Value:
  158. None
  159. --*/
  160. {
  161. DC_BEGIN_FN("CStaticOkDialog::DestroyDialog");
  162. DestroyWindow(m_hWnd);
  163. m_hWnd = NULL;
  164. DC_END_FN();
  165. }
  166. BOOL
  167. CStaticOkDialog::DialogMessage(
  168. IN LPMSG lpMsg
  169. )
  170. /*++
  171. Routine Description:
  172. This needs to be called by the event loop while this dialog is created
  173. to send it windows messages.
  174. Arguments:
  175. lpMsg - The message which was sent.
  176. Return Value:
  177. TRUE - The message was for this dialog.
  178. FALSE - The message was not for this dialog.
  179. --*/
  180. {
  181. BOOL result;
  182. DC_BEGIN_FN("CStaticOkDialog::DialogMessage");
  183. if (IsCreated()) {
  184. result = IsDialogMessage(m_hWnd,lpMsg);
  185. } else {
  186. result = FALSE;
  187. }
  188. DC_END_FN();
  189. return result;
  190. }
  191. VOID
  192. CStaticOkDialog::Activate(
  193. )
  194. /*++
  195. Routine Description:
  196. This brings the dialog to the foreground.
  197. Arguments:
  198. None
  199. Return Value:
  200. None
  201. --*/
  202. {
  203. DC_BEGIN_FN("CStaticOkDialog::Activate");
  204. if (IsCreated()) {
  205. SetForegroundWindow(m_hWnd);
  206. SetFocus(m_hWnd);
  207. }
  208. DC_END_FN();
  209. }
  210. VOID
  211. CStaticOkDialog::OnOk(
  212. )
  213. {
  214. // this is a temporary function to be removed when
  215. // salem gets remote control notifications correct.
  216. }