STYLES.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:57k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /******************************************************************************
  2. *       This is a part of the Microsoft Source Code Samples. 
  3. *       Copyright (C) 1993-1997 Microsoft Corporation.
  4. *       All rights reserved. 
  5. *       This source code is only intended as a supplement to 
  6. *       Microsoft Development Tools and/or WinHelp documentation.
  7. *       See these sources for detailed information regarding the 
  8. *       Microsoft samples programs.
  9. ******************************************************************************/
  10. /****************************** Module Header *******************************
  11. * Module Name: styles.c
  12. *
  13. * Handles the control styles selection, including the styles dialogs.
  14. *
  15. * Functions:
  16. *
  17. *    StylesDialog()
  18. *    GenericStylesDlgProc()
  19. *    CheckBoxStylesDlgProc()
  20. *    RadioButtonStylesDlgProc()
  21. *    PushButtonStylesDlgProc()
  22. *    ComboBoxStylesDlgProc()
  23. *    EditStylesDlgProc()
  24. *    ListBoxStylesDlgProc()
  25. *    CustomStylesDlgProc()
  26. *    DialogStylesDlgProc()
  27. *    FontNameEnumFunc()
  28. *    PointSizeEnumFunc()
  29. *    EnableComboBoxStyles()
  30. *    EnableEditStyles()
  31. *    EnableListBoxStyles()
  32. *    SetCustomStylesField()
  33. *    GetCustomStylesField()
  34. *    EnableDialogStyles()
  35. *    FillFontNameCombo()
  36. *    FillPointSizeCombo()
  37. *    AddToPointSizeCombo()
  38. *    FillLanguageCombo()
  39. *    FillSubLanguageCombo()
  40. *    CheckStyleBoxes()
  41. *    QueryCheckedStyles()
  42. *    StylesHelp()
  43. *
  44. * Comments:
  45. *
  46. ****************************************************************************/
  47. #include "dlgedit.h"
  48. #include "dlgfuncs.h"
  49. #include "dlgextrn.h"
  50. #include "dialogs.h"
  51. STATICFN VOID EnableComboBoxStyles(HWND hwnd, INT idCtrl);
  52. STATICFN VOID EnableEditStyles(HWND hwnd, INT idCtrl);
  53. STATICFN VOID EnableListBoxStyles(HWND hwnd, INT idCtrl);
  54. STATICFN VOID SetCustomStylesField(HWND hwnd, DWORD flStyle);
  55. STATICFN DWORD GetCustomStylesField(HWND hwnd);
  56. STATICFN VOID EnableDialogStyles(HWND hwnd, INT idCtrl);
  57. STATICFN VOID FillFontNameCombo(HWND hwndDlg);
  58. STATICFN VOID FillPointSizeCombo(HWND hwndDlg, LPTSTR pszFaceName);
  59. STATICFN VOID AddToPointSizeCombo(HWND hwndCombo, INT nPointSize);
  60. STATICFN VOID FillLanguageCombo(HWND hwndDlg);
  61. STATICFN VOID FillSubLanguageCombo(HWND hwndDlg, INT iLang);
  62. STATICFN VOID CheckStyleBoxes(HWND hwnd, INT iClass, DWORD flStyle);
  63. STATICFN VOID QueryCheckedStyles(HWND hwnd, INT iClass, DWORD *pflStyle);
  64. STATICFN VOID StylesHelp(VOID);
  65. /*
  66.  * Global pointer to the CTYPE for the control or dialog whose styles
  67.  * are being worked on.  All the styles dialog procs and workers use
  68.  * this pointer.
  69.  */
  70. static NPCTYPE npcStyles;
  71. /*
  72.  * Globals that receive the new styles the user selected.
  73.  */
  74. static DWORD flStyleNew;
  75. static DWORD flExtStyleNew;
  76. static LPTSTR pszTextNew;
  77. static DIALOGINFO diNew;
  78. /************************************************************************
  79. * StylesDialog
  80. *
  81. * Displays the appropriate styles dialog for the currently selected
  82. * control.  If the user OK's the changes, this function sets the
  83. * style of the control.
  84. *
  85. ************************************************************************/
  86. VOID StylesDialog(VOID)
  87. {
  88.     NPCTYPE npc;
  89.     HWND hwndOld;
  90.     INT fDlgResult;
  91.     BOOL fChanged = FALSE;
  92.     BOOL fFontChanged = FALSE;
  93.     TCHAR szClassNew[CCHTEXTMAX];
  94.     TCHAR szMenuNew[CCHTEXTMAX];
  95.     TCHAR szTextNew[CCHTEXTMAX];
  96.     /*
  97.      * Quit if nothing was selected, or if we are in translate mode.
  98.      */
  99.     if (!gnpcSel || gfTranslateMode)
  100.         return;
  101.     /*
  102.      * Set globals that the styles dialogs and worker routines will use.
  103.      */
  104.     npcStyles = gnpcSel;
  105.     flStyleNew = npcStyles->flStyle;
  106.     flExtStyleNew = npcStyles->flExtStyle;
  107.     if (npcStyles->text)
  108.         NameOrdCpy(szTextNew, npcStyles->text);
  109.     else
  110.         *szTextNew = CHAR_NULL;
  111.     pszTextNew = szTextNew;
  112.     /*
  113.      * Set some other globals if this is the dialog instead of a control.
  114.      */
  115.     if (gfDlgSelected) {
  116.         diNew.fResFlags = gcd.di.fResFlags;
  117.         diNew.wLanguage = gcd.di.wLanguage;
  118.         diNew.DataVersion = gcd.di.DataVersion;
  119.         diNew.Version = gcd.di.Version;
  120.         diNew.Characteristics = gcd.di.Characteristics;
  121.         lstrcpy(diNew.szFontName, gcd.di.szFontName);
  122.         diNew.nPointSize = gcd.di.nPointSize;
  123.         diNew.pszClass = szClassNew;
  124.         if (gcd.di.pszClass)
  125.             NameOrdCpy(szClassNew, gcd.di.pszClass);
  126.         else
  127.             *szClassNew = CHAR_NULL;
  128.         diNew.pszMenu = szMenuNew;
  129.         if (gcd.di.pszMenu)
  130.             NameOrdCpy(szMenuNew, gcd.di.pszMenu);
  131.         else
  132.             *szMenuNew = CHAR_NULL;
  133.     }
  134.     /*
  135.      * Is this a custom control that has a styles proc to use?
  136.      */
  137.     if (npcStyles->pwcd->iType == W_CUSTOM && npcStyles->pwcd->lpfnStyle) {
  138.         fDlgResult = CallCustomStyle(npcStyles, &flStyleNew, &flExtStyleNew,
  139.             szTextNew);
  140.     }
  141.     else {
  142.         /*
  143.          * Show the appropriate styles dialog.
  144.          */
  145.         fDlgResult = DlgBox(npcStyles->pwcd->idStylesDialog,
  146.                 (WNDPROC)npcStyles->pwcd->pfnStylesDlgProc);
  147.     }
  148.     if (fDlgResult == IDOK) {
  149.         /*
  150.          * Now go through and determine if anything was really changed.
  151.          */
  152.         if (npcStyles->flStyle != flStyleNew ||
  153.                 npcStyles->flExtStyle != flExtStyleNew ||
  154.                 NameOrdCmp(npcStyles->text ?
  155.                 npcStyles->text : szEmpty, szTextNew) != 0)
  156.             fChanged = TRUE;
  157.         /*
  158.          * If this is the dialog, check if some other things were changed.
  159.          */
  160.         if (gfDlgSelected) {
  161.             if (gcd.di.fResFlags != diNew.fResFlags ||
  162.                     gcd.di.wLanguage != diNew.wLanguage ||
  163.                     NameOrdCmp(gcd.di.pszClass ?
  164.                     gcd.di.pszClass : szEmpty, diNew.pszClass) != 0 ||
  165.                     NameOrdCmp(gcd.di.pszMenu ?
  166.                     gcd.di.pszMenu : szEmpty, diNew.pszMenu) != 0)
  167.                 fChanged = TRUE;
  168.             if (lstrcmp(gcd.di.szFontName, diNew.szFontName) != 0 ||
  169.                     (*diNew.szFontName &&
  170.                     gcd.di.nPointSize != diNew.nPointSize))
  171.                 fChanged = fFontChanged = TRUE;
  172.         }
  173.     }
  174.     /*
  175.      * Did something change?
  176.      */
  177.     if (fChanged) {
  178.         if (gfDlgSelected) {
  179.             hwndOld = npcStyles->hwnd;
  180.             CreateControl(npcStyles, pszTextNew, flStyleNew, flExtStyleNew,
  181.                     npcStyles->id, &npcStyles->rc, (HWND)NULL, &diNew);
  182.             /*
  183.              * Create all the control windows in the new dialog.
  184.              * They must be created (not just moved over by changing
  185.              * the parent and owner) because some controls have
  186.              * allocated memory on the old dialogs heap, and this
  187.              * heap will become invalid after the old dialog
  188.              * is destroyed below. 
  189.              */
  190.             for (npc = npcHead; npc; npc = npc->npcNext) {
  191.                 /*
  192.                  * If this is an icon control and the dialog font
  193.                  * was just changed, we need to resize the control
  194.                  * based on the new default icon size.
  195.                  */
  196.                 if (npc->pwcd->iType == W_ICON && fFontChanged) {
  197.                     npc->rc.right = npc->rc.left + awcd[W_ICON].cxDefault;
  198.                     npc->rc.bottom = npc->rc.top + awcd[W_ICON].cyDefault;
  199.                 }
  200.                 CreateControl(npc, npc->text, npc->flStyle, npc->flExtStyle,
  201.                         npc->id, &npc->rc, (HWND)NULL, NULL);
  202.             }
  203.             /*
  204.              * Now move all the drag windows over to the new dialog.
  205.              * This must be done after creating all the controls
  206.              * because of the touchy Z-order that the drag windows
  207.              * and the controls must have for painting and selection
  208.              * of the drag windows to work properly.  Note that we
  209.              * rely on SetParent to add the window at
  210.              * the TOP in Z-order.
  211.              */
  212.             for (npc = npcHead; npc; npc = npc->npcNext) {
  213.                 SetParent(npc->hwndDrag, npcStyles->hwnd);
  214.                 /*
  215.                  * Adjust the position of the drag window.
  216.                  */
  217.                 SizeDragToControl(npc);
  218.             }
  219.             ShowWindow(npcStyles->hwnd, SW_SHOWNA);
  220.             ToolboxOnTop();
  221.             DestroyWindow(hwndOld);
  222.         }
  223.         else {
  224.             hwndOld = npcStyles->hwnd;
  225.             if (CreateControl(npcStyles, pszTextNew, flStyleNew, flExtStyleNew,
  226.                     npcStyles->id, &npcStyles->rc, hwndOld, NULL)) {
  227.                 /*
  228.                  * Get rid of the old control window.
  229.                  */
  230.                 DestroyWindow(hwndOld);
  231.                 /*
  232.                  * Adjust the size and position of its drag window.
  233.                  */
  234.                 SizeDragToControl(npcStyles);
  235.             }
  236.         }
  237.         gfResChged = gfDlgChanged = TRUE;
  238.         ShowFileStatus(FALSE);
  239.         StatusUpdate();
  240.         StatusSetEnable();
  241.     }
  242. }
  243. /************************************************************************
  244. * GenericStylesDlgProc
  245. *
  246. * Dialog procedure for styles.
  247. *
  248. ************************************************************************/
  249. DIALOGPROC GenericStylesDlgProc(
  250.     HWND hwnd,
  251.     UINT msg,
  252.     WPARAM wParam,
  253.     LPARAM lParam)
  254. {
  255.     switch (msg) {
  256.         case WM_INITDIALOG:
  257.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  258.                     npcStyles->flStyle);
  259.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  260.             CenterWindow(hwnd);
  261.             return TRUE;
  262.         case WM_COMMAND:
  263.             switch (LOWORD(wParam)) {
  264.                 case IDOK:
  265.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  266.                             &flStyleNew);
  267.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  268.                     EndDialog(hwnd, IDOK);
  269.                     return TRUE;
  270.                 case IDCANCEL:
  271.                     EndDialog(hwnd, IDCANCEL);
  272.                     return TRUE;
  273.                 case IDHELP:
  274.                     StylesHelp();
  275.                     break;
  276.             }
  277.             return FALSE;
  278.         default:
  279.             return FALSE;
  280.     }
  281. }
  282. /************************************************************************
  283. * CheckBoxStylesDlgProc
  284. *
  285. * Dialog procedure for checkboxes.
  286. *
  287. ************************************************************************/
  288. DIALOGPROC CheckBoxStylesDlgProc(
  289.     HWND hwnd,
  290.     UINT msg,
  291.     WPARAM wParam,
  292.     LPARAM lParam)
  293. {
  294.     DWORD dwType;
  295.     BOOL f3State;
  296.     BOOL fAuto;
  297.     switch (msg) {
  298.         case WM_INITDIALOG:
  299.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  300.                     npcStyles->flStyle);
  301.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  302.             dwType = npcStyles->flStyle & BS_ALL;
  303.             if (dwType == BS_AUTOCHECKBOX || dwType == BS_AUTO3STATE)
  304.                 CheckDlgButton(hwnd, DID_BS_AUTOXXX, 1);
  305.             if (dwType == BS_3STATE || dwType == BS_AUTO3STATE)
  306.                 CheckDlgButton(hwnd, DID_BS_3STATE, 1);
  307.             CenterWindow(hwnd);
  308.             return TRUE;
  309.         case WM_COMMAND:
  310.             switch (LOWORD(wParam)) {
  311.                 case IDOK:
  312.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  313.                             &flStyleNew);
  314.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  315.                     fAuto = IsDlgButtonChecked(hwnd, DID_BS_AUTOXXX);
  316.                     f3State = IsDlgButtonChecked(hwnd, DID_BS_3STATE);
  317.                     flStyleNew &= ~BS_ALL;
  318.                     if (fAuto) {
  319.                         if (f3State)
  320.                             flStyleNew |= BS_AUTO3STATE;
  321.                         else
  322.                             flStyleNew |= BS_AUTOCHECKBOX;
  323.                     }
  324.                     else {
  325.                         if (f3State)
  326.                             flStyleNew |= BS_3STATE;
  327.                         else
  328.                             flStyleNew |= BS_CHECKBOX;
  329.                     }
  330.                     EndDialog(hwnd, IDOK);
  331.                     return TRUE;
  332.                 case IDCANCEL:
  333.                     EndDialog(hwnd, IDCANCEL);
  334.                     return TRUE;
  335.                 case IDHELP:
  336.                     StylesHelp();
  337.                     break;
  338.             }
  339.             return FALSE;
  340.         default:
  341.             return FALSE;
  342.     }
  343. }
  344. /************************************************************************
  345. * RadioButtonStylesDlgProc
  346. *
  347. * Dialog box procedure for radio buttons.
  348. *
  349. ************************************************************************/
  350. DIALOGPROC RadioButtonStylesDlgProc(
  351.     HWND hwnd,
  352.     UINT msg,
  353.     WPARAM wParam,
  354.     LPARAM lParam)
  355. {
  356.     switch (msg) {
  357.         case WM_INITDIALOG:
  358.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  359.                     npcStyles->flStyle);
  360.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  361.             if ((npcStyles->flStyle & BS_ALL) == BS_AUTORADIOBUTTON)
  362.                 CheckDlgButton(hwnd, DID_BS_AUTOXXX, 1);
  363.             CenterWindow(hwnd);
  364.             return TRUE;
  365.         case WM_COMMAND:
  366.             switch (LOWORD(wParam)) {
  367.                 case IDOK:
  368.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  369.                             &flStyleNew);
  370.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  371.                     flStyleNew &= ~BS_ALL;
  372.                     if (IsDlgButtonChecked(hwnd, DID_BS_AUTOXXX))
  373.                         flStyleNew |= BS_AUTORADIOBUTTON;
  374.                     else
  375.                         flStyleNew |= BS_RADIOBUTTON;
  376.                     EndDialog(hwnd, IDOK);
  377.                     return TRUE;
  378.                 case IDCANCEL:
  379.                     EndDialog(hwnd, IDCANCEL);
  380.                     return TRUE;
  381.                 case IDHELP:
  382.                     StylesHelp();
  383.                     break;
  384.             }
  385.             return FALSE;
  386.         default:
  387.             return FALSE;
  388.     }
  389. }
  390. /************************************************************************
  391. * PushButtonStylesDlgProc
  392. *
  393. * We do not normally allow more than one default push button in a
  394. * dialog. but if this button is already a default button, we must
  395. * allow them to change it to a normal one, even if there is already
  396. * another default button in the dialog.  Note that this condition
  397. * would normally never happen, unless they read in a res file with
  398. * this condition already.
  399. *
  400. ************************************************************************/
  401. DIALOGPROC PushButtonStylesDlgProc(
  402.     HWND hwnd,
  403.     UINT msg,
  404.     WPARAM wParam,
  405.     LPARAM lParam)
  406. {
  407.     NPCTYPE npc;
  408.     switch (msg) {
  409.         case WM_INITDIALOG:
  410.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  411.                     npcStyles->flStyle);
  412.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  413.             /*
  414.              * Only test for possibly disabling the "default"
  415.              * checkbox if the current control does not have the
  416.              * "default" style.  If it does, we must always allow
  417.              * them to turn it off.
  418.              */
  419.             if ((npcStyles->flStyle & BS_ALL) != BS_DEFPUSHBUTTON) {
  420.                 /*
  421.                  * Loop through all the controls.  If any pushbutton
  422.                  * is found with the "default" style, we disable the
  423.                  * "Default" checkbox in the styles dialog.
  424.                  */
  425.                 for (npc = npcHead; npc; npc = npc->npcNext)
  426.                     if ((npc->pwcd->iType == W_PUSHBUTTON) &&
  427.                             (npc->flStyle & BS_ALL) == BS_DEFPUSHBUTTON) {
  428.                         EnableWindow(GetDlgItem(hwnd, DID_BS_DEFPUSHBUTTON),
  429.                                 FALSE);
  430.                         break;
  431.                     }
  432.             }
  433.             CenterWindow(hwnd);
  434.             return TRUE;
  435.         case WM_COMMAND:
  436.             switch (LOWORD(wParam)) {
  437.                 case IDOK:
  438.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  439.                             &flStyleNew);
  440.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  441.                     EndDialog(hwnd, IDOK);
  442.                     return TRUE;
  443.                 case IDCANCEL:
  444.                     EndDialog(hwnd, IDCANCEL);
  445.                     return TRUE;
  446.                 case IDHELP:
  447.                     StylesHelp();
  448.                     break;
  449.             }
  450.             return FALSE;
  451.         default:
  452.             return FALSE;
  453.     }
  454. }
  455. /************************************************************************
  456. * ComboBoxStylesDlgProc
  457. *
  458. * Dialog procedure for combo boxes.
  459. *
  460. ************************************************************************/
  461. DIALOGPROC ComboBoxStylesDlgProc(
  462.     HWND hwnd,
  463.     UINT msg,
  464.     WPARAM wParam,
  465.     LPARAM lParam)
  466. {
  467.     switch (msg) {
  468.         case WM_INITDIALOG:
  469.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  470.                     npcStyles->flStyle);
  471.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  472.             EnableComboBoxStyles(hwnd, 0);
  473.             CenterWindow(hwnd);
  474.             return TRUE;
  475.         case WM_COMMAND:
  476.             switch (LOWORD(wParam)) {
  477.                 case DID_CBS_OWNERDRAWFIXED:
  478.                 case DID_CBS_OWNERDRAWVARIABLE:
  479.                     if (HIWORD(wParam) == BN_CLICKED)
  480.                         EnableComboBoxStyles(hwnd,
  481.                                 LOWORD(wParam));
  482.                     return TRUE;
  483.                 case IDOK:
  484.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  485.                             &flStyleNew);
  486.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  487.                     EndDialog(hwnd, IDOK);
  488.                     return TRUE;
  489.                 case IDCANCEL:
  490.                     EndDialog(hwnd, IDCANCEL);
  491.                     return TRUE;
  492.                 case IDHELP:
  493.                     StylesHelp();
  494.                     break;
  495.             }
  496.             return FALSE;
  497.         default:
  498.             return FALSE;
  499.     }
  500. }
  501. /************************************************************************
  502. * EnableComboBoxStyles
  503. *
  504. * Checks/unchecks, disables/enables various checkboxes that are
  505. * mutually exclusive and/or dependant for the Combo Box Styles dialog.
  506. *
  507. * Arguments:
  508. *   HWND hwnd   - Dialog window handle.
  509. *   INT idCtrl  - ID of the control that was clicked on.
  510. *
  511. ************************************************************************/
  512. STATICFN VOID EnableComboBoxStyles(
  513.     HWND hwnd,
  514.     INT idCtrl)
  515. {
  516.     BOOL fFixedChecked;
  517.     BOOL fVariableChecked;
  518.     fFixedChecked = IsDlgButtonChecked(hwnd, DID_CBS_OWNERDRAWFIXED);
  519.     fVariableChecked = IsDlgButtonChecked(hwnd, DID_CBS_OWNERDRAWVARIABLE);
  520.     if (fFixedChecked || fVariableChecked) {
  521.         EnableWindow(GetDlgItem(hwnd, DID_CBS_HASSTRINGS), TRUE);
  522.     }
  523.     else {
  524.         EnableWindow(GetDlgItem(hwnd, DID_CBS_HASSTRINGS), FALSE);
  525.         CheckDlgButton(hwnd, DID_CBS_HASSTRINGS, 0);
  526.     }
  527.     switch (idCtrl) {
  528.         case DID_CBS_OWNERDRAWFIXED:
  529.             if (fFixedChecked)
  530.                 CheckDlgButton(hwnd, DID_CBS_OWNERDRAWVARIABLE, 0);
  531.             break;
  532.         case DID_CBS_OWNERDRAWVARIABLE:
  533.             if (fVariableChecked)
  534.                 CheckDlgButton(hwnd, DID_CBS_OWNERDRAWFIXED, 0);
  535.             break;
  536.     }
  537. }
  538. /************************************************************************
  539. * EditStylesDlgProc
  540. *
  541. * Dialog procedure for edit boxes.
  542. *
  543. ************************************************************************/
  544. DIALOGPROC EditStylesDlgProc(
  545.     HWND hwnd,
  546.     UINT msg,
  547.     WPARAM wParam,
  548.     LPARAM lParam)
  549. {
  550.     switch (msg) {
  551.         case WM_INITDIALOG:
  552.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  553.                     npcStyles->flStyle);
  554.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  555.             EnableEditStyles(hwnd, 0);
  556.             CenterWindow(hwnd);
  557.             return TRUE;
  558.         case WM_COMMAND:
  559.             switch (LOWORD(wParam)) {
  560.                 case DID_ES_UPPERCASE:
  561.                 case DID_ES_LOWERCASE:
  562.                 case DID_ES_MULTILINE:
  563.                     if (HIWORD(wParam) == BN_CLICKED)
  564.                         EnableEditStyles(hwnd,
  565.                                 LOWORD(wParam));
  566.                     return TRUE;
  567.                 case IDOK:
  568.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  569.                             &flStyleNew);
  570.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  571.                     EndDialog(hwnd, IDOK);
  572.                     return TRUE;
  573.                 case IDCANCEL:
  574.                     EndDialog(hwnd, IDCANCEL);
  575.                     return TRUE;
  576.                 case IDHELP:
  577.                     StylesHelp();
  578.                     break;
  579.             }
  580.             return FALSE;
  581.         default:
  582.             return FALSE;
  583.     }
  584. }
  585. /************************************************************************
  586. * EnableEditStyles
  587. *
  588. * Checks/unchecks, disables/enables various checkboxes that are
  589. * mutually exclusive and/or dependant for the Edit Field Styles dialog.
  590. *
  591. * Arguments:
  592. *   HWND hwnd  - Dialog window handle.
  593. *   INT idCtrl - ID of the control that was clicked on.
  594. *
  595. ************************************************************************/
  596. STATICFN VOID EnableEditStyles(
  597.     HWND hwnd,
  598.     INT idCtrl)
  599. {
  600.     if (IsDlgButtonChecked(hwnd, DID_ES_MULTILINE)) {
  601.         EnableWindow(GetDlgItem(hwnd, DID_ES_CENTER), TRUE);
  602.         EnableWindow(GetDlgItem(hwnd, DID_ES_RIGHT), TRUE);
  603.         EnableWindow(GetDlgItem(hwnd, DID_WS_VSCROLL), TRUE);
  604.         EnableWindow(GetDlgItem(hwnd, DID_ES_AUTOVSCROLL), TRUE);
  605.         EnableWindow(GetDlgItem(hwnd, DID_WS_HSCROLL), TRUE);
  606.     }
  607.     else {
  608.         EnableWindow(GetDlgItem(hwnd, DID_ES_CENTER), FALSE);
  609.         EnableWindow(GetDlgItem(hwnd, DID_ES_RIGHT), FALSE);
  610.         EnableWindow(GetDlgItem(hwnd, DID_WS_VSCROLL), FALSE);
  611.         EnableWindow(GetDlgItem(hwnd, DID_ES_AUTOVSCROLL), FALSE);
  612.         EnableWindow(GetDlgItem(hwnd, DID_WS_HSCROLL), FALSE);
  613.         CheckDlgButton(hwnd, DID_ES_LEFT, 1);
  614.         CheckDlgButton(hwnd, DID_ES_CENTER, 0);
  615.         CheckDlgButton(hwnd, DID_ES_RIGHT, 0);
  616.         CheckDlgButton(hwnd, DID_WS_VSCROLL, 0);
  617.         CheckDlgButton(hwnd, DID_ES_AUTOVSCROLL, 0);
  618.         CheckDlgButton(hwnd, DID_WS_HSCROLL, 0);
  619.     }
  620.     if (idCtrl == DID_ES_UPPERCASE) {
  621.         if (IsDlgButtonChecked(hwnd, DID_ES_UPPERCASE))
  622.             CheckDlgButton(hwnd, DID_ES_LOWERCASE, 0);
  623.     }
  624.     else if (idCtrl == DID_ES_LOWERCASE) {
  625.         if (IsDlgButtonChecked(hwnd, DID_ES_LOWERCASE))
  626.             CheckDlgButton(hwnd, DID_ES_UPPERCASE, 0);
  627.     }
  628. }
  629. /************************************************************************
  630. * ListBoxStylesDlgProc
  631. *
  632. * Dialog procedure for list boxes.
  633. *
  634. ************************************************************************/
  635. DIALOGPROC ListBoxStylesDlgProc(
  636.     HWND hwnd,
  637.     UINT msg,
  638.     WPARAM wParam,
  639.     LPARAM lParam)
  640. {
  641.     switch (msg) {
  642.         case WM_INITDIALOG:
  643.             CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
  644.                     npcStyles->flStyle);
  645.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  646.             EnableListBoxStyles(hwnd, 0);
  647.             CenterWindow(hwnd);
  648.             return TRUE;
  649.         case WM_COMMAND:
  650.             switch (LOWORD(wParam)) {
  651.                 case DID_LBS_STANDARD:
  652.                 case DID_LBS_NOTIFY:
  653.                 case DID_LBS_SORT:
  654.                 case DID_WS_VSCROLL:
  655.                 case DID_WS_BORDER:
  656.                 case DID_LBS_MULTIPLESEL:
  657.                 case DID_LBS_EXTENDEDSEL:
  658.                 case DID_LBS_OWNERDRAWFIXED:
  659.                 case DID_LBS_OWNERDRAWVARIABLE:
  660.                 case DID_LBS_NODATA:
  661.                 case DID_LBS_HASSTRINGS:
  662.                     if (HIWORD(wParam) == BN_CLICKED)
  663.                         EnableListBoxStyles(hwnd,
  664.                                 LOWORD(wParam));
  665.                     return TRUE;
  666.                 case IDOK:
  667.                     QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
  668.                             &flStyleNew);
  669.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  670.                     EndDialog(hwnd, IDOK);
  671.                     return TRUE;
  672.                 case IDCANCEL:
  673.                     EndDialog(hwnd, IDCANCEL);
  674.                     return TRUE;
  675.                 case IDHELP:
  676.                     StylesHelp();
  677.                     break;
  678.             }
  679.             return FALSE;
  680.         default:
  681.             return FALSE;
  682.     }
  683. }
  684. /************************************************************************
  685. * EnableListBoxStyles
  686. *
  687. * Checks/unchecks, disables/enables various checkboxes that are
  688. * mutually exclusive and/or dependant for the List Box Styles dialog.
  689. *
  690. * Arguments:
  691. *   HWND hwnd  - Dialog window handle.
  692. *   INT idCtrl - ID of the control that was clicked on.
  693. *
  694. ************************************************************************/
  695. STATICFN VOID EnableListBoxStyles(
  696.     HWND hwnd,
  697.     INT idCtrl)
  698. {
  699.     WORD fCheckState;
  700.     BOOL fFixedChecked;
  701.     BOOL fVariableChecked;
  702.     fFixedChecked = IsDlgButtonChecked(hwnd, DID_LBS_OWNERDRAWFIXED);
  703.     fVariableChecked = IsDlgButtonChecked(hwnd, DID_LBS_OWNERDRAWVARIABLE);
  704.     if (fFixedChecked || fVariableChecked) {
  705.         EnableWindow(GetDlgItem(hwnd, DID_LBS_HASSTRINGS), TRUE);
  706.     }
  707.     else {
  708.         EnableWindow(GetDlgItem(hwnd, DID_LBS_HASSTRINGS), FALSE);
  709.         CheckDlgButton(hwnd, DID_LBS_HASSTRINGS, 0);
  710.     }
  711.     EnableWindow(GetDlgItem(hwnd, DID_LBS_NODATA), fFixedChecked);
  712.     switch (idCtrl) {
  713.         case DID_LBS_STANDARD:
  714.             fCheckState = (WORD)(IsDlgButtonChecked(hwnd, DID_LBS_STANDARD)
  715.                     ? 1 : 0);
  716.             CheckDlgButton(hwnd, DID_LBS_NOTIFY, fCheckState);
  717.             CheckDlgButton(hwnd, DID_LBS_SORT, fCheckState);
  718.             CheckDlgButton(hwnd, DID_WS_VSCROLL, fCheckState);
  719.             CheckDlgButton(hwnd, DID_WS_BORDER, fCheckState);
  720.             if (fCheckState)
  721.                 CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
  722.             break;
  723.         case DID_LBS_OWNERDRAWFIXED:
  724.             if (fFixedChecked)
  725.                 CheckDlgButton(hwnd, DID_LBS_OWNERDRAWVARIABLE, 0);
  726.             else
  727.                 CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
  728.             break;
  729.         case DID_LBS_OWNERDRAWVARIABLE:
  730.             if (fVariableChecked) {
  731.                 CheckDlgButton(hwnd, DID_LBS_OWNERDRAWFIXED, 0);
  732.                 CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
  733.                 EnableWindow(GetDlgItem(hwnd, DID_LBS_NODATA), FALSE);
  734.             }
  735.             break;
  736.         case DID_LBS_MULTIPLESEL:
  737.             if (IsDlgButtonChecked(hwnd, DID_LBS_MULTIPLESEL))
  738.                 CheckDlgButton(hwnd, DID_LBS_EXTENDEDSEL, 0);
  739.             break;
  740.         case DID_LBS_EXTENDEDSEL:
  741.             if (IsDlgButtonChecked(hwnd, DID_LBS_EXTENDEDSEL))
  742.                 CheckDlgButton(hwnd, DID_LBS_MULTIPLESEL, 0);
  743.             break;
  744.         case DID_LBS_NODATA:
  745.             if (IsDlgButtonChecked(hwnd, DID_LBS_NODATA)) {
  746.                 CheckDlgButton(hwnd, DID_LBS_SORT, 0);
  747.                 CheckDlgButton(hwnd, DID_LBS_HASSTRINGS, 0);
  748.                 CheckDlgButton(hwnd, DID_LBS_STANDARD, 0);
  749.             }
  750.             break;
  751.         case DID_LBS_HASSTRINGS:
  752.             if (IsDlgButtonChecked(hwnd, DID_LBS_HASSTRINGS))
  753.                 CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
  754.             break;
  755.         default:
  756.             if (!IsDlgButtonChecked(hwnd, DID_LBS_NOTIFY) ||
  757.                     !IsDlgButtonChecked(hwnd, DID_LBS_SORT) ||
  758.                     !IsDlgButtonChecked(hwnd, DID_WS_VSCROLL) ||
  759.                     !IsDlgButtonChecked(hwnd, DID_WS_BORDER))
  760.                 fCheckState = 0;
  761.             else
  762.                 fCheckState = 1;
  763.             CheckDlgButton(hwnd, DID_LBS_STANDARD, fCheckState);
  764.             if (IsDlgButtonChecked(hwnd, DID_LBS_SORT) ||
  765.                     IsDlgButtonChecked(hwnd, DID_LBS_HASSTRINGS))
  766.                 CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
  767.             break;
  768.     }
  769. }
  770. /************************************************************************
  771. * CustomStylesDlgProc
  772. *
  773. * Dialog procedure for custom controls.
  774. *
  775. ************************************************************************/
  776. DIALOGPROC CustomStylesDlgProc(
  777.     HWND hwnd,
  778.     UINT msg,
  779.     WPARAM wParam,
  780.     LPARAM lParam)
  781. {
  782.     switch (msg) {
  783.         case WM_INITDIALOG:
  784.             SetDlgItemText(hwnd, DID_CUSTOMSTYLESCLASS,
  785.                     npcStyles->pwcd->pszClass);
  786.             SendDlgItemMessage(hwnd, DID_CUSTOMSTYLESSTYLES, EM_LIMITTEXT,
  787.                     CCHHEXLONGMAX, 0L);
  788.             SetCustomStylesField(hwnd, npcStyles->flStyle);
  789.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  790.             CenterWindow(hwnd);
  791.             return TRUE;
  792.         case WM_COMMAND:
  793.             switch (LOWORD(wParam)) {
  794.                 case DID_CUSTOMSTYLESSTYLES:
  795.                     if (HIWORD(wParam) == EN_CHANGE) {
  796.                         flStyleNew = GetCustomStylesField(hwnd);
  797.                         CheckStyleBoxes(hwnd, IC_WINDOW, flStyleNew);
  798.                     }
  799.                     break;
  800.                 case DID_WS_VISIBLE:
  801.                 case DID_WS_DISABLED:
  802.                 case DID_WS_GROUP:
  803.                 case DID_WS_TABSTOP:
  804.                     if (HIWORD(wParam) == BN_CLICKED) {
  805.                         flStyleNew = GetCustomStylesField(hwnd);
  806.                         QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  807.                         SetCustomStylesField(hwnd, flStyleNew);
  808.                     }
  809.                     break;
  810.                 case IDOK:
  811.                     flStyleNew = GetCustomStylesField(hwnd);
  812.                     EndDialog(hwnd, IDOK);
  813.                     return TRUE;
  814.                 case IDCANCEL:
  815.                     EndDialog(hwnd, IDCANCEL);
  816.                     return TRUE;
  817.                 case IDHELP:
  818.                     StylesHelp();
  819.                     break;
  820.             }
  821.             return FALSE;
  822.         default:
  823.             return FALSE;
  824.     }
  825. }
  826. /************************************************************************
  827. * SetCustomStylesField
  828. *
  829. * Sets the style bits in a custom control.
  830. *
  831. * Arguments:
  832. *   HWND hwnd - handle to the custom control
  833. *   DWORD flStyle - style of the custom control
  834. *
  835. ************************************************************************/
  836. STATICFN VOID SetCustomStylesField(
  837.     HWND hwnd,
  838.     DWORD flStyle)
  839. {
  840.     TCHAR szBuf[32];
  841.     wsprintf(szBuf, L"%#.8lx", flStyle);
  842.     SetDlgItemText(hwnd, DID_CUSTOMSTYLESSTYLES, szBuf);
  843. }
  844. /************************************************************************
  845. * GetCustomStylesField
  846. *
  847. * Gets the style bits of a custom control.
  848. * Arguments:
  849. *   HWND hwnd - handle to the custom control.
  850. *
  851. * Returns:
  852. * The style bits specified for the custom control.
  853. *
  854. ************************************************************************/
  855. STATICFN DWORD GetCustomStylesField(
  856.     HWND hwnd)
  857. {
  858.     TCHAR szBuf[CCHTEXTMAX];
  859.     GetDlgItemText(hwnd, DID_CUSTOMSTYLESSTYLES, szBuf, CCHTEXTMAX);
  860.     return valtoi(szBuf);
  861. }
  862. /************************************************************************
  863. * DialogStylesDlgProc
  864. *
  865. * Dialog procedure for a dialog box.
  866. *
  867. ************************************************************************/
  868. DIALOGPROC DialogStylesDlgProc(
  869.     HWND hwnd,
  870.     UINT msg,
  871.     WPARAM wParam,
  872.     LPARAM lParam)
  873. {
  874.     DWORD flResFlagsNew;
  875.     INT nPointSize;
  876.     INT iLang;
  877.     INT iSubLang;
  878.     TCHAR szFontName[LF_FACESIZE];
  879.     INT nIndex;
  880.     switch (msg) {
  881.         case WM_INITDIALOG:
  882.             CheckStyleBoxes(hwnd, IC_RESFLAGS, (DWORD)diNew.fResFlags);
  883.             CheckStyleBoxes(hwnd, IC_DIALOG, npcStyles->flStyle);
  884.             CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
  885.             if (IsDlgButtonChecked(hwnd, DID_WS_CAPTION)) {
  886.                 CheckDlgButton(hwnd, DID_WS_BORDER, 1);
  887.                 CheckDlgButton(hwnd, DID_WS_DLGFRAME, 1);
  888.             }
  889.             FillFontNameCombo(hwnd);
  890.             FillLanguageCombo(hwnd);
  891.             if (IsOrd(diNew.pszClass))
  892.                 SetDlgItemInt(hwnd, DID_DLGSTYLECLASS,
  893.                         OrdID(diNew.pszClass), FALSE);
  894.             else
  895.                 SetDlgItemText(hwnd, DID_DLGSTYLECLASS, diNew.pszClass);
  896.             if (IsOrd(diNew.pszMenu))
  897.                 SetDlgItemInt(hwnd, DID_DLGSTYLEMENU,
  898.                         OrdID(diNew.pszMenu), FALSE);
  899.             else
  900.                 SetDlgItemText(hwnd, DID_DLGSTYLEMENU, diNew.pszMenu);
  901.             EnableDialogStyles(hwnd, 0);
  902.             CenterWindow(hwnd);
  903.             return TRUE;
  904.         case WM_COMMAND:
  905.             switch (LOWORD(wParam)) {
  906.                 case DID_WS_BORDER:
  907.                 case DID_WS_DLGFRAME:
  908.                 case DID_WS_CAPTION:
  909.                 case DID_WS_POPUP:
  910.                 case DID_WS_CHILD:
  911.                     if (HIWORD(wParam) == BN_CLICKED)
  912.                         EnableDialogStyles(hwnd,
  913.                                 LOWORD(wParam));
  914.                     return TRUE;
  915.                 case DID_DLGSTYLEFONTNAME:
  916.                     /*
  917.                      * Did the font name combo change?
  918.                      */
  919.                     if (HIWORD(wParam) == CBN_EDITCHANGE ||
  920.                             HIWORD(wParam) == CBN_SELCHANGE) {
  921.                         /*
  922.                          * Get the font name and begin looking for it.
  923.                          */
  924.                         if (HIWORD(wParam) == CBN_EDITCHANGE) {
  925.                             /*
  926.                              * The edit field was typed into.  Get the
  927.                              * new text from there.
  928.                              */
  929.                             GetDlgItemText(hwnd, DID_DLGSTYLEFONTNAME,
  930.                                     szFontName, LF_FACESIZE);
  931.                         }
  932.                         else {
  933.                             /*
  934.                              * A new string was selected from the list
  935.                              * box.  Get it from the list box, because
  936.                              * at this point the new text is not yet set
  937.                              * into the edit control!
  938.                              */
  939.                             nIndex = (INT)SendDlgItemMessage(hwnd,
  940.                                     DID_DLGSTYLEFONTNAME, CB_GETCURSEL, 0, 0L);
  941.                             if (nIndex != CB_ERR)
  942.                                 SendDlgItemMessage(hwnd,
  943.                                         DID_DLGSTYLEFONTNAME, CB_GETLBTEXT,
  944.                                         nIndex, (DWORD)szFontName);
  945.                             else
  946.                                 *szFontName = CHAR_NULL;
  947.                         }
  948.                         FillPointSizeCombo(hwnd, szFontName);
  949.                     }
  950.                     return TRUE;
  951.                 case DID_DLGSTYLELANG:
  952.                     /*
  953.                      * Did the language combo change?
  954.                      */
  955.                     if (HIWORD(wParam) == CBN_SELCHANGE) {
  956.                         nIndex = (INT)SendDlgItemMessage(hwnd,
  957.                                 DID_DLGSTYLELANG, CB_GETCURSEL, 0, 0L);
  958.                         iLang = (INT)SendDlgItemMessage(hwnd,
  959.                                 DID_DLGSTYLELANG, CB_GETITEMDATA, nIndex, 0);
  960.                         FillSubLanguageCombo(hwnd, iLang);
  961.                     }
  962.                     return TRUE;
  963.                 case IDOK:
  964.                     /*
  965.                      * If they have entered a font name and an empty
  966.                      * or zero point size, display an error.
  967.                      */
  968.                     nPointSize = GetDlgItemInt(
  969.                             hwnd, DID_DLGSTYLEPOINTSIZE, NULL, FALSE);
  970.                     if (!nPointSize &&
  971.                             SendDlgItemMessage(hwnd,
  972.                             DID_DLGSTYLEFONTNAME, WM_GETTEXTLENGTH, 0, 0L)) {
  973.                         Message(MSG_ZEROPOINTSIZE);
  974.                         SetFocus(GetDlgItem(hwnd, DID_DLGSTYLEPOINTSIZE));
  975.                         return TRUE;
  976.                     }
  977.                     GetDlgItemText(hwnd, DID_DLGSTYLEFONTNAME,
  978.                             diNew.szFontName, LF_FACESIZE);
  979.                     diNew.nPointSize = nPointSize;
  980.                     /*
  981.                      * Get the Language.
  982.                      */
  983.                     nIndex = (INT)SendDlgItemMessage(hwnd,
  984.                             DID_DLGSTYLELANG, CB_GETCURSEL, 0, 0L);
  985.                     iLang = (INT)SendDlgItemMessage(hwnd,
  986.                             DID_DLGSTYLELANG, CB_GETITEMDATA,
  987.                             nIndex, 0);
  988.                     nIndex = (INT)SendDlgItemMessage(hwnd,
  989.                             DID_DLGSTYLESUBLANG, CB_GETCURSEL, 0, 0L);
  990.                     iSubLang = (INT)SendDlgItemMessage(hwnd,
  991.                             DID_DLGSTYLESUBLANG, CB_GETITEMDATA,
  992.                             nIndex, 0);
  993.                     diNew.wLanguage = MAKELANGID(gaLangTable[iLang].wPrimary,
  994.                             gaLangTable[iLang].asl[iSubLang].wSubLang);
  995.                     /*
  996.                      * Get the resource flags.  We need to use a temporary
  997.                      * long variable because QueryCheckedStyles requires
  998.                      * a long.
  999.                      */
  1000.                     flResFlagsNew = diNew.fResFlags;
  1001.                     QueryCheckedStyles(hwnd, IC_RESFLAGS, &flResFlagsNew);
  1002.                     diNew.fResFlags = (WORD)flResFlagsNew;
  1003.                     QueryCheckedStyles(hwnd, IC_DIALOG, &flStyleNew);
  1004.                     QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
  1005.                     /*
  1006.                      * Set the DS_SETFONT style, if they specified
  1007.                      * a font.
  1008.                      */
  1009.                     if (*diNew.szFontName)
  1010.                         flStyleNew |= DS_SETFONT;
  1011.                     else
  1012.                         flStyleNew &= ~DS_SETFONT;
  1013.                     GetDlgItemText(hwnd, DID_DLGSTYLECLASS,
  1014.                             diNew.pszClass, CCHTEXTMAX);
  1015.                     /*
  1016.                      * Convert the class to an ordinal, if necessary.
  1017.                      */
  1018.                     StrToNameOrd(diNew.pszClass, FALSE);
  1019.                     GetDlgItemText(hwnd, DID_DLGSTYLEMENU,
  1020.                             diNew.pszMenu, CCHTEXTMAX);
  1021.                     /*
  1022.                      * Convert the menu name to an ordinal, if necessary.
  1023.                      */
  1024.                     StrToNameOrd(diNew.pszMenu, FALSE);
  1025.                     /*
  1026.                      * If they just removed the caption style,
  1027.                      * clear the dialog's caption text at the
  1028.                      * same time.
  1029.                      */
  1030.                     if ((npcStyles->flStyle & WS_CAPTION) == WS_CAPTION &&
  1031.                             (flStyleNew & WS_CAPTION) != WS_CAPTION)
  1032.                         *pszTextNew = CHAR_NULL;
  1033.                     EndDialog(hwnd, IDOK);
  1034.                     return TRUE;
  1035.                 case IDCANCEL:
  1036.                     EndDialog(hwnd, IDCANCEL);
  1037.                     return TRUE;
  1038.                 case IDHELP:
  1039.                     StylesHelp();
  1040.                     break;
  1041.             }
  1042.             return FALSE;
  1043.         default:
  1044.             return FALSE;
  1045.     }
  1046. }
  1047. /************************************************************************
  1048. * EnableDialogStyles
  1049. *
  1050. * Checks and unchecks various checkboxes that are mutually exclusive
  1051. * for the Dialog Styles dialog.
  1052. *
  1053. * Arguments:
  1054. *   HWND hwnd  - Dialog window handle.
  1055. *   INT idCtrl - ID of the control that was clicked on.
  1056. *
  1057. ************************************************************************/
  1058. STATICFN VOID EnableDialogStyles(
  1059.     HWND hwnd,
  1060.     INT idCtrl)
  1061. {
  1062.     switch (idCtrl) {
  1063.         case DID_WS_CAPTION:
  1064.             if (IsDlgButtonChecked(hwnd, DID_WS_CAPTION)) {
  1065.                 CheckDlgButton(hwnd, DID_WS_BORDER, 1);
  1066.                 CheckDlgButton(hwnd, DID_WS_DLGFRAME, 1);
  1067.             }
  1068.             else {
  1069.                 CheckDlgButton(hwnd, DID_WS_BORDER, 0);
  1070.                 CheckDlgButton(hwnd, DID_WS_DLGFRAME, 0);
  1071.             }
  1072.             break;
  1073.         case DID_WS_BORDER:
  1074.         case DID_WS_DLGFRAME:
  1075.             if (IsDlgButtonChecked(hwnd, DID_WS_BORDER) &&
  1076.                     IsDlgButtonChecked(hwnd, DID_WS_DLGFRAME))
  1077.                 CheckDlgButton(hwnd, DID_WS_CAPTION, 1);
  1078.             else
  1079.                 CheckDlgButton(hwnd, DID_WS_CAPTION, 0);
  1080.             break;
  1081.         case DID_WS_CHILD:
  1082.             if (IsDlgButtonChecked(hwnd, DID_WS_CHILD))
  1083.                 CheckDlgButton(hwnd, DID_WS_POPUP, 0);
  1084.             break;
  1085.         case DID_WS_POPUP:
  1086.             if (IsDlgButtonChecked(hwnd, DID_WS_POPUP))
  1087.                 CheckDlgButton(hwnd, DID_WS_CHILD, 0);
  1088.             break;
  1089.     }
  1090. }
  1091. /************************************************************************
  1092. * FillFontNameCombo
  1093. *
  1094. * Fills combo box with available fonts for dialog.
  1095. *
  1096. * Arguments:
  1097. *   HWND hwndDlg - Dialog window handle.
  1098. *
  1099. ************************************************************************/
  1100. STATICFN VOID FillFontNameCombo(
  1101.     HWND hwndDlg)
  1102. {
  1103.     HDC hDC;
  1104.     HWND hwndCombo;
  1105.     TCHAR szName1[LF_FACESIZE];
  1106.     TCHAR szName2[LF_FACESIZE];
  1107.     LPTSTR pszName;
  1108.     LPTSTR pszNameLast;
  1109.     LPTSTR pszNameTemp;
  1110.     INT iIndex;
  1111.     INT iItems;
  1112.     hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLEFONTNAME);
  1113.     if (hDC = GetDC(ghwndMain)) {
  1114.         EnumFonts(hDC, NULL, (FONTENUMPROC) FontNameEnumFunc, (LPARAM)&hwndCombo);
  1115.         ReleaseDC(ghwndMain, hDC);
  1116.     }
  1117.     /*
  1118.      * Strip out any duplicate names in the combobox.  This routine
  1119.      * relies on the items being sorted first.
  1120.      */
  1121.     iItems = (INT)SendMessage(hwndCombo, CB_GETCOUNT, 0, 0);
  1122.     *szName1 = CHAR_NULL;
  1123.     *szName2 = CHAR_NULL;
  1124.     pszName = szName1;
  1125.     pszNameLast = szName2;
  1126.     for (iIndex = 0; iIndex < iItems;) {
  1127.         /*
  1128.          * Get the text of the next item.
  1129.          */
  1130.         SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (DWORD)pszName);
  1131.         /*
  1132.          * If it matches the previous item, delete it.  Otherwise,
  1133.          * flip the buffers to save the current items text and
  1134.          * go on to the next item.
  1135.          */
  1136.         if (lstrcmp(pszName, pszNameLast) == 0) {
  1137.             SendMessage(hwndCombo, CB_DELETESTRING, iIndex, 0);
  1138.             iItems--;
  1139.         }
  1140.         else {
  1141.             pszNameTemp = pszNameLast;
  1142.             pszNameLast = pszName;
  1143.             pszName = pszNameTemp;
  1144.             iIndex++;
  1145.         }
  1146.     }
  1147.     /*
  1148.      * Initialize the font fields.  The order the fields are set
  1149.      * is important, because setting the face name clears out the
  1150.      * point size combo.
  1151.      */
  1152.     SetDlgItemText(hwndDlg, DID_DLGSTYLEFONTNAME, diNew.szFontName);
  1153.     FillPointSizeCombo(hwndDlg, diNew.szFontName);
  1154. }
  1155. /************************************************************************
  1156. * FontNameEnumFunc
  1157. *
  1158. * Enumeration function that adds all the font face names to the
  1159. * Font Face Name combo box in the Dialog Styles dialog.
  1160. *
  1161. * Arguments:
  1162. *   LPLOGFONT lpLogFont - pointer to font structure
  1163. *   LPTEXTMETRIC lpTextMetric - pointer to textmetric struct for font
  1164. *   INT nFontType - type of font
  1165. *   LPVOID lpData - font data
  1166. *
  1167. ************************************************************************/
  1168. BOOL APIENTRY FontNameEnumFunc(
  1169.     LPLOGFONT lpLogFont,
  1170.     LPTEXTMETRIC lpTextMetric,
  1171.     INT nFontType,
  1172.     LPVOID lpData)
  1173. {
  1174.     /*
  1175.      * Add this name to the combo box.
  1176.      */
  1177.     SendMessage(*((LPHWND)lpData), CB_ADDSTRING, 0,
  1178.             (DWORD)lpLogFont->lfFaceName);
  1179.     /*
  1180.      * Keep on going...
  1181.      */
  1182.     return TRUE;
  1183. }
  1184. /************************************************************************
  1185. * FillPointSizeCombo
  1186. *
  1187. * This function fills the Point Size combobox with the point sizes
  1188. * that are available for the given face name.  It should be called
  1189. * whenever the Font Name combobox is changed to keep them in sync.
  1190. *
  1191. * Arguments:
  1192. *   HWND hwndDlg        - Dialog window handle.
  1193. *   LPTSTR pszFaceName  - Face name for the selected font.
  1194. *
  1195. ************************************************************************/
  1196. STATICFN VOID FillPointSizeCombo(
  1197.     HWND hwndDlg,
  1198.     LPTSTR pszFaceName)
  1199. {
  1200.     HDC hDC;
  1201.     HWND hwndCombo;
  1202.     hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLEPOINTSIZE);
  1203.     SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
  1204.     if (*pszFaceName && (hDC = GetDC(ghwndMain))) {
  1205.         EnumFonts(hDC, pszFaceName, (FONTENUMPROC) PointSizeEnumFunc, (LPARAM)&hwndCombo);
  1206.         ReleaseDC(ghwndMain, hDC);
  1207.     }
  1208.     /*
  1209.      * Select a default one.  This is the point size that is currently
  1210.      * selected if the face name is the current one, or else it is the
  1211.      * first point size in the list.
  1212.      */
  1213.     if (gcd.fFontSpecified && lstrcmp(pszFaceName, gcd.di.szFontName) == 0)
  1214.         SetDlgItemInt(hwndDlg, DID_DLGSTYLEPOINTSIZE, gcd.di.nPointSize, FALSE);
  1215.     else
  1216.         SendDlgItemMessage(hwndDlg, DID_DLGSTYLEPOINTSIZE,
  1217.                 CB_SETCURSEL, 0, 0L);
  1218. }
  1219. /************************************************************************
  1220. * PointSizeEnumFunc
  1221. *
  1222. * Enumeration function that adds all the point sizes to the
  1223. * Pt. Size combo box in the Dialog Styles dialog.
  1224. *
  1225. * Arguments:
  1226. *   LPLOGFONT lpLogFont - pointer to font structure
  1227. *   LPTEXTMETRIC lpTextMetric - pointer to textmetric struct for font
  1228. *   INT nFontType - type of font
  1229. *   LPVOID lpData - font data
  1230. *
  1231. ************************************************************************/
  1232. BOOL APIENTRY PointSizeEnumFunc(
  1233.     LPLOGFONT lpLogFont,
  1234.     LPTEXTMETRIC lpTextMetric,
  1235.     INT nFontType,
  1236.     LPVOID lpData)
  1237. {
  1238.     HWND hwndCombo;
  1239.     INT nPointSize;
  1240.     hwndCombo = *((LPHWND)lpData);
  1241.     if (nFontType == RASTER_FONTTYPE) {
  1242.         /*
  1243.          * Convert the pixels to point size.  Note that because of the
  1244.          * definition of the tmHeight field, the tmInternalLeading has
  1245.          * to be subtracted from it before converting to get the proper
  1246.          * font point size.  This is done automatically by the Windows
  1247.          * CreateFont call if you pass in a nHeight parameter that is
  1248.          * negative, so be aware of this when doing the reverse calculation
  1249.          * to create a font of the proper height!
  1250.          */
  1251.         nPointSize = PixelsToPointSize(
  1252.                 lpTextMetric->tmHeight - lpTextMetric->tmInternalLeading);
  1253.         AddToPointSizeCombo(hwndCombo, nPointSize);
  1254.     }
  1255.     else {
  1256.         /*
  1257.          * For scalable (TrueType, ATM or vector) fonts, add the
  1258.          * common point sizes.  This list was pulled out of the
  1259.          ( commdlg.dll Font dialog.
  1260.          */
  1261.         AddToPointSizeCombo(hwndCombo, 8);
  1262.         AddToPointSizeCombo(hwndCombo, 9);
  1263.         AddToPointSizeCombo(hwndCombo, 10);
  1264.         AddToPointSizeCombo(hwndCombo, 11);
  1265.         AddToPointSizeCombo(hwndCombo, 12);
  1266.         AddToPointSizeCombo(hwndCombo, 14);
  1267.         AddToPointSizeCombo(hwndCombo, 16);
  1268.         AddToPointSizeCombo(hwndCombo, 18);
  1269.         AddToPointSizeCombo(hwndCombo, 20);
  1270.         AddToPointSizeCombo(hwndCombo, 22);
  1271.         AddToPointSizeCombo(hwndCombo, 24);
  1272.         AddToPointSizeCombo(hwndCombo, 26);
  1273.         AddToPointSizeCombo(hwndCombo, 28);
  1274.         AddToPointSizeCombo(hwndCombo, 36);
  1275.         AddToPointSizeCombo(hwndCombo, 48);
  1276.         AddToPointSizeCombo(hwndCombo, 72);
  1277.     }
  1278.     /*
  1279.      * Keep on going...
  1280.      */
  1281.     return TRUE;
  1282. }
  1283. /************************************************************************
  1284. * AddToPointSizeCombo
  1285. *
  1286. * This function adds a point size to the point size combobox.
  1287. * It does not allow duplicate point sizes, and the sizes will
  1288. * be inserted in order.
  1289. *
  1290. * Arguments:
  1291. *   HWND hwndCombo - The combobox window handle.
  1292. *   INT nPointSize - The point size to add.
  1293. *
  1294. ************************************************************************/
  1295. STATICFN VOID AddToPointSizeCombo(
  1296.     HWND hwndCombo,
  1297.     INT nPointSize)
  1298. {
  1299.     TCHAR szPointSize[31];
  1300.     INT nPoints2;
  1301.     INT iIndex;
  1302.     INT iIndexAdd;
  1303.     INT iItems;
  1304.     iItems = (INT)SendMessage(hwndCombo, CB_GETCOUNT, 0, 0);
  1305.     for (iIndex = 0, iIndexAdd = -1; iIndex < iItems; iIndex++) {
  1306.         nPoints2 = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, iIndex, 0);
  1307.         if (nPoints2 == nPointSize) {
  1308.             /*
  1309.              * A duplicate was found.  Skip this one.
  1310.              */
  1311.             return;
  1312.         }
  1313.         else if (nPoints2 > nPointSize) {
  1314.             iIndexAdd = iIndex;
  1315.             break;
  1316.         }
  1317.     }
  1318.     /*
  1319.      * Add this point size to the combo box.
  1320.      */
  1321.     itoaw(nPointSize, szPointSize, 10);
  1322.     iIndex = (INT)SendMessage(hwndCombo, CB_INSERTSTRING,
  1323.             iIndexAdd, (DWORD)szPointSize);
  1324.     SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)nPointSize);
  1325. }
  1326. /************************************************************************
  1327. * FillLanguageCombo
  1328. *
  1329. * This function fills the Language combobox with the known languages.
  1330. *
  1331. * Arguments:
  1332. *   HWND hwndDlg - Dialog window handle.
  1333. *
  1334. ************************************************************************/
  1335. STATICFN VOID FillLanguageCombo(
  1336.     HWND hwndDlg)
  1337. {
  1338.     HWND hwndCombo;
  1339.     INT i;
  1340.     INT iIndex;
  1341.     INT iSel;
  1342.     INT iLang;
  1343.     WORD wPrimary;
  1344.     hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLELANG);
  1345.     SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
  1346.     for (i = 0; i < gcLanguages; i++) {
  1347.         iIndex = (INT)SendMessage(hwndCombo, CB_ADDSTRING,
  1348.                 0, (DWORD)ids(gaLangTable[i].idsLangDesc));
  1349.         SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)i);
  1350.     }
  1351.     wPrimary = (WORD)PRIMARYLANGID(diNew.wLanguage);
  1352.     for (i = 0, iSel = 0; i < gcLanguages; i++) {
  1353.         iLang = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
  1354.         if (gaLangTable[iLang].wPrimary == wPrimary) {
  1355.             iSel = i;
  1356.             break;
  1357.         }
  1358.     }
  1359.     SendMessage(hwndCombo, CB_SETCURSEL, iSel, 0L);
  1360.     FillSubLanguageCombo(hwndDlg,
  1361.             (INT)SendMessage(hwndCombo, CB_GETITEMDATA, iSel, 0));
  1362. }
  1363. /************************************************************************
  1364. * FillSubLanguageCombo
  1365. *
  1366. * This function fills the Sub-Language combobox with the sub-languages
  1367. * for the specified language.
  1368. *
  1369. * Arguments:
  1370. *   HWND hwndDlg - Dialog window handle.
  1371. *   INT iLang    - Index to the language in the language table.
  1372. *
  1373. ************************************************************************/
  1374. STATICFN VOID FillSubLanguageCombo(
  1375.     HWND hwndDlg,
  1376.     INT iLang)
  1377. {
  1378.     HWND hwndCombo;
  1379.     INT i;
  1380.     INT iIndex;
  1381.     INT iSel = 0;
  1382.     WORD wSubLang;
  1383.     hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLESUBLANG);
  1384.     SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
  1385.     for (i = 0; i < gaLangTable[iLang].cSubLangs; i++) {
  1386.         iIndex = (INT)SendMessage(hwndCombo, CB_ADDSTRING, 0,
  1387.                 (DWORD)ids(gaLangTable[iLang].asl[i].idsSubLangDesc));
  1388.         SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)i);
  1389.     }
  1390.     /*
  1391.      * Is this the language set for the dialog?  If so, find the
  1392.      * sublanguage and make that the default.
  1393.      */
  1394.     if (gaLangTable[iLang].wPrimary == (WORD)PRIMARYLANGID(diNew.wLanguage)) {
  1395.         wSubLang = SUBLANGID(diNew.wLanguage);
  1396.         for (i = 0; i < gaLangTable[iLang].cSubLangs; i++) {
  1397.             iIndex = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
  1398.             if (wSubLang == gaLangTable[iLang].asl[iIndex].wSubLang) {
  1399.                 iSel = i;
  1400.                 break;
  1401.             }
  1402.         }
  1403.     }
  1404.     SendMessage(hwndCombo, CB_SETCURSEL, iSel, 0L);
  1405. }
  1406. /************************************************************************
  1407. * CheckStyleBoxes
  1408. *
  1409. * This function takes the given style and checks the appropriate
  1410. * check boxes and radio buttons in the styles dialog.  The iClass
  1411. * determines the lookup table to use.
  1412. *
  1413. * Arguments:
  1414. *   HWND hwnd     - Dialog window handle.
  1415. *   INT iClass    - Control class (determines the style lookup table).
  1416. *   DWORD flStyle - Style of the control.
  1417. *
  1418. ************************************************************************/
  1419. STATICFN VOID CheckStyleBoxes(
  1420.     HWND hwnd,
  1421.     INT iClass,
  1422.     DWORD flStyle)
  1423. {
  1424.     register INT i;
  1425.     PCLASSSTYLE pcs;
  1426.     HWND hwndControl;
  1427.     DWORD flStyleMask;
  1428.     i = acsd[iClass].cClassStyles;
  1429.     pcs = acsd[iClass].pacs;
  1430.     while (i--) {
  1431.         /*
  1432.          * Is there a DID_* defined for this style?
  1433.          */
  1434.         if (pcs->idControl) {
  1435.             /*
  1436.              * Does the dialog have a control with this id?
  1437.              */
  1438.             if (hwndControl = GetDlgItem(hwnd, pcs->idControl)) {
  1439.                 flStyleMask =
  1440.                         pcs->flStyleMask ? pcs->flStyleMask : pcs->flStyle;
  1441.                 /*
  1442.                  * If there is a match, check the box.  Otherwise,
  1443.                  * uncheck it.
  1444.                  */
  1445.                 SendMessage(hwndControl, BM_SETCHECK,
  1446.                         ((flStyle & flStyleMask) == pcs->flStyle) ? 1 : 0,
  1447.                         0L);
  1448.             }
  1449.         }
  1450.         pcs++;
  1451.     }
  1452. }
  1453. /************************************************************************
  1454. * QueryCheckedStyles
  1455. *
  1456. * This function returns the new style that the user has selected from
  1457. * dialog.  It reads all the checkboxes and builds up the style.
  1458. * Upon entry, the DWORD that is at pflStyle should be set to the
  1459. * original style for the control.  Chosen bits will be masked off
  1460. * and set as appropriate.  This allows bits that are not settable
  1461. * from within this styles dialog to be left untouched.
  1462. *
  1463. * Arguments:
  1464. *   HWND hwnd       - Dialog window handle.
  1465. *   INT iClass      - Control class (determines the style lookup table).
  1466. *   DWORD *pflStyle - Where to return the style of the control.  What
  1467. *                     this points to should initially have the original
  1468. *                     styles of the control.
  1469. *
  1470. ************************************************************************/
  1471. STATICFN VOID QueryCheckedStyles(
  1472.     HWND hwnd,
  1473.     INT iClass,
  1474.     DWORD *pflStyle)
  1475. {
  1476.     register INT i;
  1477.     PCLASSSTYLE pcs;
  1478.     HWND hwndControl;
  1479.     DWORD flStyleMask;
  1480.     DWORD flStyle;
  1481.     /*
  1482.      * The first step is to strip off all bits that may be changed by
  1483.      * the current dialog.
  1484.      */
  1485.     flStyle = *pflStyle;
  1486.     i = acsd[iClass].cClassStyles;
  1487.     pcs = acsd[iClass].pacs;
  1488.     while (i--) {
  1489.         /*
  1490.          * Is this a style that is settable by a dialog, and does the
  1491.          * current dialog have this style control?
  1492.          */
  1493.         if (pcs->idControl && GetDlgItem(hwnd, pcs->idControl)) {
  1494.             flStyleMask =
  1495.                     pcs->flStyleMask ? pcs->flStyleMask : pcs->flStyle;
  1496.             /*
  1497.              * Strip off all bits in the mask for this style.
  1498.              */
  1499.             flStyle &= ~flStyleMask;
  1500.         }
  1501.         pcs++;
  1502.     }
  1503.     /*
  1504.      * Now we go through all bits that may be set and set any that the
  1505.      * user has selected.
  1506.      */
  1507.     i = acsd[iClass].cClassStyles;
  1508.     pcs = acsd[iClass].pacs;
  1509.     while (i--) {
  1510.         if (pcs->idControl &&
  1511.                 (hwndControl = GetDlgItem(hwnd, pcs->idControl))) {
  1512.             if (SendMessage(hwndControl, BM_GETCHECK, 0, 0L))
  1513.                 flStyle |= pcs->flStyle;
  1514.         }
  1515.         pcs++;
  1516.     }
  1517.     *pflStyle = flStyle;
  1518. }
  1519. /************************************************************************
  1520. * StylesHelp
  1521. *
  1522. * This function shows the appropriate help context from any of the
  1523. * styles dialogs.  It uses the type of control in npcStyles to
  1524. * determine what help to show.
  1525. *
  1526. ************************************************************************/
  1527. STATICFN VOID StylesHelp(VOID)
  1528. {
  1529.     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
  1530.             npcStyles->pwcd->HelpContext);
  1531. }