home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / winnt / dlgedit / dialogs.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  28KB  |  901 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples. 
  4. *       Copyright (C) 1993-1997 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. /****************************** Module Header *******************************
  13. * Module Name: dialogs.c
  14. *
  15. * Contains many of the dialogs and supporting routines used by the
  16. * dialog box editor.
  17. *
  18. * Functions:
  19. *
  20. *    DlgBox()
  21. *    EnteringDialog()
  22. *    CreateTestDialog()
  23. *    DestroyTestDialog()
  24. *    SelectDialogDialog()
  25. *    ArrangeSettingsDialog()
  26. *    AboutDlgProc()
  27. *    SelectDialogDlgProc()
  28. *    SelectDialogInit()
  29. *    SelectDialogFillLangList()
  30. *    SelectDialogOK()
  31. *    TestDlgProc()
  32. *    TestInitDlg()
  33. *    ArrangeSettingsDlgProc()
  34. *
  35. * Comments:
  36. ****************************************************************************/
  37.  
  38. #include "dlgedit.h"
  39. #include "dlgfuncs.h"
  40. #include "dlgextrn.h"
  41. #include "dialogs.h"
  42. #include "dlghelp.h"
  43.  
  44.  
  45. /*
  46.  * Maximum number of characters in the Arrange Settings fields.
  47.  */
  48. #define CCHARRSETMAX    2
  49.  
  50. DIALOGPROC SelectDialogDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  51. STATICFN VOID SelectDialogInit(HWND hwnd);
  52. STATICFN VOID SelectDialogFillLangList(HWND hwnd);
  53. STATICFN BOOL SelectDialogOK(HWND hwnd);
  54. DIALOGPROC TestDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  55. STATICFN VOID TestInitDlg(HWND hwnd);
  56. DIALOGPROC ArrangeSettingsDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
  57.     LPARAM lParam);
  58.  
  59.  
  60.  
  61. /************************************************************************
  62. * DlgBox
  63. *
  64. * This function basically does a DialogBox, but it does it safely
  65. * for the dialog editor, saving some states.
  66. *
  67. * Arguments:
  68. *     INT idDlg       = Ordinal name of the dialog.
  69. *     WNDPROC lpfnDlg = Dialog procedure to use (this function will
  70. *                       call Make/FreeProcInstance).
  71. *
  72. * Returns:
  73. *     What DialogBox returned.
  74. *
  75. ************************************************************************/
  76.  
  77. INT DlgBox(
  78.     INT idDlg,
  79.     WNDPROC lpfnDlg)
  80. {
  81.     INT nResult;
  82.     INT idPrevDlg;
  83.  
  84.     EnteringDialog(idDlg, &idPrevDlg, TRUE);
  85.     nResult = DialogBox(ghInst, MAKEINTRESOURCE(idDlg), ghwndMain, (DLGPROC)lpfnDlg);
  86.     EnteringDialog(idPrevDlg, NULL, FALSE);
  87.  
  88.     return nResult;
  89. }
  90.  
  91.  
  92.  
  93. /************************************************************************
  94. * EnteringDialog
  95. *
  96. * This function enables or disables things based on whether we are
  97. * going to show one of the editor's dialogs.  It must be called
  98. * before and after showing a dialog box.
  99. *
  100. * Arguments:
  101. *   INT idDlg       - Ordinal name of the dialog.
  102. *   PINT pidPrevDlg - Points to where to save the id of the previous
  103. *                     (current) dialog.  If fEntering is FALSE, this
  104. *                     is not used and should be NULL.
  105. *   BOOL fEntering  - TRUE if about ready to show the dialog.  FALSE if
  106. *                     the dialog was just dismissed.  For the FALSE case,
  107. *                     the idDlg should be zero, or the id of the previous
  108. *                     dialog.
  109. *
  110. ************************************************************************/
  111.  
  112. VOID EnteringDialog(
  113.     INT idDlg,
  114.     PINT pidPrevDlg,
  115.     BOOL fEntering)
  116. {
  117.     /*
  118.      * If we are entering a new dialog, save the previous dialog
  119.      * in the place specified.
  120.      */
  121.     if (fEntering)
  122.         *pidPrevDlg = gidCurrentDlg;
  123.  
  124.     gfDisabled = fEntering;
  125.     gidCurrentDlg = idDlg;
  126.     StatusSetEnable();
  127.  
  128.     if (ghwndToolbox)
  129.         EnableWindow(ghwndToolbox, !fEntering);
  130. }
  131.  
  132.  
  133.  
  134. /************************************************************************
  135. * SelectDialogDialog
  136. *
  137. * This function saves the current dialog box in the resource in
  138. * memory, then it puts up a dialog box with a list of dialog
  139. * boxes in the resource.  Finally it puts up the selected dialog.
  140. *
  141. ************************************************************************/
  142.  
  143. VOID SelectDialogDialog(VOID)
  144. {
  145.     if (!SynchDialogResource())
  146.         return;
  147.  
  148.     DlgBox(DID_SELECTDIALOG, (WNDPROC)SelectDialogDlgProc);
  149. }
  150.  
  151.  
  152.  
  153. /************************************************************************
  154. * SelectDialogDlgProc
  155. *
  156. * This is the View Dialog dialog procedure.
  157. *
  158. * Arguments:
  159. *    HWND - handle to the dialog
  160. *    UINT - window message
  161. *    WPARAM - message parameter 
  162. *    LPARAM - message parameter
  163. *
  164. * Returns:
  165. *    Default dialog return.
  166. *
  167. ************************************************************************/
  168.  
  169. DIALOGPROC SelectDialogDlgProc(
  170.     HWND hwnd,
  171.     UINT msg,
  172.     WPARAM wParam,
  173.     LPARAM lParam)
  174. {
  175.     switch (msg) {
  176.         case WM_INITDIALOG:
  177.             SelectDialogInit(hwnd);
  178.             return TRUE;
  179.  
  180.         case WM_COMMAND:
  181.             switch (LOWORD(wParam)) {
  182.                 case DID_SELECTDIALOGNAMELIST:
  183.                     switch (HIWORD(wParam)) {
  184.                         case LBN_SELCHANGE:
  185.                             SelectDialogFillLangList(hwnd);
  186.                             break;
  187.  
  188.                         case LBN_DBLCLK:
  189.                             if (SelectDialogOK(hwnd))
  190.                                 EndDialog(hwnd, IDOK);
  191.  
  192.                             break;
  193.                     }
  194.  
  195.                     break;
  196.  
  197.                 case DID_SELECTDIALOGLANGLIST:
  198.                     switch (HIWORD(wParam)) {
  199.                         case LBN_DBLCLK:
  200.                             if (SelectDialogOK(hwnd))
  201.                                 EndDialog(hwnd, IDOK);
  202.  
  203.                             break;
  204.                     }
  205.  
  206.                     break;
  207.  
  208.                 case IDOK:
  209.                     if (SelectDialogOK(hwnd))
  210.                         EndDialog(hwnd, IDOK);
  211.  
  212.                     break;
  213.  
  214.                 case IDCANCEL:
  215.                     EndDialog(hwnd, IDCANCEL);
  216.                     break;
  217.  
  218.                 case IDHELPDLG:
  219.                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
  220.                             HELPID_SELECTDIALOG);
  221.                     break;
  222.             }
  223.  
  224.             return TRUE;
  225.  
  226.         default:
  227.             return FALSE;
  228.     }
  229. }
  230.  
  231.  
  232.  
  233. /************************************************************************
  234. * SelectDialogInit
  235. *
  236. * Processes the WM_INITDIALOG message for the Select Dialog dialog
  237. * procedure.
  238. *
  239. * This function fills the select dialog listbox with the names or
  240. * numbers of all the dialogs in the resource list.  If the dialog has
  241. * a name, that is used.  If it just has an ordinal, then the decimal
  242. * ascii string for the ordinal number is used.
  243. *
  244. * Arguments:
  245. *    HWND - handle to the dialog
  246. *
  247. ************************************************************************/
  248.  
  249. STATICFN VOID SelectDialogInit(
  250.     HWND hwnd)
  251. {
  252.     HWND hwndNameLB;
  253.     TCHAR szName[CCHTEXTMAX];
  254.     INT i;
  255.     INT cDlgsAdded;
  256.     INT iSelect;
  257.     PRESLINK prl;
  258.     PRESLINK prl2;
  259.     LPTSTR pszName;
  260.     NPLABEL npLabel;
  261.  
  262.     hwndNameLB = GetDlgItem(hwnd, DID_SELECTDIALOGNAMELIST);
  263.     cDlgsAdded = 0;
  264.  
  265.     /*
  266.      * Insert each dialog found in the resource.
  267.      */
  268.     for (prl = gprlHead; prl; prl = prl->prlNext) {
  269.         if (prl->fDlgResource) {
  270.             /*
  271.              * Check to be sure we have not added a dialog with this
  272.              * name already (but perhaps a different language).
  273.              */
  274.             for (prl2 = gprlHead; prl2 != prl; prl2 = prl2->prlNext) {
  275.                 if (prl2->fDlgResource) {
  276.                     if (NameOrdCmp(prl2->pszName, prl->pszName) == 0)
  277.                         break;
  278.                 }
  279.             }
  280.  
  281.             if (prl2 == prl) {
  282.                 /*
  283.                  * If the name is an ordinal, display a number.  If there
  284.                  * happens to be a define for this number, display that
  285.                  * instead, however.
  286.                  *
  287.                  * Note that we do not ever show it in hex, because
  288.                  * rc.exe does not parse hex ordinals for dialogs, so
  289.                  * we never show it in that format.
  290.                  */
  291.                 if (IsOrd(prl->pszName)) {
  292.                     if (npLabel = FindID(OrdID(prl->pszName), plInclude))
  293.                         pszName = npLabel->pszLabel;
  294.                     else
  295.                         pszName = itoaw(OrdID(prl->pszName), szName, 10);
  296.                 }
  297.                 else {
  298.                     pszName = prl->pszName;
  299.                 }
  300.  
  301.                 i = (INT)SendMessage(hwndNameLB, LB_ADDSTRING, 0, (DWORD)pszName);
  302.                 SendMessage(hwndNameLB, LB_SETITEMDATA, i, (DWORD)prl);
  303.                 cDlgsAdded++;
  304.             }
  305.         }
  306.     }
  307.  
  308.     /*
  309.      * If there is a current dialog, search for it and
  310.      * make it the default selected item.
  311.      */
  312.     iSelect = 0;
  313.     if (gcd.prl) {
  314.         for (i = 0; i < cDlgsAdded; i++) {
  315.             prl = (PRESLINK)SendMessage(hwndNameLB, LB_GETITEMDATA, i, 0L);
  316.             if (NameOrdCmp(prl->pszName, gcd.prl->pszName) == 0) {
  317.                 iSelect = i;
  318.                 break;
  319.             }
  320.         }
  321.     }
  322.  
  323.     SendMessage(hwndNameLB, LB_SETCURSEL, iSelect, 0L);
  324.  
  325.     SelectDialogFillLangList(hwnd);
  326.  
  327.     CenterWindow(hwnd);
  328. }
  329.  
  330.  
  331.  
  332. /************************************************************************
  333. * SelectDialogFillLangList
  334. *
  335. * Fills the listbox with the list of dialogs matching the specified name
  336. *
  337. * Arguments:
  338. *    HWND - handle to the dialog editor window
  339. *
  340. ************************************************************************/
  341.  
  342. STATICFN VOID SelectDialogFillLangList(
  343.     HWND hwnd)
  344. {
  345.     TCHAR szLang[CCHTEXTMAX];
  346.     HWND hwndNameLB;
  347.     HWND hwndLangLB;
  348.     PRESLINK prl;
  349.     INT i;
  350.     INT iSelect;
  351.     WORD wPrimary;
  352.     WORD wSubLang;
  353.     INT iLang;
  354.     INT iSubLang;
  355.     LPTSTR pszName;
  356.     INT cItems;
  357.  
  358.     hwndNameLB = GetDlgItem(hwnd, DID_SELECTDIALOGNAMELIST);
  359.     hwndLangLB = GetDlgItem(hwnd, DID_SELECTDIALOGLANGLIST);
  360.  
  361.     SendMessage(hwndLangLB, LB_RESETCONTENT, 0, 0);
  362.  
  363.     if ((iSelect = (INT)SendMessage(hwndNameLB, LB_GETCURSEL, 0, 0)) == LB_ERR)
  364.         return;
  365.  
  366.     /*
  367.      * Get the name of the dialog selected in the Name listbox
  368.      * (the reslink pointer is stored in the listbox items data field).
  369.      */
  370.     prl = (PRESLINK)SendMessage(hwndNameLB, LB_GETITEMDATA, iSelect, 0L);
  371.     pszName = prl->pszName;
  372.  
  373.     /*
  374.      * Insert each dialog found in the resource that matches that name.
  375.      */
  376.     for (prl = gprlHead; prl; prl = prl->prlNext) {
  377.         if (prl->fDlgResource && NameOrdCmp(prl->pszName, pszName) == 0) {
  378.             wPrimary = (WORD)PRIMARYLANGID(prl->wLanguage);
  379.             for (iLang = 0; iLang < gcLanguages; iLang++) {
  380.                 if (gaLangTable[iLang].wPrimary == wPrimary) {
  381.                     break;
  382.                 }
  383.             }
  384.  
  385.             wSubLang = SUBLANGID(prl->wLanguage);
  386.             for (iSubLang = 0;
  387.                     iSubLang < gaLangTable[iLang].cSubLangs;
  388.                     iSubLang++) {
  389.                 if (wSubLang == gaLangTable[iLang].asl[iSubLang].wSubLang) {
  390.                     break;
  391.                 }
  392.             }
  393.  
  394.             wsprintf(szLang, L"%s, %s",
  395.                     ids(gaLangTable[iLang].idsLangDesc),
  396.                     ids(gaLangTable[iLang].asl[iSubLang].idsSubLangDesc));
  397.  
  398.             i = (INT)SendMessage(hwndLangLB, LB_ADDSTRING, 0, (DWORD)szLang);
  399.             SendMessage(hwndLangLB, LB_SETITEMDATA, i, (DWORD)prl);
  400.         }
  401.     }
  402.  
  403.     iSelect = 0;
  404.     cItems = (INT)SendMessage(hwndLangLB, LB_GETCOUNT, 0, 0);
  405.     if (gcd.prl && NameOrdCmp(gcd.prl->pszName, pszName) == 0) {
  406.         for (i = 0; i < cItems; i++) {
  407.             prl = (PRESLINK)SendMessage(hwndLangLB, LB_GETITEMDATA, i, 0);
  408.             if (gcd.prl == prl) {
  409.                 iSelect = i;
  410.                 break;
  411.             }
  412.         }
  413.     }
  414.  
  415.     SendMessage(hwndLangLB, LB_SETCURSEL, iSelect, 0L);
  416. }
  417.  
  418.  
  419.  
  420. /************************************************************************
  421. * SelectDialogOK
  422. *
  423. * Processes the selection of a new dialog from the Select Dialog
  424. * dialog procedure.
  425. *
  426. * Arguments:
  427. *    HWND - handle to the select dialog box
  428. *
  429. * Returns:
  430. *    TRUE 
  431. *
  432. ************************************************************************/
  433.  
  434. STATICFN BOOL SelectDialogOK(
  435.     HWND hwnd)
  436. {
  437.     HWND hwndLangLB;
  438.     INT iSelect;
  439.     PRESLINK prl;
  440.  
  441.     hwndLangLB = GetDlgItem(hwnd, DID_SELECTDIALOGLANGLIST);
  442.  
  443.     if ((iSelect = (INT)SendMessage(hwndLangLB, LB_GETCURSEL, 0, 0)) !=
  444.             LB_ERR) {
  445.         /*
  446.          * Get a pointer to the selected dialog (stored in the listbox
  447.          * items data field).
  448.          */
  449.         prl = (PRESLINK)SendMessage(hwndLangLB, LB_GETITEMDATA, iSelect, 0L);
  450.  
  451.         /*
  452.          * Is there a dialog currently being edited?
  453.          */
  454.         if (gfEditingDlg) {
  455.             /*
  456.              * If they chose the same dialog as what they are currently
  457.              * editing, just get out without doing anything more.
  458.              * Otherwise, delete the current dialog because we are
  459.              * now committed to loading a new one.
  460.              */
  461.             if (prl == gcd.prl)
  462.                 return TRUE;
  463.             else
  464.                 DeleteDialog(FALSE);
  465.         }
  466.  
  467.         /*
  468.          * Finally, load the new dialog (make it current).
  469.          */
  470.         ResLinkToDialog(prl);
  471.  
  472.         /*
  473.          * Select the new dialog, if it was successfully created.
  474.          */
  475.         if (gfEditingDlg)
  476.             SelectControl(gcd.npc, FALSE);
  477.     }
  478.  
  479.     return TRUE;
  480. }
  481.  
  482.  
  483.  
  484. /************************************************************************
  485. * CreateTestDialog
  486. *
  487. * Creates a dialog for the test mode of the dialog editor
  488. *
  489. ************************************************************************/
  490.  
  491. VOID CreateTestDialog(VOID)
  492. {
  493.     PRES pRes;
  494.     PDIALOGBOXHEADER pdbh;
  495.  
  496.     if (!gfEditingDlg)
  497.         return;
  498.  
  499.     CancelSelection(TRUE);
  500.  
  501.     /*
  502.      * Save the current dialog in the resource buffer.
  503.      */
  504.     if (!SynchDialogResource())
  505.         return;
  506.  
  507.     /*
  508.      * Make a memory copy of the current dialog resource for test mode.
  509.      */
  510.     if (!(pRes = AllocDialogResource(TRUE, FALSE)))
  511.         return;
  512.  
  513.     pdbh = (PDIALOGBOXHEADER)SkipResHeader(pRes);
  514.  
  515.     /*
  516.      * Create the test dialog in a modeless loop using the test dialog proc.
  517.      */
  518.     ghwndTestDlg = CreateDialogIndirect(ghInst, (LPDLGTEMPLATE)pdbh,
  519.             ghwndSubClient, TestDlgProc);
  520.  
  521.     if (ghwndTestDlg) {
  522.         gfTestMode = TRUE;
  523.  
  524.         /*
  525.          * Disable various top level menus.
  526.          */
  527.         MyEnableMenuItemByPos(ghMenuMain, MENUPOS_FILE, FALSE);
  528.         MyEnableMenuItemByPos(ghMenuMain, MENUPOS_EDIT, FALSE);
  529.         MyEnableMenuItemByPos(ghMenuMain, MENUPOS_ARRANGE, FALSE);
  530.         DrawMenuBar(ghwndMain);
  531.  
  532.         ToolboxSelectTool(W_NOTHING, FALSE);
  533.         if (gfShowToolbox)
  534.             ToolboxShow(FALSE);
  535.  
  536.         StatusSetEnable();
  537.  
  538.         /*
  539.          * Remove the work mode dialog from view (actually, it is now
  540.          * hidden behind the test dialog, but we hide it in case the
  541.          * user moves the test dialog.
  542.          */
  543.         ShowWindow(gcd.npc->hwnd, SW_HIDE);
  544.     }
  545. }
  546.  
  547.  
  548.  
  549. /************************************************************************
  550. * TestDlgProc
  551. *
  552. * This is the dialog procedure for the dialog in Test mode.
  553. *
  554. ************************************************************************/
  555.  
  556. DIALOGPROC TestDlgProc(
  557.     HWND hwnd,
  558.     UINT msg,
  559.     WPARAM wParam,
  560.     LPARAM lParam)
  561. {
  562.     switch (msg) {
  563.         case WM_INITDIALOG:
  564.             TestInitDlg(hwnd);
  565.             return TRUE;
  566.  
  567.         case WM_SYSCOMMAND:
  568.             if (wParam == SC_CLOSE) {
  569.                 DestroyTestDialog();
  570.                 return TRUE;
  571.             }
  572.  
  573.             return FALSE;
  574.  
  575.         case WM_DRAWITEM:
  576.             return DrawOwnerDrawButton((LPDRAWITEMSTRUCT)lParam);
  577.  
  578.         case WM_DESTROY:
  579.             gfTestMode = FALSE;
  580.  
  581.             ShowWindow(gcd.npc->hwnd, SW_SHOWNA);
  582.  
  583.             /*
  584.              * Enable various top level menus.
  585.              */
  586.             MyEnableMenuItemByPos(ghMenuMain, MENUPOS_FILE, TRUE);
  587.             MyEnableMenuItemByPos(ghMenuMain, MENUPOS_EDIT, TRUE);
  588.             MyEnableMenuItemByPos(ghMenuMain, MENUPOS_ARRANGE, TRUE);
  589.             DrawMenuBar(ghwndMain);
  590.  
  591.             if (gfShowToolbox)
  592.                 ToolboxShow(TRUE);
  593.  
  594.             StatusSetEnable();
  595.  
  596.             return TRUE;
  597.  
  598.         default:
  599.             return FALSE;
  600.     }
  601. }
  602.  
  603.  
  604.  
  605. /************************************************************************
  606. * TestInitDlg
  607. *
  608. * This function handles the initialization of the test dialog.
  609. *
  610. * Arguments:
  611. *     HWND hwnd = The test dialog window handle.
  612. *
  613. ************************************************************************/
  614.  
  615. STATICFN VOID TestInitDlg(
  616.     HWND hwnd)
  617. {
  618.     register INT i;
  619.     TCHAR szBuf[CCHTEXTMAX];
  620.     HWND hwndCtrl;
  621.     LPTSTR pszTextEnd;
  622.     TCHAR szClass[32];
  623.     INT iClass;
  624.  
  625.     /*
  626.      * The following will fill some controls with sample text lines.
  627.      */
  628.     lstrcpy(szBuf, ids(IDS_DEFLBTEXT));
  629.     pszTextEnd = szBuf + lstrlen(szBuf);
  630.     hwndCtrl = GetWindow(hwnd, GW_CHILD);
  631.     while (hwndCtrl) {
  632.         GetClassName(hwndCtrl, szClass, sizeof(szClass));
  633.  
  634.         switch (iClass = GetiClass(szClass)) {
  635.             case IC_LISTBOX:
  636.             case IC_COMBOBOX:
  637.                 /*
  638.                  * Fill listboxes and comboboxes with some sample lines.
  639.                  */
  640.                 for (i = 1; i <= CLBTESTLINES; i++) {
  641.                     itoaw(i, pszTextEnd, 10);
  642.                     SendMessage(hwndCtrl,
  643.                             (WORD)((iClass == IC_LISTBOX) ?
  644.                             LB_INSERTSTRING : CB_INSERTSTRING),
  645.                             (WPARAM)-1, (DWORD)szBuf);
  646.                 }
  647.  
  648.                 break;
  649.         }
  650.  
  651.         hwndCtrl = GetWindow(hwndCtrl, GW_HWNDNEXT);
  652.     }
  653. }
  654.  
  655.  
  656.  
  657. /************************************************************************
  658. * DestroyTestDialog
  659. *
  660. * Destroys the test dialog window.
  661. ************************************************************************/
  662.  
  663. VOID DestroyTestDialog(VOID)
  664. {
  665.     DestroyWindow(ghwndTestDlg);
  666.     ghwndTestDlg = NULL;
  667. }
  668.  
  669.  
  670.  
  671. /************************************************************************
  672. * ArrangeSettingsDialog
  673. *
  674. * This function displays the Arrange Settings dialog box.
  675. *
  676. ************************************************************************/
  677.  
  678. VOID ArrangeSettingsDialog(VOID)
  679. {
  680.     DlgBox(DID_ARRSETTINGS, (WNDPROC)ArrangeSettingsDlgProc);
  681. }
  682.  
  683.  
  684.  
  685. /************************************************************************
  686. * ArrangeSettingsDlgProc
  687. *
  688. * This is the Arrange Settings dialog procedure.
  689. *
  690. ************************************************************************/
  691.  
  692. DIALOGPROC ArrangeSettingsDlgProc(
  693.     HWND hwnd,
  694.     UINT msg,
  695.     WPARAM wParam,
  696.     LPARAM lParam)
  697. {
  698.     switch (msg) {
  699.         case WM_INITDIALOG:
  700.             SendDlgItemMessage(hwnd, DID_ARRSETCXGRID, EM_LIMITTEXT,
  701.                     CCHARRSETMAX, 0L);
  702.             SendDlgItemMessage(hwnd, DID_ARRSETCYGRID, EM_LIMITTEXT,
  703.                     CCHARRSETMAX, 0L);
  704.             SetDlgItemInt(hwnd, DID_ARRSETCXGRID, gcxGrid, TRUE);
  705.             SetDlgItemInt(hwnd, DID_ARRSETCYGRID, gcyGrid, TRUE);
  706.  
  707.             SendDlgItemMessage(hwnd, DID_ARRSETXMARGIN, EM_LIMITTEXT,
  708.                     CCHARRSETMAX, 0L);
  709.             SendDlgItemMessage(hwnd, DID_ARRSETYMARGIN, EM_LIMITTEXT,
  710.                     CCHARRSETMAX, 0L);
  711.             SetDlgItemInt(hwnd, DID_ARRSETXMARGIN, gxMargin, TRUE);
  712.             SetDlgItemInt(hwnd, DID_ARRSETYMARGIN, gyMargin, TRUE);
  713.  
  714.             SendDlgItemMessage(hwnd, DID_ARRSETXSPACE, EM_LIMITTEXT,
  715.                     CCHARRSETMAX, 0L);
  716.             SendDlgItemMessage(hwnd, DID_ARRSETYSPACE, EM_LIMITTEXT,
  717.                     CCHARRSETMAX, 0L);
  718.             SetDlgItemInt(hwnd, DID_ARRSETXSPACE, gxSpace, TRUE);
  719.             SetDlgItemInt(hwnd, DID_ARRSETYSPACE, gySpace, TRUE);
  720.  
  721.             SendDlgItemMessage(hwnd, DID_ARRSETXMINPUSHSPACE, EM_LIMITTEXT,
  722.                     CCHARRSETMAX, 0L);
  723.             SendDlgItemMessage(hwnd, DID_ARRSETXMAXPUSHSPACE, EM_LIMITTEXT,
  724.                     CCHARRSETMAX, 0L);
  725.             SendDlgItemMessage(hwnd, DID_ARRSETYPUSHSPACE, EM_LIMITTEXT,
  726.                     CCHARRSETMAX, 0L);
  727.             SetDlgItemInt(hwnd, DID_ARRSETXMINPUSHSPACE, gxMinPushSpace, TRUE);
  728.             SetDlgItemInt(hwnd, DID_ARRSETXMAXPUSHSPACE, gxMaxPushSpace, TRUE);
  729.             SetDlgItemInt(hwnd, DID_ARRSETYPUSHSPACE, gyPushSpace, TRUE);
  730.  
  731.             CenterWindow(hwnd);
  732.  
  733.             return TRUE;
  734.  
  735.         case WM_COMMAND:
  736.             switch (LOWORD(wParam)) {
  737.                 INT cxGridNew;
  738.                 INT cyGridNew;
  739.                 INT xMarginNew;
  740.                 INT yMarginNew;
  741.                 INT xSpaceNew;
  742.                 INT ySpaceNew;
  743.                 INT xMinPushSpaceNew;
  744.                 INT xMaxPushSpaceNew;
  745.                 INT yPushSpaceNew;
  746.                 BOOL fTranslated1;
  747.                 BOOL fTranslated2;
  748.                 BOOL fTranslated3;
  749.  
  750.                 case IDOK:
  751.                     cxGridNew = GetDlgItemInt(hwnd, DID_ARRSETCXGRID,
  752.                             &fTranslated1, TRUE);
  753.                     cyGridNew = GetDlgItemInt(hwnd, DID_ARRSETCYGRID,
  754.                             &fTranslated2, TRUE);
  755.  
  756.                     if (!fTranslated1 || !fTranslated2 ||
  757.                             cxGridNew <= 0 || cyGridNew <= 0) {
  758.                         Message(MSG_GTZERO, ids(IDS_GRID));
  759.                         SetFocus(GetDlgItem(hwnd, DID_ARRSETCXGRID));
  760.                         break;
  761.                     }
  762.  
  763.                     xMarginNew = GetDlgItemInt(hwnd, DID_ARRSETXMARGIN,
  764.                             &fTranslated1, TRUE);
  765.                     yMarginNew = GetDlgItemInt(hwnd, DID_ARRSETYMARGIN,
  766.                             &fTranslated2, TRUE);
  767.  
  768.                     if (!fTranslated1 || !fTranslated2 ||
  769.                             xMarginNew < 0 || yMarginNew < 0) {
  770.                         Message(MSG_POSITIVENUM, ids(IDS_MARGIN));
  771.                         SetFocus(GetDlgItem(hwnd, DID_ARRSETXMARGIN));
  772.                         break;
  773.                     }
  774.  
  775.                     xSpaceNew = GetDlgItemInt(hwnd, DID_ARRSETXSPACE,
  776.                             &fTranslated1, TRUE);
  777.                     ySpaceNew = GetDlgItemInt(hwnd, DID_ARRSETYSPACE,
  778.                             &fTranslated2, TRUE);
  779.  
  780.                     if (!fTranslated1 || !fTranslated2 ||
  781.                             xSpaceNew < 0 || ySpaceNew < 0) {
  782.                         Message(MSG_POSITIVENUM, ids(IDS_CTRLSPACING));
  783.                         SetFocus(GetDlgItem(hwnd, DID_ARRSETXSPACE));
  784.                         break;
  785.                     }
  786.  
  787.                     xMinPushSpaceNew = GetDlgItemInt(hwnd,
  788.                             DID_ARRSETXMINPUSHSPACE, &fTranslated1, TRUE);
  789.                     xMaxPushSpaceNew = GetDlgItemInt(hwnd,
  790.                             DID_ARRSETXMAXPUSHSPACE, &fTranslated2, TRUE);
  791.                     yPushSpaceNew = GetDlgItemInt(hwnd, DID_ARRSETYPUSHSPACE,
  792.                             &fTranslated3, TRUE);
  793.  
  794.                     if (!fTranslated1 || !fTranslated2 || !fTranslated3 ||
  795.                             xMinPushSpaceNew < 0 || xMaxPushSpaceNew < 0 ||
  796.                             yPushSpaceNew < 0) {
  797.                         Message(MSG_POSITIVENUM, ids(IDS_PUSHSPACING));
  798.                         SetFocus(GetDlgItem(hwnd, DID_ARRSETXMINPUSHSPACE));
  799.                         break;
  800.                     }
  801.  
  802.                     if (xMinPushSpaceNew > xMaxPushSpaceNew) {
  803.                         Message(MSG_MINGTMAXSPACE);
  804.                         SetFocus(GetDlgItem(hwnd, DID_ARRSETXMINPUSHSPACE));
  805.                         break;
  806.                     }
  807.  
  808.                     gcxGrid = cxGridNew;
  809.                     gcyGrid = cyGridNew;
  810.                     gxMargin = xMarginNew;
  811.                     gyMargin = yMarginNew;
  812.                     gxSpace = xSpaceNew;
  813.                     gySpace = ySpaceNew;
  814.                     gxMinPushSpace = xMinPushSpaceNew;
  815.                     gxMaxPushSpace = xMaxPushSpaceNew;
  816.                     gyPushSpace = yPushSpaceNew;
  817.  
  818.                     EndDialog(hwnd, LOWORD(wParam));
  819.                     break;
  820.  
  821.                 case DID_ARRSETDEFAULTS:
  822.                     SetDlgItemInt(hwnd, DID_ARRSETCXGRID,
  823.                             DEFCXGRID, TRUE);
  824.                     SetDlgItemInt(hwnd, DID_ARRSETCYGRID,
  825.                             DEFCYGRID, TRUE);
  826.  
  827.                     SetDlgItemInt(hwnd, DID_ARRSETXMARGIN,
  828.                             DEFXMARGIN, TRUE);
  829.                     SetDlgItemInt(hwnd, DID_ARRSETYMARGIN,
  830.                             DEFYMARGIN, TRUE);
  831.  
  832.                     SetDlgItemInt(hwnd, DID_ARRSETXSPACE,
  833.                             DEFXSPACE, TRUE);
  834.                     SetDlgItemInt(hwnd, DID_ARRSETYSPACE,
  835.                             DEFYSPACE, TRUE);
  836.  
  837.                     SetDlgItemInt(hwnd, DID_ARRSETXMINPUSHSPACE,
  838.                             DEFXMINPUSHSPACE, TRUE);
  839.                     SetDlgItemInt(hwnd, DID_ARRSETXMAXPUSHSPACE,
  840.                             DEFXMAXPUSHSPACE, TRUE);
  841.                     SetDlgItemInt(hwnd, DID_ARRSETYPUSHSPACE,
  842.                             DEFYPUSHSPACE, TRUE);
  843.  
  844.                     break;
  845.  
  846.                 case IDCANCEL:
  847.                     EndDialog(hwnd, IDCANCEL);
  848.                     break;
  849.  
  850.                 case IDHELPDLG:
  851.                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
  852.                             HELPID_ARRSETTINGS);
  853.                     break;
  854.             }
  855.  
  856.             return TRUE;
  857.  
  858.         default:
  859.             return FALSE;
  860.     }
  861. }
  862.  
  863.  
  864.  
  865. /************************************************************************
  866. * AboutDlgProc
  867. *
  868. * This is the About Box dialog procedure.
  869. *
  870. ************************************************************************/
  871.  
  872. DIALOGPROC AboutDlgProc(
  873.     HWND hwnd,
  874.     UINT msg,
  875.     WPARAM wParam,
  876.     LPARAM lParam)
  877. {
  878.     switch (msg) {
  879.         case WM_INITDIALOG:
  880.             {
  881.                 TCHAR szVersion[CCHTEXTMAX];
  882.  
  883.                 lstrcpy(szVersion, ids(IDS_APPVERSION));
  884.                 lstrcat(szVersion, ids(IDS_APPVERSIONMINOR));
  885.  
  886.                 SetDlgItemText(hwnd, DID_ABOUTVERSION, szVersion);
  887.                 CenterWindow(hwnd);
  888.             }
  889.  
  890.             return TRUE;
  891.  
  892.         case WM_COMMAND:
  893.             EndDialog(hwnd, IDOK);
  894.             return TRUE;
  895.  
  896.         default:
  897.             return FALSE;
  898.     }
  899. }
  900.