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.

533 lines
13 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*************************************************************************/
  4. /***** Custom User Interface Library Sample ******************************/
  5. /*************************************************************************/
  6. DLGMP DialogMap[] =
  7. {
  8. (SZ)"Info", (WNDPROC)FGstInfoDlgProc, (PFNEVENT)NULL,
  9. (SZ)"Edit", (WNDPROC)FGstEditDlgProc, (PFNEVENT)NULL,
  10. (SZ)"MultiEdit", (WNDPROC)FGstMultiEditDlgProc, (PFNEVENT)NULL,
  11. (SZ)"Check", (WNDPROC)FGstCheckDlgProc, (PFNEVENT)NULL,
  12. (SZ)"Check1", (WNDPROC)FGstCheck1DlgProc, (PFNEVENT)EhrcGstCheck1EventHandler,
  13. (SZ)"Radio", (WNDPROC)FGstRadioDlgProc, (PFNEVENT)NULL,
  14. (SZ)"List", (WNDPROC)FGstListDlgProc, (PFNEVENT)NULL,
  15. (SZ)"Multi", (WNDPROC)FGstMultiDlgProc, (PFNEVENT)NULL,
  16. (SZ)"Dual", (WNDPROC)FGstDualDlgProc, (PFNEVENT)NULL,
  17. (SZ)"Dual1", (WNDPROC)FGstDual1DlgProc, (PFNEVENT)NULL,
  18. (SZ)"MultiCombo", (WNDPROC)FGstMultiComboDlgProc, (PFNEVENT)EhrcGstMultiComboEventHandler,
  19. (SZ)"Combination", (WNDPROC)FGstCombinationDlgProc, (PFNEVENT)EhrcGstMultiComboEventHandler,
  20. (SZ)"RadioCombination", (WNDPROC)FGstComboRadDlgProc, (PFNEVENT)EhrcGstMultiComboEventHandler,
  21. (SZ)"Maintenance", (WNDPROC)FGstMaintDlgProc, (PFNEVENT)EhrcGstMaintenanceEventHandler,
  22. (SZ)"Billboard", (WNDPROC)FGstBillboardDlgProc, (PFNEVENT)NULL
  23. };
  24. /*
  25. ** Purpose:
  26. ** To push the dialog szDlgName onto the top of the dialog stack if it
  27. ** is not already on top of the stack. if it is already on the top of
  28. ** the stack it merely ensures that the dialog is active and enabled.
  29. **
  30. ** Arguments:
  31. ** szDlgName: the name of the dialog (not the dialog template name).
  32. ** hinst: Handle to instance of the APP (i.e. the shell).
  33. ** hwndShell: Handle to the main app window (i.e. the shell).
  34. **
  35. ** Returns:
  36. ** fTrue if the operation succeeds, fFalse otherwise.
  37. **
  38. ****************************************************************************/
  39. BOOL APIENTRY
  40. FDoDialog(
  41. IN SZ szDlgName,
  42. IN HANDLE hInst,
  43. IN HWND hwndShell
  44. )
  45. {
  46. BOOL fReturn;
  47. SZ szDlgType, szDlgTemplate;
  48. pDLGMP pdlgmp;
  49. AssertDataSeg();
  50. Assert(szDlgName != NULL);
  51. // find the dialog type associated with this dialog and
  52. // validate it
  53. EvalAssert((szDlgType = SzFindSymbolValueInSymTab(DLGTYPE)) != NULL);
  54. // Handle the case when the dialog is already on the stack
  55. if (SzStackTopName() != NULL &&
  56. CrcStringCompare(szDlgName, SzStackTopName()) == crcEqual) {
  57. if (FResumeStackTop()) {
  58. Assert(HdlgStackTop() != NULL);
  59. PostMessage(HdlgStackTop(), (UINT)STF_REINITDIALOG, 0, 0L);
  60. fReturn = fTrue;
  61. }
  62. else {
  63. fReturn = fFalse;
  64. }
  65. }
  66. else {
  67. // find out if the dialog is a message box. message boxes are handled
  68. // here.
  69. if ( CrcStringCompare(szDlgType, "MessageBox") == crcEqual ) {
  70. fReturn = FHandleUIMessageBox(hwndShell);
  71. PostMessage(hwndShell, (UINT) STF_SHL_INTERP, 0, 0L);
  72. return(fReturn);
  73. }
  74. else {
  75. //
  76. // find the dialog template associated with this dialog and
  77. // validate it. see if what we are doing is enough
  78. EvalAssert((szDlgTemplate = SzFindSymbolValueInSymTab(DLGTEMPLATE)) != NULL);
  79. //
  80. // map the dialog type into a dialog procedure
  81. //
  82. EvalAssert((pdlgmp = pdlgmpFindDlgType (szDlgType, DialogMap)) != NULL);
  83. //
  84. // start the dialog
  85. //
  86. fReturn = (HdlgPushDbcb(
  87. hInst,
  88. szDlgName,
  89. szDlgTemplate,
  90. hwndShell,
  91. pdlgmp->FGstDlgProc,
  92. (DWORD)0,
  93. pdlgmp->EhrcEventHandler,
  94. (SZ)"",
  95. (WNDPROC)NULL
  96. ) != NULL);
  97. }
  98. }
  99. if ( CrcStringCompare( szDlgType, "Billboard" ) == crcEqual ) {
  100. PostMessage(hwndShell, (UINT) STF_SHL_INTERP, 0, 0L);
  101. }
  102. return( fReturn );
  103. }
  104. pDLGMP
  105. pdlgmpFindDlgType(
  106. IN SZ szDlgType,
  107. IN pDLGMP DialogMap
  108. )
  109. {
  110. while ( DialogMap!=NULL &&
  111. CrcStringCompare(szDlgType, DialogMap->szDlgType) != crcEqual ) {
  112. DialogMap++;
  113. }
  114. return (DialogMap);
  115. }
  116. /*
  117. ** Purpose:
  118. ** To destroy the top N dialogs on the dialog stack and free the storage
  119. ** occupied by their DBCB's (dialog box context blocks).
  120. **
  121. ** Arguments:
  122. ** n: The number of dialogs to be destroyed.
  123. ** fResume: Indicates if the dialog on top of the dialog stack after
  124. ** killing N dialogs should be resumed. fResume = fTrue means
  125. ** that it should be resumed, fFalse means that it should not
  126. ** be resumed.
  127. **
  128. ** Returns:
  129. ** fTrue if the operation is completely successful (i.e. all n of the
  130. ** dialogs are successfully destroyed and the top of stack is resumed if
  131. ** appropriate), fFalse otherwise.
  132. ****************************************************************************/
  133. BOOL APIENTRY FKillNDialogs(USHORT n,BOOL fResume)
  134. {
  135. BOOL fReturn;
  136. AssertDataSeg();
  137. Assert(n > 0);
  138. if ((fReturn = (FPopNDbcb(n) != fFalse)) &&
  139. fResume)
  140. {
  141. Assert(!FStackEmpty());
  142. fReturn = FResumeStackTop();
  143. }
  144. return(fReturn);
  145. }
  146. /*
  147. ** Purpose:
  148. ** Display a message box whose characteristics are drawn from the
  149. ** symbol table.
  150. ** Arguments:
  151. ** hwndParent: non-NULL handle to parent's window.
  152. ** Symbol Table Inputs:
  153. ** STF_MB_TITLE: string to display as title - can be blank.
  154. ** STF_MB_TEXT: string to display as text - should not be blank.
  155. ** STF_MB_TYPE: 1 -> MB_OK; 2 -> MB_OKCANCEL; 3 -> MB_YESNO;
  156. ** 4 -> MB_YESNOCANCEL; 5 -> MB_RETRYCANCEL; 6 -> MB_ABORTRETRYIGNORE.
  157. ** STF_MB_ICON: 1 -> none; 2 -> info; 3 -> stop; 4 -> ?; 5 -> !
  158. ** STF_MB_DEF: default button - 1 (default), 2, or 3.
  159. ** Symbol Table Outputs:
  160. ** DLGEVENT: "ABORT", "CANCEL", "IGNORE", "NO", "OK", "RETRY", or "YES".
  161. ** Returns:
  162. ** fFalse for undefined input symbols or OOM; fTrue otherwise.
  163. ****************************************************************************/
  164. BOOL APIENTRY FHandleUIMessageBox(hwndParent)
  165. HWND hwndParent;
  166. {
  167. INT imbReturn;
  168. UINT wType = MB_TASKMODAL;
  169. SZ szTitle, szText;
  170. BOOL fRet = fFalse;
  171. HWND aw;
  172. ChkArg(hwndParent != NULL, 1, fFalse);
  173. if ((szText = SzFindSymbolValueInSymTab("STF_MB_TYPE")) == NULL)
  174. {
  175. Assert(fFalse);
  176. goto LHUIMBError;
  177. }
  178. switch (*szText)
  179. {
  180. case '1':
  181. wType |= MB_OK;
  182. break;
  183. case '2':
  184. wType |= MB_OKCANCEL;
  185. break;
  186. case '3':
  187. wType |= MB_YESNO;
  188. break;
  189. case '4':
  190. wType |= MB_YESNOCANCEL;
  191. break;
  192. case '5':
  193. wType |= MB_RETRYCANCEL;
  194. break;
  195. case '6':
  196. wType |= MB_ABORTRETRYIGNORE;
  197. break;
  198. default:
  199. Assert(fFalse);
  200. goto LHUIMBError;
  201. }
  202. if ((szText = SzFindSymbolValueInSymTab("STF_MB_ICON")) == NULL)
  203. {
  204. Assert(fFalse);
  205. goto LHUIMBError;
  206. }
  207. switch (*szText)
  208. {
  209. case '1':
  210. break;
  211. case '2':
  212. wType |= MB_ICONINFORMATION;
  213. break;
  214. case '3':
  215. wType |= MB_ICONSTOP;
  216. break;
  217. case '4':
  218. wType |= MB_ICONQUESTION;
  219. break;
  220. case '5':
  221. wType |= MB_ICONEXCLAMATION;
  222. break;
  223. default:
  224. Assert(fFalse);
  225. goto LHUIMBError;
  226. }
  227. if ((szText = SzFindSymbolValueInSymTab("STF_MB_DEF")) == NULL)
  228. {
  229. Assert(fFalse);
  230. goto LHUIMBError;
  231. }
  232. switch (*szText)
  233. {
  234. case '1':
  235. break;
  236. case '2':
  237. wType |= MB_DEFBUTTON2;
  238. break;
  239. case '3':
  240. wType |= MB_DEFBUTTON3;
  241. break;
  242. default:
  243. Assert(fFalse);
  244. goto LHUIMBError;
  245. }
  246. if ((szText = SzFindSymbolValueInSymTab("STF_MB_TEXT")) == NULL)
  247. {
  248. Assert(fFalse);
  249. goto LHUIMBError;
  250. }
  251. if ((szTitle = SzFindSymbolValueInSymTab("STF_MB_TITLE")) == NULL)
  252. szTitle = "";
  253. aw = GetActiveWindow();
  254. if ( aw == NULL || aw == GetDesktopWindow() ) {
  255. aw = hwndParent;
  256. }
  257. while ((imbReturn = MessageBox(aw, szText, szTitle, wType)) == 0) {
  258. if (!FHandleOOM(hwndParent)) {
  259. goto LHUIMBError;
  260. }
  261. }
  262. switch (imbReturn)
  263. {
  264. case IDABORT:
  265. szText = "ABORT";
  266. break;
  267. case IDCANCEL:
  268. szText = "CANCEL";
  269. break;
  270. case IDIGNORE:
  271. szText = "IGNORE";
  272. break;
  273. case IDNO:
  274. szText = "NO";
  275. break;
  276. case IDOK:
  277. szText = "OK";
  278. break;
  279. case IDRETRY:
  280. szText = "RETRY";
  281. break;
  282. case IDYES:
  283. szText = "YES";
  284. break;
  285. default:
  286. Assert(fFalse);
  287. goto LHUIMBError;
  288. }
  289. while (!FAddSymbolValueToSymTab("DLGEVENT", szText))
  290. if (!FHandleOOM(hwndParent))
  291. goto LHUIMBError;
  292. fRet = fTrue;
  293. LHUIMBError:
  294. return(fRet);
  295. }
  296. /*
  297. ** Purpose:
  298. ** ??
  299. ** Arguments:
  300. ** ??
  301. ** Returns:
  302. ** ??
  303. ****************************************************************************/
  304. EHRC APIENTRY EhrcGstCheck1EventHandler(HANDLE hInst,
  305. HWND hwndShell,
  306. UINT wMsg,
  307. WPARAM wParam,
  308. LONG lParam)
  309. {
  310. SZ sz = SzFindSymbolValueInSymTab("ButtonPressed");
  311. WORD idc;
  312. INT iButton;
  313. CHP rgchNum[10];
  314. Unused(hInst);
  315. Unused(hwndShell);
  316. Unused(wMsg);
  317. Unused(wParam);
  318. Unused(lParam);
  319. Assert(sz != NULL);
  320. switch (idc = (WORD)atoi(sz))
  321. {
  322. case IDC_B1:
  323. case IDC_B2:
  324. case IDC_B3:
  325. case IDC_B4:
  326. case IDC_B5:
  327. case IDC_B6:
  328. case IDC_B7:
  329. case IDC_B8:
  330. case IDC_B9:
  331. case IDC_B10:
  332. sz = "NOTIFY";
  333. iButton = (INT) (idc - IDC_B1 + 1);
  334. break;
  335. case IDC_SP1:
  336. case IDC_SP2:
  337. case IDC_SP3:
  338. case IDC_SP4:
  339. case IDC_SP5:
  340. case IDC_SP6:
  341. case IDC_SP7:
  342. case IDC_SP8:
  343. case IDC_SP9:
  344. case IDC_SP10:
  345. sz = "CUSTOMISE";
  346. iButton = (INT) (idc - IDC_SP1 + 1);
  347. break;
  348. default:
  349. return(ehrcNotHandled);
  350. }
  351. _itoa(iButton, rgchNum, 10);
  352. if(!FAddSymbolValueToSymTab("ButtonChecked", rgchNum) ||
  353. !FAddSymbolValueToSymTab("DLGEVENT", sz))
  354. return(ehrcError);
  355. else
  356. return(ehrcPostInterp);
  357. }
  358. /*
  359. ** Purpose:
  360. ** ??
  361. ** Arguments:
  362. ** ??
  363. ** Returns:
  364. ** ??
  365. ****************************************************************************/
  366. EHRC APIENTRY EhrcGstMultiComboEventHandler(HANDLE hInst,
  367. HWND hwndShell,
  368. UINT wMsg,
  369. WPARAM wParam,
  370. LONG lParam)
  371. {
  372. SZ sz = SzFindSymbolValueInSymTab("ButtonPressed");
  373. WORD idc;
  374. INT iButton;
  375. CHP rgchNum[10];
  376. Unused(hInst);
  377. Unused(hwndShell);
  378. Unused(wMsg);
  379. Unused(wParam);
  380. Unused(lParam);
  381. Assert(sz != NULL);
  382. switch (idc = (WORD)atoi(sz))
  383. {
  384. case IDC_COMBO1:
  385. case IDC_COMBO2:
  386. case IDC_COMBO3:
  387. case IDC_COMBO4:
  388. case IDC_COMBO5:
  389. case IDC_COMBO6:
  390. case IDC_COMBO7:
  391. case IDC_COMBO8:
  392. case IDC_COMBO9:
  393. sz = "NOTIFY";
  394. iButton = (INT) (idc - IDC_COMBO1 + 1);
  395. break;
  396. default:
  397. return(ehrcNotHandled);
  398. }
  399. _itoa(iButton, rgchNum, 10);
  400. if(!FAddSymbolValueToSymTab("ButtonChecked", rgchNum) ||
  401. !FAddSymbolValueToSymTab("DLGEVENT", sz))
  402. return(ehrcError);
  403. else
  404. return(ehrcPostInterp);
  405. }
  406. /*
  407. ** Purpose:
  408. ** ??
  409. ** Arguments:
  410. ** ??
  411. ** Returns:
  412. ** ??
  413. ****************************************************************************/
  414. EHRC APIENTRY
  415. EhrcGstMaintenanceEventHandler(
  416. HANDLE hInst,
  417. HWND hwndShell,
  418. UINT wMsg,
  419. WPARAM wParam,
  420. LONG lParam
  421. )
  422. {
  423. SZ sz = SzFindSymbolValueInSymTab("ButtonPressed");
  424. WORD idc;
  425. INT iButton;
  426. CHP rgchNum[10];
  427. Unused(hInst);
  428. Unused(hwndShell);
  429. Unused(wMsg);
  430. Unused(wParam);
  431. Unused(lParam);
  432. Assert(sz != NULL);
  433. switch (idc = (WORD)atoi(sz)) {
  434. case MENU_CHANGE:
  435. sz = "SYSTEM";
  436. iButton = 1;
  437. break;
  438. default:
  439. return(ehrcNotHandled);
  440. }
  441. _itoa(iButton, rgchNum, 10);
  442. if(!FAddSymbolValueToSymTab("ButtonChecked", rgchNum) ||
  443. !FAddSymbolValueToSymTab("DLGEVENT", sz)) {
  444. return(ehrcError);
  445. }
  446. else {
  447. return(ehrcPostInterp);
  448. }
  449. }