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.

236 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. cdlg.cpp
  5. Abstract:
  6. Imitation of MFC CDialog class
  7. Author:
  8. Vlad Sadovsky (vlads) 26-Mar-1997
  9. Revision History:
  10. 26-Mar-1997 VladS created
  11. --*/
  12. #include "cplusinc.h"
  13. #include "sticomm.h"
  14. #include "cdlg.h"
  15. #include "windowsx.h"
  16. VOID CALLBACK
  17. TimerDlgProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
  18. //
  19. // Constructor/destructor
  20. //
  21. CDlg::CDlg(int DlgID, HWND hWnd, HINSTANCE hInst,UINT msElapseTimePeriod)
  22. : m_DlgID(DlgID),
  23. m_hParent(hWnd),
  24. m_Inst(hInst),
  25. m_bCreatedModeless(FALSE),
  26. m_msElapseTimePeriod(msElapseTimePeriod),
  27. m_hDlg(0),
  28. m_uiTimerId(0)
  29. {
  30. }
  31. CDlg::~CDlg()
  32. {
  33. if (m_uiTimerId) {
  34. ::KillTimer(GetWindow(),m_uiTimerId);
  35. m_uiTimerId = 0;
  36. }
  37. if(m_hDlg) {
  38. DestroyWindow(m_hDlg);
  39. }
  40. }
  41. INT_PTR
  42. CALLBACK
  43. CDlg::BaseDlgProc(
  44. HWND hDlg,
  45. UINT uMessage,
  46. WPARAM wParam,
  47. LPARAM lParam
  48. )
  49. {
  50. CDlg * pSV = (CDlg*) GetWindowLongPtr(hDlg,DWLP_USER);
  51. switch (uMessage) {
  52. case WM_INITDIALOG:
  53. {
  54. ASSERT(lParam);
  55. pSV=(CDlg*)lParam;
  56. pSV->SetWindow(hDlg);
  57. SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)pSV);
  58. //
  59. // Create timer for canceling dialog if user did not respond in time
  60. //
  61. if(pSV->m_msElapseTimePeriod) {
  62. pSV->m_uiTimerId = ::SetTimer(pSV->GetWindow(),ID_TIMER_EVENT,pSV->m_msElapseTimePeriod,NULL);
  63. //(TIMERPROC)TimerDlgProc);
  64. }
  65. pSV->OnInit();
  66. }
  67. break;
  68. case WM_COMMAND:
  69. if(pSV) {
  70. return pSV->OnCommand(LOWORD(wParam),(HWND)lParam,HIWORD(wParam));
  71. }
  72. break;
  73. case WM_NOTIFY:
  74. if(pSV) {
  75. return pSV->OnNotify((NMHDR FAR *)lParam);
  76. }
  77. break;
  78. case WM_DESTROY:
  79. if(pSV) {
  80. pSV->Destroy();
  81. }
  82. break;
  83. case WM_TIMER:
  84. if(pSV && pSV->m_uiTimerId && (ID_TIMER_EVENT == wParam)) {
  85. // Imitate cancel
  86. ::PostMessage(hDlg,
  87. WM_COMMAND,
  88. #ifdef _WIN64
  89. (WPARAM)MAKELONG(IDCANCEL,0), (LPARAM)(pSV->GetDlgItem(IDCANCEL))
  90. #else
  91. GET_WM_COMMAND_MPS(IDCANCEL, pSV->GetDlgItem(IDCANCEL), 0)
  92. #endif
  93. );
  94. }
  95. break;
  96. }
  97. if(pSV) {
  98. return pSV->DlgProc(hDlg,uMessage,wParam,lParam);
  99. }
  100. return FALSE;
  101. }
  102. //
  103. // Overridable dialog procedure and message handlers
  104. //
  105. BOOL
  106. CALLBACK
  107. CDlg::DlgProc(
  108. HWND hDlg,
  109. UINT uMessage,
  110. WPARAM wParam,
  111. LPARAM lParam
  112. )
  113. {
  114. return FALSE;
  115. }
  116. int
  117. CDlg::OnCommand(
  118. UINT id,
  119. HWND hwndCtl,
  120. UINT codeNotify
  121. )
  122. {
  123. switch( id) {
  124. case IDOK:
  125. case IDCANCEL:
  126. EndDialog(id);
  127. break;
  128. }
  129. return 1; // not handled
  130. }
  131. void CDlg::OnInit()
  132. {
  133. }
  134. int CDlg::OnNotify(NMHDR * pHdr)
  135. {
  136. return FALSE;
  137. }
  138. //
  139. // Creation functions
  140. //
  141. INT_PTR CDlg::CreateModal()
  142. {
  143. m_bCreatedModeless=FALSE;
  144. return DialogBoxParam( m_Inst, MAKEINTRESOURCE(m_DlgID), m_hParent, BaseDlgProc, (LPARAM)this);
  145. }
  146. HWND CDlg::CreateModeless()
  147. {
  148. if(m_hDlg) {
  149. return m_hDlg;
  150. }
  151. HWND hWnd=CreateDialogParam(m_Inst, MAKEINTRESOURCE(m_DlgID), m_hParent, BaseDlgProc, (LPARAM)this);
  152. if(hWnd) {
  153. m_bCreatedModeless=TRUE;
  154. }
  155. return hWnd;
  156. }
  157. void CDlg::Destroy()
  158. {
  159. if(m_bCreatedModeless) {
  160. if(m_hDlg) {
  161. m_hDlg=NULL;
  162. }
  163. }
  164. }
  165. void CDlg::SetDlgID(UINT id)
  166. {
  167. m_DlgID=id;
  168. }
  169. void CDlg::SetInstance(HINSTANCE hInst)
  170. {
  171. m_Inst=hInst;
  172. }
  173. VOID CALLBACK
  174. TimerDlgProc(
  175. HWND hDlg, // handle of window for timer messages
  176. UINT uMsg, // WM_TIMER message
  177. UINT idEvent, // timer identifier
  178. DWORD dwTime // current system time
  179. )
  180. {
  181. CDlg * pSV = (CDlg*) GetWindowLongPtr(hDlg,DWLP_USER);
  182. if((uMsg == WM_TIMER) &&
  183. (pSV &&(pSV->GetTimerId() == (UINT_PTR)idEvent))
  184. ) {
  185. // Imitate cancel
  186. PostMessage(hDlg,
  187. WM_COMMAND,
  188. // GET_WM_COMMAND_MPS(IDCANCEL, pSV->GetDlgItem(IDCANCEL), 0)
  189. (WPARAM)MAKELONG(IDCANCEL,0), (LPARAM)(pSV->GetDlgItem(IDCANCEL))
  190. );
  191. }
  192. }