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.

476 lines
14 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. EXITMESS.C
  5. Abstract:
  6. good bye message dialog box
  7. Author:
  8. Bob Watson (a-robw)
  9. Revision History:
  10. 17 Feb 94 Written
  11. --*/
  12. //
  13. // Windows Include Files
  14. //
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <tchar.h> // unicode macros
  19. //
  20. // app include files
  21. //
  22. #include "otnboot.h"
  23. #include "otnbtdlg.h"
  24. //
  25. extern BOOL bDisplayExitMessages;
  26. static
  27. DWORD
  28. FormatExitMessageString (
  29. IN HWND hTextWnd,
  30. IN OUT LPTSTR szBuffer,
  31. IN DWORD dwBufSize
  32. )
  33. /*++
  34. Routine Description:
  35. Formats the message string to fit in the Text Window by word wrapping
  36. and indenting the text string in szBuffer.
  37. Arguments:
  38. IN HWND hTextWnd
  39. handle of text window that will display the text
  40. IN OUT LPTSTR szBuffer
  41. string to display
  42. IN DWORD dwBufSize
  43. size of szBuffer in characters
  44. Return Value:
  45. --*/
  46. {
  47. LPTSTR szWorkString;
  48. LPTSTR szSrc, szDest, szLine, szSrcWord, szDestWord;
  49. HDC hDC;
  50. SIZE sizeText;
  51. RECT rTextWnd;
  52. int nCharsInLine;
  53. DWORD dwCharsInString = 0;
  54. LONG nWindowWidth;
  55. //#ifdef DBCS
  56. // fixed kkntbug #10802
  57. // NCAdmin: The sentence of an end message is strange
  58. WORD wCharType;
  59. WCHAR szCheckStyle[2];
  60. LCID lcid = GetSystemDefaultLCID();
  61. HFONT hf, hfOld;
  62. //#endif
  63. szWorkString = GlobalAlloc (GPTR, dwBufSize * sizeof(TCHAR));
  64. if (szWorkString != NULL) {
  65. // get DC of window
  66. hDC = GetDC (hTextWnd);
  67. if( hDC != NULL ) {
  68. //#ifdef DBCS
  69. // fixed kkntbug #10802
  70. // NCAdmin: The sentence of an end message is strange
  71. // reset DC with font object for getting correct size
  72. hf = (HFONT)SendMessage(hTextWnd, WM_GETFONT, 0, 0);
  73. if (hf) hfOld = SelectObject(hDC, hf);
  74. //#endif
  75. // get size of window
  76. GetWindowRect (hTextWnd, &rTextWnd);
  77. nWindowWidth = rTextWnd.right - rTextWnd.left;
  78. // subtract left & right borders
  79. nWindowWidth -= (GetSystemMetrics (SM_CXBORDER) * 2);
  80. // subtract scroll bar width
  81. nWindowWidth -= GetSystemMetrics (SM_CXVSCROLL);
  82. // subtract text indent
  83. //#ifdef DBCS
  84. // fixed kkntbug #10802
  85. // NCAdmin: The sentence of an end message is strange
  86. sizeText.cx = sizeText.cy = 0;
  87. GetTextExtentPoint32 (hDC,
  88. fmtLeadingSpaces,
  89. lstrlen(fmtLeadingSpaces),
  90. &sizeText);
  91. nWindowWidth -= sizeText.cx;
  92. //#else
  93. // nWindowWidth -= 4; // as measured
  94. //#endif
  95. // initialize pointers & counters
  96. szSrc = szSrcWord = szBuffer;
  97. szLine = szDestWord = szDest = szWorkString;
  98. nCharsInLine = 0;
  99. dwCharsInString = 0;
  100. // process string
  101. while (*szSrc != 0) {
  102. *szDest = *szSrc;
  103. // get length of new string after a word has been copied
  104. //#ifdef DBCS
  105. // fixed kkntbug #10802
  106. // NCAdmin: The sentence of an end message is strange
  107. // fixed kkntbug #13147
  108. // NCAdmin:When ending "Make Network Installation Setup Disk" ,apllication error occurs.
  109. //
  110. // check what the "szSrc"(just 1 character) is type
  111. //
  112. szCheckStyle[0] = *szSrc;
  113. szCheckStyle[1] = UNICODE_NULL;
  114. if (!GetStringTypeEx(lcid,
  115. CT_CTYPE3,
  116. szCheckStyle,
  117. 1,
  118. &wCharType))
  119. wCharType = 0;
  120. if ((*szSrc == cSpace) ||
  121. (wCharType & C3_KATAKANA) ||
  122. !(wCharType & C3_HALFWIDTH)) {
  123. //#else
  124. // if (*szSrc == cSpace) {
  125. //#endif
  126. // reset size variable
  127. sizeText.cx = sizeText.cy = 0;
  128. GetTextExtentPoint32 (hDC, szLine, nCharsInLine, &sizeText);
  129. // then check the size
  130. if (sizeText.cx >= nWindowWidth) {
  131. // this word pushes past the edge so wrap the word
  132. // and place it on the next line
  133. lstrcpy (szDestWord, cszCrLf);
  134. szLine = szDestWord+2; // start new line after CrLf
  135. dwCharsInString += 2;
  136. lstrcat (szDestWord, fmtLeadingSpaces);
  137. szSrc = szSrcWord;
  138. szDest = szDestWord + lstrlen(szDestWord);
  139. // copy last word to new line
  140. //#ifdef DBCS
  141. // fixed kkntbug #10802
  142. // NCAdmin: The sentence of an end message is strange
  143. // fixed kkntbug #13147
  144. // NCAdmin:When ending "Make Network Installation Setup Disk" ,apllication error occurs.
  145. while (*szSrc) {
  146. //
  147. // check what the "szSrc"(just 1 character) is type
  148. //
  149. szCheckStyle[0] = *szSrc;
  150. szCheckStyle[1] = UNICODE_NULL;
  151. if (!GetStringTypeEx(lcid,
  152. CT_CTYPE3,
  153. szCheckStyle,
  154. 1,
  155. &wCharType))
  156. wCharType = 0;
  157. if ((wCharType & C3_KATAKANA) ||
  158. !(wCharType & C3_HALFWIDTH) ||
  159. (*szSrc == cSpace) ||
  160. (*szSrc == 0))
  161. break;
  162. //#else
  163. // while ((*szSrc != cSpace) && (*szSrc != 0)) {
  164. //#endif
  165. *szDest++ = *szSrc++;
  166. }
  167. //#ifdef DBCS
  168. // fixed kkntbug #10802
  169. // NCAdmin: The sentence of an end message is strange
  170. if ((*szSrc != 0) &&
  171. !(wCharType & C3_KATAKANA) &&
  172. (wCharType & C3_HALFWIDTH)) {
  173. //#else
  174. // if (*szSrc != 0) {
  175. //#endif
  176. // copy space after word to get back to pre-wrap
  177. // position
  178. *szDest++ = *szSrc++;
  179. }
  180. // update counters
  181. nCharsInLine = lstrlen(szLine);
  182. dwCharsInString += nCharsInLine;
  183. } else {
  184. //this one fits, so advance pointer to next char
  185. szDest++;
  186. szSrc++;
  187. nCharsInLine++;
  188. dwCharsInString++;
  189. }
  190. // update word pointers
  191. szSrcWord = szSrc;
  192. szDestWord = szDest;
  193. } else {
  194. szSrc++;
  195. szDest++;
  196. nCharsInLine++;
  197. dwCharsInString++;
  198. }
  199. if (dwCharsInString >= dwBufSize) break; // quit before overflow
  200. }
  201. //#ifdef DBCS
  202. // restore old font object
  203. if (hf) SelectObject(hDC, hfOld);
  204. //#endif
  205. ReleaseDC (hTextWnd, hDC);
  206. // copy new string to orig.
  207. lstrcpy (szBuffer, szWorkString);
  208. FREE_IF_ALLOC (szWorkString);
  209. }
  210. }
  211. return dwCharsInString;
  212. }
  213. static
  214. BOOL
  215. ExitMessDlg_WM_INITDIALOG (
  216. IN HWND hwndDlg,
  217. IN WPARAM wParam,
  218. IN LPARAM lParam
  219. )
  220. /*++
  221. Routine Description:
  222. Initializes message display translating all buffered message codes
  223. and writing the corresponding messages to the display. If no
  224. messages are in the list, the the dialog box is closed and not
  225. displayed.
  226. Arguments:
  227. IN HWND hwndDlg
  228. Handle to dialog box window
  229. IN WPARAM wParam
  230. Not Used
  231. IN LPARAM lParam
  232. Not Used
  233. Return Value:
  234. FALSE if messages displayed
  235. TRUE if dialog box is closed
  236. --*/
  237. {
  238. LPTSTR szTextBuff;
  239. LPTSTR szStringBuff;
  240. DWORD dwMsgNdx;
  241. RECT rEditWindow;
  242. BOOL bReturn;
  243. // don't even bother unless the "display Exit Messages" flag is set
  244. if (bDisplayExitMessages) {
  245. szStringBuff = GlobalAlloc (GPTR, SMALL_BUFFER_SIZE * sizeof(TCHAR));
  246. if (szStringBuff == NULL) return TRUE;
  247. // only display if there are any messages to show
  248. if (pAppInfo->uExitMessages[0] != 0) {
  249. RemoveMaximizeFromSysMenu (hwndDlg);
  250. PositionWindow (hwndDlg);
  251. szTextBuff = GlobalAlloc (GPTR, (MEDIUM_BUFFER_SIZE * sizeof(TCHAR)));
  252. if (szTextBuff != NULL) {
  253. *szTextBuff = 0;
  254. // load TextBuff with strings that should appear in message box
  255. for (dwMsgNdx = 0; dwMsgNdx < MAX_EXITMSG; dwMsgNdx++) {
  256. if (pAppInfo->uExitMessages[dwMsgNdx] > 0) {
  257. if (LoadString (
  258. (HINSTANCE)GetWindowLongPtr(GetParent(hwndDlg), GWLP_HINSTANCE),
  259. pAppInfo->uExitMessages[dwMsgNdx],
  260. szStringBuff,
  261. MAX_PATH) > 0) {
  262. FormatExitMessageString (
  263. GetDlgItem (hwndDlg, NCDU_CONTINUE_MESSAGE),
  264. szStringBuff, SMALL_BUFFER_SIZE);
  265. if ((lstrlen(szStringBuff) + lstrlen(szTextBuff) + 2) > MEDIUM_BUFFER_SIZE) {
  266. if(GlobalReAlloc(szTextBuff, (lstrlen(szStringBuff) + lstrlen(szTextBuff) + 2), GPTR) == NULL) {
  267. break;
  268. }
  269. lstrcat (szTextBuff, szStringBuff);
  270. lstrcat (szTextBuff, cszCrLf);
  271. }
  272. }
  273. } else {
  274. break;
  275. }
  276. }
  277. GetClientRect (GetDlgItem (hwndDlg, NCDU_CONTINUE_MESSAGE), &rEditWindow);
  278. SendDlgItemMessage (hwndDlg, NCDU_CONTINUE_MESSAGE, EM_SETRECT,
  279. (WPARAM)0, (LPARAM)&rEditWindow);
  280. SendDlgItemMessage (hwndDlg, NCDU_CONTINUE_MESSAGE, EM_FMTLINES,
  281. (WPARAM)TRUE, 0);
  282. SetDlgItemText (hwndDlg, NCDU_CONTINUE_MESSAGE, szTextBuff);
  283. GetDlgItemText (hwndDlg, NCDU_CONTINUE_MESSAGE,
  284. szTextBuff, (int)GlobalSize (szTextBuff));
  285. SetDlgItemText (hwndDlg, NCDU_CONTINUE_MESSAGE, szTextBuff);
  286. FREE_IF_ALLOC (szTextBuff);
  287. } else {
  288. // this is OK because this dialog never "registered"
  289. EndDialog (hwndDlg, (int)WM_CLOSE);
  290. }
  291. SetFocus (GetDlgItem(hwndDlg, IDOK));
  292. bReturn = FALSE;
  293. } else {
  294. // no mesaages to show so end dialog now
  295. EndDialog (hwndDlg, (int)WM_CLOSE);
  296. bReturn = TRUE;
  297. }
  298. FREE_IF_ALLOC (szStringBuff);
  299. PostMessage (GetParent(hwndDlg), NCDU_CLEAR_DLG, (WPARAM)hwndDlg, IDOK);
  300. PostMessage (GetParent(hwndDlg), NCDU_REGISTER_DLG,
  301. NCDU_EXIT_MESSAGE_DLG, (LPARAM)hwndDlg);
  302. SetCursor(LoadCursor(NULL, IDC_ARROW));
  303. } else {
  304. // this is OK because this dialog never "registered"
  305. EndDialog (hwndDlg, (int)WM_CLOSE);
  306. bReturn = TRUE;
  307. }
  308. return bReturn;
  309. }
  310. static
  311. BOOL
  312. ExitMessDlg_WM_COMMAND (
  313. IN HWND hwndDlg,
  314. IN WPARAM wParam,
  315. IN LPARAM lParam
  316. )
  317. /*++
  318. Routine Description:
  319. Processes the windows message sent when a user presses a button or
  320. menu item
  321. Arguments:
  322. IN HWND hwndDlg
  323. Handle to dialog box window
  324. IN WPARAM wParam
  325. LOPARAM contains the ID of the control that initiated the command
  326. (i.e. the one that was pushed)
  327. IN LPARAM lParam
  328. Not used
  329. Return Value:
  330. TRUE if the message was processed
  331. FALSE if not
  332. --*/
  333. {
  334. switch (LOWORD(wParam)) {
  335. case IDCANCEL:
  336. switch (HIWORD(wParam)) {
  337. case BN_CLICKED:
  338. PostMessage (GetParent (hwndDlg),
  339. (int)NCDU_SHOW_SW_CONFIG_DLG, 0, 0);
  340. SetCursor(LoadCursor(NULL, IDC_WAIT));
  341. return TRUE;
  342. default:
  343. return FALSE;
  344. }
  345. case IDOK:
  346. switch (HIWORD(wParam)) {
  347. case BN_CLICKED:
  348. PostMessage (GetParent (hwndDlg),
  349. (int)WM_CLOSE, 0, 0);
  350. SetCursor(LoadCursor(NULL, IDC_WAIT));
  351. return TRUE;
  352. default:
  353. return FALSE;
  354. }
  355. default:
  356. return FALSE;
  357. }
  358. }
  359. INT_PTR CALLBACK
  360. ExitMessDlgProc (
  361. IN HWND hwndDlg,
  362. IN UINT message,
  363. IN WPARAM wParam,
  364. IN LPARAM lParam
  365. )
  366. /*++
  367. Routine Description:
  368. Main Dialog Box Param. Dispatchs to the local processing routine
  369. on receipt of the following messages.
  370. WM_INITDIALOG: Dialog box initialization
  371. WM_COMMAND: Sent when user selects a button
  372. WM_PAINT: for painting icon when minimized
  373. WM_MOVE: for saving the new location of the window
  374. WM_SYSCOMMAND: for processing menu messages
  375. all other messages are passed to the default dialag box
  376. procedure.
  377. Arguments:
  378. Standard WNDPROC arguments
  379. Return Value:
  380. FALSE if not processed otherwise, the value returned by the
  381. called routine.
  382. --*/
  383. {
  384. switch (message) {
  385. case WM_INITDIALOG: return (ExitMessDlg_WM_INITDIALOG (hwndDlg, wParam, lParam));
  386. case WM_COMMAND: return (ExitMessDlg_WM_COMMAND (hwndDlg, wParam, lParam));
  387. case WM_PAINT: return (Dlg_WM_PAINT (hwndDlg, wParam, lParam));
  388. case WM_MOVE: return (Dlg_WM_MOVE (hwndDlg, wParam, lParam));
  389. case WM_SYSCOMMAND: return (Dlg_WM_SYSCOMMAND (hwndDlg, wParam, lParam));
  390. default: return FALSE;
  391. }
  392. }