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.

339 lines
7.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: ispudlg.cpp
  8. //
  9. // Contents: Microsoft Internet Security Office Helper
  10. //
  11. // History: 14-Aug-1997 pberkman created
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "global.hxx"
  15. #include "ispudlg.hxx"
  16. INT_PTR CALLBACK UIMessageProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. INT_PTR CALLBACK ProcessingDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18. ISPUdlg_::ISPUdlg_(HWND hWndParent, HINSTANCE hInst, DWORD dwDialogId)
  19. {
  20. m_dwDialogId = dwDialogId;
  21. m_hInst = hInst;
  22. m_hWndParent = hWndParent;
  23. m_hWndMe = NULL;
  24. m_hrResult = E_NOTIMPL;
  25. m_hDlgProcessing = NULL;
  26. }
  27. ISPUdlg_::~ISPUdlg_(void)
  28. {
  29. if (m_hDlgProcessing)
  30. {
  31. DestroyWindow(m_hDlgProcessing);
  32. }
  33. }
  34. HRESULT ISPUdlg_::Invoke(void)
  35. {
  36. if (DialogBoxParam(m_hInst, MAKEINTRESOURCE(m_dwDialogId), m_hWndParent,
  37. UIMessageProc, (LPARAM)this) == (-1))
  38. {
  39. return(HRESULT_FROM_WIN32(GetLastError()));
  40. }
  41. return(m_hrResult);
  42. }
  43. void ISPUdlg_::ShowError(HWND hWnd, DWORD dwStringId, DWORD dwTitleId)
  44. {
  45. char szTitle[MAX_PATH + 1];
  46. char szErr[MAX_PATH + 1];
  47. LoadStringA(m_hInst, dwTitleId, &szTitle[0], MAX_PATH);
  48. LoadStringA(m_hInst, dwStringId, &szErr[0], MAX_PATH);
  49. MessageBeep(MB_ICONEXCLAMATION);
  50. MessageBox((hWnd) ? hWnd : m_hWndParent, &szErr[0], &szTitle[0],
  51. MB_OK | MB_ICONERROR);
  52. }
  53. void ISPUdlg_::StartShowProcessing(DWORD dwDialogId, DWORD dwTextControlId, DWORD dwStringId)
  54. {
  55. char szText[MAX_PATH + 1];
  56. if (m_hDlgProcessing)
  57. {
  58. DestroyWindow(m_hDlgProcessing);
  59. }
  60. szText[0] = NULL;
  61. LoadStringA(m_hInst, dwStringId, &szText[0], MAX_PATH);
  62. m_hDlgProcessing = CreateDialog(m_hInst, MAKEINTRESOURCE(dwDialogId), m_hWndParent,
  63. ProcessingDialogProc);
  64. this->Center(m_hDlgProcessing);
  65. ShowWindow(m_hDlgProcessing, SW_SHOW);
  66. SetDlgItemText(m_hDlgProcessing, dwTextControlId, &szText[0]);
  67. }
  68. void ISPUdlg_::ChangeShowProcessing(DWORD dwTextControlId, DWORD dwStirngId)
  69. {
  70. if (!(m_hDlgProcessing))
  71. {
  72. return;
  73. }
  74. char szText[MAX_PATH + 1];
  75. szText[0] = NULL;
  76. LoadStringA(m_hInst, dwStirngId, &szText[0], MAX_PATH);
  77. SetDlgItemText(m_hDlgProcessing, dwTextControlId, &szText[0]);
  78. }
  79. void ISPUdlg_::EndShowProcessing(void)
  80. {
  81. if (m_hDlgProcessing)
  82. {
  83. DestroyWindow(m_hDlgProcessing);
  84. m_hDlgProcessing = NULL;
  85. }
  86. }
  87. BOOL ISPUdlg_::OnMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  88. {
  89. switch (uMsg)
  90. {
  91. case WM_INITDIALOG:
  92. m_hWndMe = hWnd;
  93. this->Center();
  94. return(this->OnInitDialog(hWnd, wParam, lParam));
  95. case WM_COMMAND:
  96. return(this->OnCommand(hWnd, uMsg, wParam, lParam));
  97. case WM_CLOSE:
  98. return(this->OnCancel(hWnd));
  99. case WM_HELP:
  100. return(this->OnHelp(hWnd, wParam, lParam));
  101. default:
  102. return(FALSE);
  103. }
  104. return(TRUE);
  105. }
  106. BOOL ISPUdlg_::OnOK(HWND hWnd)
  107. {
  108. EndDialog(hWnd, (int)m_hrResult);
  109. return(TRUE);
  110. }
  111. BOOL ISPUdlg_::OnCancel(HWND hWnd)
  112. {
  113. EndDialog(hWnd, (int)m_hrResult);
  114. return(TRUE);
  115. }
  116. void ISPUdlg_::Center(HWND hWnd2Center)
  117. {
  118. RECT rcDlg;
  119. RECT rcArea;
  120. RECT rcCenter;
  121. HWND hWndParent;
  122. HWND hWndCenter;
  123. DWORD dwStyle;
  124. int w_Dlg;
  125. int h_Dlg;
  126. int xLeft;
  127. int yTop;
  128. if (!(hWnd2Center))
  129. {
  130. hWnd2Center = m_hWndMe;
  131. }
  132. GetWindowRect(hWnd2Center, &rcDlg);
  133. dwStyle = (DWORD)GetWindowLong(hWnd2Center, GWL_STYLE);
  134. if (dwStyle & WS_CHILD)
  135. {
  136. hWndCenter = GetParent(hWnd2Center);
  137. hWndParent = GetParent(hWnd2Center);
  138. GetClientRect(hWndParent, &rcArea);
  139. GetClientRect(hWndCenter, &rcCenter);
  140. MapWindowPoints(hWndCenter, hWndParent, (POINT *)&rcCenter, 2);
  141. }
  142. else
  143. {
  144. hWndCenter = GetWindow(hWnd2Center, GW_OWNER);
  145. if (hWndCenter)
  146. {
  147. dwStyle = (DWORD)GetWindowLong(hWndCenter, GWL_STYLE);
  148. if (!(dwStyle & WS_VISIBLE) || (dwStyle & WS_MINIMIZE))
  149. {
  150. hWndCenter = NULL;
  151. }
  152. }
  153. SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);
  154. if (hWndCenter)
  155. {
  156. GetWindowRect(hWndCenter, &rcCenter);
  157. }
  158. else
  159. {
  160. rcCenter = rcArea;
  161. }
  162. }
  163. w_Dlg = rcDlg.right - rcDlg.left;
  164. h_Dlg = rcDlg.bottom - rcDlg.top;
  165. xLeft = (rcCenter.left + rcCenter.right) / 2 - w_Dlg / 2;
  166. yTop = (rcCenter.top + rcCenter.bottom) / 2 - h_Dlg / 2;
  167. if (xLeft < rcArea.left)
  168. {
  169. xLeft = rcArea.left;
  170. }
  171. else if ((xLeft + w_Dlg) > rcArea.right)
  172. {
  173. xLeft = rcArea.right - w_Dlg;
  174. }
  175. if (yTop < rcArea.top)
  176. {
  177. yTop = rcArea.top;
  178. }
  179. else if ((yTop + h_Dlg) > rcArea.bottom)
  180. {
  181. yTop = rcArea.bottom - h_Dlg;
  182. }
  183. SetWindowPos(hWnd2Center, NULL, xLeft, yTop, -1, -1, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
  184. }
  185. void ISPUdlg_::SetItemText(DWORD dwControlId, WCHAR *pwszText)
  186. {
  187. DWORD cbsz;
  188. char *psz;
  189. cbsz = (DWORD)WideCharToMultiByte(0, 0, pwszText, wcslen(pwszText) + 1, NULL, 0, NULL, NULL);
  190. if (cbsz < 1)
  191. {
  192. return;
  193. }
  194. if (!(psz = new char[cbsz + 1]))
  195. {
  196. return;
  197. }
  198. psz[0] = NULL;
  199. WideCharToMultiByte(0, 0, pwszText, wcslen(pwszText) + 1, psz, cbsz, NULL, NULL);
  200. SetDlgItemText(m_hWndMe, (UINT)dwControlId, psz);
  201. delete psz;
  202. }
  203. BOOL ISPUdlg_::GetItemText(DWORD dwControlId, WCHAR **ppwszText)
  204. {
  205. DWORD cbsz;
  206. char *psz;
  207. *ppwszText = NULL;
  208. cbsz = (DWORD)SendDlgItemMessage(m_hWndMe, (UINT)dwControlId, WM_GETTEXTLENGTH, 0, 0);
  209. if (cbsz < 1)
  210. {
  211. return(FALSE);
  212. }
  213. if (!(psz = new char[cbsz + 1]))
  214. {
  215. return(FALSE);
  216. }
  217. psz[0] = NULL;
  218. GetDlgItemText(m_hWndMe, (UINT)dwControlId, psz, cbsz + 1);
  219. if (!(*ppwszText = new WCHAR[cbsz + 1]))
  220. {
  221. delete psz;
  222. return(FALSE);
  223. }
  224. MultiByteToWideChar(0, 0, psz, -1, *ppwszText, cbsz + 1);
  225. delete psz;
  226. return(TRUE);
  227. }
  228. //////////////////////////////////////////////////////////////////////////
  229. ////
  230. //// local
  231. ////
  232. INT_PTR CALLBACK UIMessageProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  233. {
  234. ISPUdlg_ *pUI;
  235. if (uMsg == WM_INITDIALOG)
  236. {
  237. pUI = (ISPUdlg_ *)lParam;
  238. SetWindowLongPtr(hWnd, DWLP_USER, (INT_PTR)lParam);
  239. }
  240. else
  241. {
  242. pUI = (ISPUdlg_ *)GetWindowLongPtr(hWnd, DWLP_USER);
  243. }
  244. if (!(pUI))
  245. {
  246. return(FALSE);
  247. }
  248. return(pUI->OnMessage(hWnd, uMsg, wParam, lParam));
  249. }
  250. INT_PTR CALLBACK ProcessingDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  251. {
  252. switch(uMsg)
  253. {
  254. case WM_INITDIALOG:
  255. return(TRUE);
  256. }
  257. return(FALSE);
  258. }