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.

424 lines
10 KiB

  1. #include "precomp.h"
  2. #include "resource.h"
  3. /****************************************************************************
  4. *
  5. * FILE: DShowDlg.cpp
  6. *
  7. * CREATED: Chris Pirich (ChrisPi) 5-6-96
  8. *
  9. * CONTENTS: CDontShowDlg object
  10. *
  11. ****************************************************************************/
  12. #include "DShowDlg.h"
  13. #include "conf.h"
  14. #include "ConfUtil.h"
  15. /****************************************************************************
  16. *
  17. * CLASS: CDontShowDlg
  18. *
  19. * MEMBER: CDontShowDlg()
  20. *
  21. * PURPOSE: Constructor - initializes variables
  22. *
  23. ****************************************************************************/
  24. CDontShowDlg::CDontShowDlg( UINT uMsgId,
  25. LPCTSTR pcszRegVal,
  26. UINT uFlags):
  27. m_uMsgId (uMsgId),
  28. m_hwnd (NULL),
  29. m_reDontShow (UI_KEY, HKEY_CURRENT_USER),
  30. m_uFlags (uFlags),
  31. m_nWidth (0),
  32. m_nHeight (0),
  33. m_nTextWidth (0),
  34. m_nTextHeight (0)
  35. {
  36. DebugEntry(CDontShowDlg::CDontShowDlg);
  37. ASSERT(pcszRegVal);
  38. m_pszRegVal = PszAlloc(pcszRegVal);
  39. DebugExitVOID(CDontShowDlg::CDontShowDlg);
  40. }
  41. /****************************************************************************
  42. *
  43. * CLASS: CDontShowDlg
  44. *
  45. * MEMBER: DoModal()
  46. *
  47. * PURPOSE: Brings up the modal dialog box
  48. *
  49. ****************************************************************************/
  50. INT_PTR CDontShowDlg::DoModal(HWND hwnd)
  51. {
  52. DebugEntry(CDontShowDlg::DoModal);
  53. INT_PTR nRet = IDCANCEL;
  54. if (_Module.InitControlMode())
  55. {
  56. nRet = IDOK;
  57. }
  58. else if (NULL != m_pszRegVal)
  59. {
  60. // If the "dont show me" check box has been checked before and stored in
  61. // the registry, then return IDOK, so the calling code doesn't have to
  62. // differentiate the two cases.
  63. nRet = (TRUE == m_reDontShow.GetNumber(m_pszRegVal, FALSE)) ?
  64. IDOK : IDCANCEL;
  65. }
  66. if (IDOK != nRet)
  67. {
  68. HWND hwndDesktop = ::GetDesktopWindow();
  69. if (NULL != hwndDesktop)
  70. {
  71. HDC hdc = ::GetDC(hwndDesktop);
  72. if (NULL != hdc)
  73. {
  74. HFONT hFontOld = (HFONT) SelectObject(hdc, g_hfontDlg);
  75. TCHAR szString[DS_MAX_MESSAGE_LENGTH];
  76. LPTSTR pszString = NULL;
  77. if (0 != HIWORD(m_uMsgId))
  78. {
  79. // use m_uMsgId as a string pointer
  80. // NOTE: object must be used on the stack since the pointer is
  81. // not copied
  82. pszString = (LPTSTR) m_uMsgId;
  83. }
  84. else if (::LoadString( ::GetInstanceHandle(), (UINT)m_uMsgId,
  85. szString, ARRAY_ELEMENTS(szString)))
  86. {
  87. pszString = szString;
  88. }
  89. if (NULL != pszString)
  90. {
  91. m_nTextWidth = DS_MAX_TEXT_WIDTH;
  92. RECT rct = {0, 0, m_nTextWidth, 0xFFFF};
  93. m_nTextHeight = ::DrawText( hdc,
  94. pszString,
  95. -1,
  96. &rct,
  97. DT_LEFT | DT_CALCRECT | DT_WORDBREAK);
  98. }
  99. ::SelectObject(hdc, hFontOld);
  100. ::ReleaseDC(hwndDesktop, hdc);
  101. }
  102. }
  103. // If the box wasn't checked before, then bring up the dialog:
  104. nRet = DialogBoxParam( ::GetInstanceHandle(),
  105. MAKEINTRESOURCE(IDD_DONT_SHOW_ME),
  106. hwnd,
  107. CDontShowDlg::DontShowDlgProc,
  108. (LPARAM) this);
  109. }
  110. DebugExitINT_PTR(CDontShowDlg::DoModal, nRet);
  111. return nRet;
  112. }
  113. /****************************************************************************
  114. *
  115. * CLASS: CDontShowDlg
  116. *
  117. * MEMBER: DontShowDlgProc()
  118. *
  119. * PURPOSE: Dialog Proc - handles all messages
  120. *
  121. ****************************************************************************/
  122. INT_PTR CALLBACK CDontShowDlg::DontShowDlgProc(HWND hDlg,
  123. UINT uMsg,
  124. WPARAM wParam,
  125. LPARAM lParam)
  126. {
  127. BOOL bMsgHandled = FALSE;
  128. // uMsg may be any value.
  129. // wparam may be any value.
  130. // lparam may be any value.
  131. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  132. switch (uMsg)
  133. {
  134. case WM_INITDIALOG:
  135. {
  136. if (NULL != lParam)
  137. {
  138. CDontShowDlg* pdsd = (CDontShowDlg*) lParam;
  139. pdsd->m_hwnd = hDlg;
  140. ::SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  141. int nInitialTextWidth = 0;
  142. int nInitialTextHeight = 0;
  143. TCHAR szMsgBuf[DS_MAX_MESSAGE_LENGTH];
  144. if (0 != HIWORD(pdsd->m_uMsgId))
  145. {
  146. // use m_uMsgId as a string pointer
  147. // NOTE: object must be used on the stack since the pointer is
  148. // not copied
  149. ASSERT(IS_VALID_READ_PTR((LPTSTR) pdsd->m_uMsgId, TCHAR));
  150. lstrcpyn(szMsgBuf, (LPTSTR) pdsd->m_uMsgId, CCHMAX(szMsgBuf));
  151. }
  152. else
  153. {
  154. ::LoadString( ::GetInstanceHandle(),
  155. (INT)pdsd->m_uMsgId,
  156. szMsgBuf,
  157. (INT)ARRAY_ELEMENTS(szMsgBuf));
  158. }
  159. // Set the text
  160. ::SetDlgItemText( hDlg,
  161. IDC_TEXT_STATIC,
  162. szMsgBuf);
  163. RECT rctDlg;
  164. ::GetWindowRect(hDlg, &rctDlg);
  165. int nOrigWidth = rctDlg.right - rctDlg.left;
  166. int nOrigHeight = rctDlg.bottom - rctDlg.top;
  167. HWND hwndText = ::GetDlgItem(hDlg, IDC_TEXT_STATIC);
  168. if (NULL != hwndText)
  169. {
  170. RECT rctText;
  171. if (::GetWindowRect(hwndText, &rctText))
  172. {
  173. nInitialTextWidth = rctText.right - rctText.left;
  174. nInitialTextHeight = rctText.bottom - rctText.top;
  175. // Resize the text control
  176. ::SetWindowPos( hwndText,
  177. NULL, 0, 0,
  178. pdsd->m_nTextWidth,
  179. pdsd->m_nTextHeight,
  180. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
  181. }
  182. // Set the font (for DBCS systems)
  183. ::SendMessage(hwndText, WM_SETFONT, (WPARAM) g_hfontDlg, 0);
  184. }
  185. pdsd->m_nWidth = (nOrigWidth - nInitialTextWidth)
  186. + pdsd->m_nTextWidth;
  187. pdsd->m_nHeight = (nOrigHeight - nInitialTextHeight)
  188. + pdsd->m_nTextHeight;
  189. RECT rctCtrl;
  190. // Move the ok button (IDOK)
  191. HWND hwndOK = ::GetDlgItem(hDlg, IDOK);
  192. if ((NULL != hwndOK) && ::GetWindowRect(hwndOK, &rctCtrl))
  193. {
  194. // Turn rctCtrl's top and left into client coords:
  195. ::MapWindowPoints(NULL, hDlg, (LPPOINT) &rctCtrl, 2);
  196. if (pdsd->m_uFlags & MB_OKCANCEL)
  197. {
  198. ::SetWindowPos( hwndOK,
  199. NULL,
  200. rctCtrl.left + ((pdsd->m_nWidth - nOrigWidth) / 2),
  201. rctCtrl.top + (pdsd->m_nHeight - nOrigHeight),
  202. 0, 0,
  203. SWP_NOACTIVATE | SWP_NOZORDER
  204. | SWP_NOSIZE | SWP_NOREDRAW);
  205. }
  206. else
  207. {
  208. // center the OK button
  209. ::SetWindowPos( hwndOK,
  210. NULL,
  211. (pdsd->m_nWidth / 2) -
  212. ((rctCtrl.right - rctCtrl.left) / 2),
  213. rctCtrl.top + (pdsd->m_nHeight - nOrigHeight),
  214. 0, 0,
  215. SWP_NOACTIVATE | SWP_NOZORDER
  216. | SWP_NOSIZE | SWP_NOREDRAW);
  217. }
  218. }
  219. // Move the cancel button (IDCANCEL)
  220. HWND hwndCancel = ::GetDlgItem(hDlg, IDCANCEL);
  221. if ((NULL != hwndCancel) && ::GetWindowRect(hwndCancel, &rctCtrl))
  222. {
  223. if (pdsd->m_uFlags & MB_OKCANCEL)
  224. {
  225. // Turn rctCtrl's top and left into client coords:
  226. ::MapWindowPoints(NULL, hDlg, (LPPOINT) &rctCtrl, 1);
  227. ::SetWindowPos( hwndCancel,
  228. NULL,
  229. rctCtrl.left + ((pdsd->m_nWidth - nOrigWidth) / 2),
  230. rctCtrl.top + (pdsd->m_nHeight - nOrigHeight),
  231. 0, 0,
  232. SWP_NOACTIVATE | SWP_NOZORDER
  233. | SWP_NOSIZE | SWP_NOREDRAW);
  234. }
  235. else
  236. {
  237. ::ShowWindow(hwndCancel, SW_HIDE);
  238. }
  239. }
  240. // Move the check box (IDC_DONT_SHOW_ME_CHECK)
  241. HWND hwndCheck = ::GetDlgItem(hDlg, IDC_DONT_SHOW_ME_CHECK);
  242. if ((NULL != hwndCheck) && ::GetWindowRect(hwndCheck, &rctCtrl))
  243. {
  244. // Turn rctCtrl's top and left into client coords:
  245. ::MapWindowPoints(NULL, hDlg, (LPPOINT) &rctCtrl, 1);
  246. ::SetWindowPos( hwndCheck,
  247. NULL,
  248. rctCtrl.left,
  249. rctCtrl.top + (pdsd->m_nHeight - nOrigHeight),
  250. 0, 0,
  251. SWP_NOACTIVATE | SWP_NOZORDER
  252. | SWP_NOSIZE | SWP_NOREDRAW);
  253. }
  254. // Show, resize, and activate
  255. ::SetWindowPos( hDlg,
  256. 0,
  257. 0,
  258. 0,
  259. pdsd->m_nWidth,
  260. pdsd->m_nHeight,
  261. SWP_SHOWWINDOW | SWP_NOZORDER |
  262. SWP_NOMOVE | SWP_DRAWFRAME);
  263. // Put the appropriate icon on the dialog:
  264. HWND hwndIcon = ::GetDlgItem(hDlg, IDC_ICON_STATIC);
  265. ::SendMessage( hwndIcon,
  266. STM_SETICON,
  267. (WPARAM) ::LoadIcon(NULL, IDI_INFORMATION),
  268. 0);
  269. if (pdsd->m_uFlags & DSD_ALWAYSONTOP)
  270. {
  271. ::SetWindowPos( hDlg,
  272. HWND_TOPMOST,
  273. 0, 0, 0, 0,
  274. SWP_NOMOVE | SWP_NOSIZE);
  275. }
  276. if (pdsd->m_uFlags & MB_SETFOREGROUND)
  277. {
  278. ::SetForegroundWindow(hDlg);
  279. }
  280. }
  281. bMsgHandled = 1;
  282. break;
  283. }
  284. default:
  285. {
  286. CDontShowDlg* ppd = (CDontShowDlg*) GetWindowLongPtr( hDlg,
  287. DWLP_USER);
  288. if (NULL != ppd)
  289. {
  290. bMsgHandled = ppd->OnMessage(uMsg, wParam, lParam);
  291. }
  292. }
  293. }
  294. return bMsgHandled;
  295. }
  296. /****************************************************************************
  297. *
  298. * CLASS: CDontShowDlg
  299. *
  300. * MEMBER: OnMessage()
  301. *
  302. * PURPOSE: processes all messages except WM_INITDIALOG
  303. *
  304. ****************************************************************************/
  305. BOOL CDontShowDlg::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  306. {
  307. BOOL bRet = FALSE;
  308. ASSERT(m_hwnd);
  309. switch (uMsg)
  310. {
  311. case WM_COMMAND:
  312. {
  313. switch (LOWORD(wParam))
  314. {
  315. case IDOK:
  316. {
  317. bRet = OnOk();
  318. break;
  319. }
  320. case IDCANCEL:
  321. {
  322. ::EndDialog(m_hwnd, LOWORD(wParam));
  323. bRet = TRUE;
  324. break;
  325. }
  326. }
  327. break;
  328. }
  329. default:
  330. break;
  331. }
  332. return bRet;
  333. }
  334. /****************************************************************************
  335. *
  336. * CLASS: CDontShowDlg
  337. *
  338. * MEMBER: OnOk()
  339. *
  340. * PURPOSE: processes the WM_COMMAND,IDOK message
  341. *
  342. ****************************************************************************/
  343. BOOL CDontShowDlg::OnOk()
  344. {
  345. DebugEntry(CDontShowDlg::OnOk);
  346. BOOL bRet = TRUE;
  347. if ((BST_CHECKED == ::IsDlgButtonChecked(m_hwnd, IDC_DONT_SHOW_ME_CHECK)) &&
  348. (NULL != m_pszRegVal))
  349. {
  350. m_reDontShow.SetValue(m_pszRegVal, TRUE);
  351. }
  352. ::EndDialog(m_hwnd, IDOK);
  353. DebugExitBOOL(CDontShowDlg::OnOk, bRet);
  354. return bRet;
  355. }
  356. ///////////////////////////////////////////////////////////////////////////////
  357. //
  358. /* F E N A B L E D O N T S H O W */
  359. /*-------------------------------------------------------------------------
  360. %%Function: FEnableDontShow
  361. Return TRUE if the "Don't Show" dialog is enabled
  362. -------------------------------------------------------------------------*/
  363. BOOL FEnableDontShow(LPCTSTR pszKey)
  364. {
  365. RegEntry reUI(UI_KEY, HKEY_CURRENT_USER);
  366. return (0 == reUI.GetNumber(pszKey, 0));
  367. }
  368.