home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / pm / controls / sty_user.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  31KB  |  935 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_USER.C
  4. *
  5. *  Description : This module contains the code for processing
  6. *                messages sent to the standard window that the
  7. *                standard window does not process.
  8. *
  9. *  Concepts    : Message processing
  10. *
  11. *  API's       : WinSetWindowPos
  12. *                WinSetFocus
  13. *                WinDefWIndowProc
  14. *                WinDlgBox
  15. *                WinSendMsg
  16. *                WinOpenClipbrd
  17. *                WinQueryClipbrdFmtInfo
  18. *                WinCloseClipbrd
  19. *                WinMessageBox
  20. *                WinLoadString
  21. *                WinSendMsg
  22. *                GpiCreateLogFont
  23. *                GpiSetCharSet
  24. *                GpiQueryFontMetrics
  25. *                GpiDeleteSetId
  26. *                WinGetPS
  27. *                WinReleasePS
  28. *                WinFontDlg
  29. *
  30. *  Copyright (C) 1992 IBM Corporation
  31. *
  32. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  33. *      sample code created by IBM Corporation. This sample code is not
  34. *      part of any standard or IBM product and is provided to you solely
  35. *      for  the purpose of assisting you in the development of your
  36. *      applications.  The code is provided "AS IS", without
  37. *      warranty of any kind.  IBM shall not be liable for any damages
  38. *      arising out of your use of the sample code, even if they have been
  39. *      advised of the possibility of such damages.                                                    *
  40. *
  41. ************************************************************************/
  42.  
  43. /*  Include files, macros, defined constants, and externs               */
  44.  
  45. #define INCL_WINMENUS
  46. #define INCL_WINWINDOWMGR
  47. #define INCL_WINCLIPBOARD
  48. #define INCL_WINMLE
  49. #define INCL_WINSTDFONT
  50. #define INCL_GPILCIDS
  51. #define INCL_GPIPRIMITIVES
  52. #define INCL_WINSYS
  53. #define INCL_DOSDEVICES   /* Device values */
  54.  
  55. #include <os2.h>
  56. #include "sty_main.h"
  57. #include "sty_xtrn.h"
  58. #include "sty_dlg.h"
  59. #include <string.h>
  60.  
  61. /*  Global variables */
  62.  
  63. LONG lClrForeground = CLR_BLACK;                    /* color for window text */
  64. LONG lClrBackground = CLR_WHITE;                     /* color for background */
  65.  
  66. LONG lClrDefaultForeground = CLR_BLACK;             /* color for window text */
  67. LONG lClrDefaultBackground = CLR_WHITE;              /* color for background */
  68.  
  69. /*--------------------------------------------------------------*\
  70.  *  Entry point declarations
  71. \*--------------------------------------------------------------*/
  72.  
  73. VOID SetForegroundColor(SHORT idMenu);
  74. VOID SetBackgroundColor(SHORT idMenu);
  75. VOID SetFont(VOID);
  76. VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs);
  77. MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg,
  78.                                   MPARAM mp1, MPARAM mp2);
  79. MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg,
  80.                                   MPARAM mp1, MPARAM mp2);
  81. VOID ShowDemoDlg(SHORT idMenuItem);
  82. VOID ShowDemoMsgBox(SHORT idMenuItem);
  83.  
  84. /*********************************************************************
  85.  *  Name: UserWndProc
  86.  *
  87.  *  Description : Process any messages sent to hwndMain
  88.  *                that are not processed by the standard
  89.  *                window procedure.
  90.  *
  91.  *  Concepts : Routine is called for each message MainWndProc does
  92.  *             not process.  A switch statement branches control
  93.  *             based upon the message passed.  Any messages not
  94.  *             processed here must be passed onto
  95.  *             WinDefWindowProc()
  96.  *
  97.  *  API's : WinSetWindowPos
  98.  *          WinSetFocus
  99.  *          WinDefWIndowProc
  100.  *
  101.  * Parameters   : hwnd - Window handle to which message is addressed
  102.  *                msg - Message type
  103.  *                mp1 - First message parameter
  104.  *                mp2 - Second message parameter
  105.  *
  106.  *  Returns: Return value depended upon the message processed
  107.  *
  108.  ****************************************************************/
  109. MRESULT UserWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  110. {
  111.    switch(msg)
  112.    {
  113.       case WM_SIZE:
  114.          /*
  115.           * Re-size the MLE to be the same width and height
  116.           * as the client window
  117.           */
  118.          WinSetWindowPos(hwndMLE, HWND_TOP, 0, 0, SHORT1FROMMP(mp2),
  119.                             SHORT2FROMMP(mp2), SWP_SIZE);
  120.          break;
  121.  
  122.       case WM_SETFOCUS:
  123.          if(SHORT1FROMMP(mp1))
  124.          {
  125.             WinPostMsg(hwnd, SM_SETFOCUS, NULL, NULL);
  126.          }
  127.          break;
  128.  
  129.       case SM_SETFOCUS:
  130.          WinSetFocus(HWND_DESKTOP, hwndMLE);
  131.          break;
  132.  
  133.       default:
  134.          /*
  135.           * Default must call WinDefWindowProc()
  136.           */
  137.          return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  138.          break;
  139.    }
  140.  
  141.    return (MRESULT)0;
  142.  
  143. }   /*    End of UserWndProc()                                          */
  144.  
  145. /*********************************************************************
  146.  *  Name: UserCommand
  147.  *
  148.  *  Description : Process any WM_COMMAND messages send to
  149.  *                hwndMain that are not processed by MainCommand
  150.  *
  151.  *  Concepts : Routine is called for each WM_COMMAND that is not
  152.  *             posted by a standard menu item. A switch statement
  153.  *             branches control based upon the id of the control
  154.  *             which posted the message.
  155.  *
  156.  *  API's : WinDlgBox
  157.  *
  158.  *  Parameters :  mp1 - First message parameter
  159.  *                mp2 - Second message parameter
  160.  *
  161.  *  Returns: Void
  162.  *
  163.  ****************************************************************/
  164. VOID UserCommand(MPARAM mp1, MPARAM mp2)
  165. {
  166.    switch(SHORT1FROMMP(mp1))
  167.    {
  168.       case IDM_OPTIONSFORECOLORBLACK:
  169.       case IDM_OPTIONSFORECOLORBLUE:
  170.       case IDM_OPTIONSFORECOLORRED:
  171.       case IDM_OPTIONSFORECOLORDEFAULT:
  172.           SetForegroundColor(SHORT1FROMMP(mp1));
  173.           break;
  174.  
  175.       case IDM_OPTIONSBACKCOLORPINK:
  176.       case IDM_OPTIONSBACKCOLORCYAN:
  177.       case IDM_OPTIONSBACKCOLORYELLOW:
  178.       case IDM_OPTIONSBACKCOLORDEFAULT:
  179.           SetBackgroundColor(SHORT1FROMMP(mp1));
  180.           break;
  181.  
  182.       case IDM_OPTIONSFONT:
  183.           SetFont();
  184.           break;
  185.  
  186.       case IDM_DEMODLGBUTTONS:
  187.       case IDM_DEMODLGLISTBOXES:
  188.       case IDM_DEMODLGCOMBOBOXES:
  189.       case IDM_DEMODLGENTRYFIELDS:
  190.       case IDM_DEMODLGSTATIC:
  191.       case IDM_DEMODLGSLIDER:
  192.       case IDM_DEMODLGSPINBUTTON:
  193.       case IDM_DEMODLGVALUESET:
  194.       case IDM_DEMODLGNOTEBOOK:
  195.       case IDM_DEMODLGCONTAINER:
  196.           ShowDemoDlg(SHORT1FROMMP(mp1));
  197.           break;
  198.  
  199.       case IDM_DEMOMSGBOXOK:
  200.       case IDM_DEMOMSGBOXOKCANCEL:
  201.       case IDM_DEMOMSGBOXYESNO:
  202.       case IDM_DEMOMSGBOXYESNOCANCEL:
  203.       case IDM_DEMOMSGBOXRETRYCANCEL:
  204.       case IDM_DEMOMSGBOXABORT:
  205.       case IDM_DEMOMSGBOXENTER:
  206.       case IDM_DEMOMSGBOXENTERCANCEL:
  207.       case IDM_DEMOMSGBOXQUERY:
  208.       case IDM_DEMOMSGBOXWARNING:
  209.       case IDM_DEMOMSGBOXINFO:
  210.       case IDM_DEMOMSGBOXCRITICAL:
  211.       case IDM_DEMOMSGBOXAPP:
  212.       case IDM_DEMOMSGBOXSYS:
  213.       case IDM_DEMOMSGBOXHELP:
  214.           ShowDemoMsgBox(SHORT1FROMMP(mp1));
  215.           break;
  216.  
  217.       case IDM_DEMODLGPP:
  218.           WinDlgBox(hwndMain, hwndMain, (PFNWP)PresParamDemoDlgProc,
  219.                     (HMODULE)0, IDD_PPDEMODLG, (PVOID)NULL);
  220.           break;
  221.  
  222.       default:
  223.           break;
  224.    }
  225.  /*
  226.   * This routine currently doesn't use the mp2 parameter but
  227.   * it is referenced here to prevent an 'Unreferenced Parameter'
  228.   * warning at compile time.
  229.   */
  230.   mp2;
  231. }   /*    End of UserCommand()                                          */
  232.  
  233. /*********************************************************************
  234.  *  Name: InitMenu
  235.  *
  236.  *  Description : Processes the WM_INITMENU message for the main
  237.  *                window, disabling any menus that are not active
  238.  *
  239.  *  Concepts : Routine is called each time a menu is selected.  A
  240.  *             switch statement branches control based upon the
  241.  *             id of the menu which is being displayed.
  242.  *
  243.  *  API's : WinSendMsg
  244.  *          WinOpenClipbrd
  245.  *          WinQueryClipbrdFmtInfo
  246.  *          WinCloseClipbrd
  247.  *
  248.  *  Parameters :  mp1 - First message parameter
  249.  *                mp2 - Second message parameter
  250.  *
  251.  *  Returns: Nome
  252.  *
  253.  ****************************************************************/
  254. VOID InitMenu( MPARAM mp1, MPARAM mp2)
  255. {
  256.    ULONG  ulFmtInfo;
  257.    BOOL bEnable;
  258.    MRESULT mr1, mr2;
  259.  
  260.    switch(SHORT1FROMMP(mp1))
  261.    {
  262.       case IDM_HELP:
  263.       /*
  264.        * Enable or disable the Help menu depending upon whether the
  265.        * help manager has been enabled
  266.        */
  267.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPUSINGHELP, fHelpEnabled);
  268.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPGENERAL, fHelpEnabled);
  269.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPKEYS, fHelpEnabled);
  270.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPINDEX, fHelpEnabled);
  271.          break;
  272.  
  273.       case IDM_EDIT:
  274.       /*
  275.        * if text is selected in the MLE, the enable the Cut, Copy,
  276.        * and Clear menus.  Otherwise, do not
  277.        */
  278.          mr1 = WinSendMsg(hwndMLE, MLM_QUERYSEL,
  279.                            MPFROMSHORT(MLFQS_MINSEL), NULL);
  280.  
  281.          mr2 = WinSendMsg(hwndMLE, MLM_QUERYSEL,
  282.                            MPFROMSHORT(MLFQS_MAXSEL), NULL);
  283.  
  284.          if (mr1 != mr2)
  285.             bEnable = TRUE;
  286.          else
  287.             bEnable = FALSE;
  288.  
  289.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCUT, bEnable);
  290.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCOPY, bEnable);
  291.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCLEAR, bEnable);
  292.  
  293.          /*
  294.           * determine if the MLE can Undo the last action.  If it can't,
  295.           * then disable he Undo menu
  296.           */
  297.  
  298.          mr1 =  WinSendMsg(hwndMLE, MLM_QUERYUNDO, NULL, NULL);
  299.          if (mr1 != 0)
  300.             bEnable = TRUE;
  301.          else
  302.             bEnable = FALSE;
  303.  
  304.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITUNDO, bEnable);
  305.  
  306.          /*
  307.           * determine if the clipboard has some text on it.  If it
  308.           * doesn't, then disable the Paste menu
  309.           */
  310.          if(WinOpenClipbrd(hab))
  311.          {
  312.            if (WinQueryClipbrdFmtInfo(hab, CF_TEXT, &ulFmtInfo))
  313.               bEnable = TRUE;
  314.            else
  315.               bEnable = FALSE;
  316.            WinCloseClipbrd(hab);
  317.          }
  318.          else
  319.             bEnable = TRUE;
  320.  
  321.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITPASTE, bEnable);
  322.          break;
  323.  
  324.       case IDM_OPTIONSFORECOLOR:
  325.          {
  326.           LONG lColor;
  327.           BOOL bBlack = TRUE;
  328.           BOOL bBlue = TRUE;
  329.           BOOL bRed = TRUE;
  330.           BOOL bDefault = TRUE;
  331.  
  332.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYTEXTCOLOR, NULL, NULL);
  333.           switch (lColor)
  334.           {
  335.              case CLR_BLACK:
  336.                 bBlack = FALSE;
  337.                 break;
  338.              case CLR_BLUE:
  339.                 bBlue = FALSE;
  340.                 break;
  341.              case CLR_RED:
  342.                 bRed = FALSE;
  343.                 break;
  344.              default:
  345.                 bDefault = FALSE;
  346.                 break;
  347.            }
  348.  
  349.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLACK,
  350.                            bBlack);
  351.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLUE, bBlue);
  352.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORRED, bRed);
  353.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORDEFAULT,
  354.                            bDefault);
  355.          }
  356.          break;
  357.       case IDM_OPTIONSBACKCOLOR:
  358.          {
  359.           LONG lColor;
  360.           BOOL bYellow = TRUE;
  361.           BOOL bPink = TRUE;
  362.           BOOL bCyan = TRUE;
  363.           BOOL bDefault = TRUE;
  364.  
  365.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYBACKCOLOR, NULL, NULL);
  366.           switch (lColor)
  367.           {
  368.              case CLR_YELLOW:
  369.                 bYellow = FALSE;
  370.                 break;
  371.              case CLR_PINK:
  372.                 bPink = FALSE;
  373.                 break;
  374.              case CLR_CYAN:
  375.                 bCyan = FALSE;
  376.                 break;
  377.              default:
  378.                 bDefault = FALSE;
  379.                 break;
  380.            }
  381.  
  382.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORYELLOW,
  383.                            bYellow);
  384.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORPINK, bPink);
  385.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORCYAN, bCyan);
  386.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORDEFAULT,
  387.                            bDefault);
  388.          }
  389.          break;
  390.  
  391.       default:
  392.           break;
  393.    }
  394. }   /*       End of InitMenu()                                          */
  395.  
  396. /*********************************************************************
  397.  *  Name: EnableMenuItem
  398.  *
  399.  *  Description : Enables or disables menu item.
  400.  *
  401.  *  Concepts : Called whenever a menu item is to be enabled or
  402.  *             disabled.  Sends a MM_SETITEMATTR to the menu with
  403.  *             the given item id.  Sets the MIA_DISABLED
  404.  *             attribute flag if the item is to be disabled,
  405.  *             clears the flag if enabling.
  406.  *
  407.  *  API's : WinSendMsg
  408.  *
  409.  *  Parameters   : hwnd - Window handle of the menu
  410.  *                 sIditem  - Id of the menu item.
  411.  *                 bEnable - Enable/Disable flag
  412.  *
  413.  *  Returns: Void
  414.  *
  415.  ****************************************************************/
  416. VOID EnableMenuItem( HWND hwndMenu, SHORT sIditem, BOOL bEnable)
  417. {
  418.   SHORT sFlag;
  419.  
  420.   if(bEnable)
  421.     sFlag = 0;
  422.   else
  423.     sFlag = MIA_DISABLED;
  424.  
  425.   WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(sIditem, TRUE),
  426.                MPFROM2SHORT(MIA_DISABLED, sFlag));
  427.  
  428. }   /*         End of EnableMenuItem()                                  */
  429.  
  430. /*********************************************************************
  431.  *  Name: ShowDemoDlg
  432.  *
  433.  *  Description : Displays the demonstration dialog for the menu
  434.  *                id chosen.
  435.  *
  436.  *  Concepts : Called whenever a menu item from the Dialog Box
  437.  *             menu of the Demo menu is selected.  Determines the
  438.  *             id of the dialog template and creates a dialog of
  439.  *             that template.
  440.  *
  441.  *  API's : WinDlgBox
  442.  *
  443.  *  Parameters :   sIdMenuItem - Id of the menu item.
  444.  *
  445.  *  Returns: Void
  446.  *
  447.  ****************************************************************/
  448. VOID ShowDemoDlg( SHORT sIdMenuItem)
  449. {
  450.   static SHORT sIdDlg;
  451.  
  452.   switch(sIdMenuItem)
  453.   {
  454.      case IDM_DEMODLGBUTTONS:
  455.          sIdDlg = IDD_BUTTONSDLG;
  456.          break;
  457.  
  458.      case IDM_DEMODLGLISTBOXES:
  459.          sIdDlg = IDD_LISTBOXDLG;
  460.          break;
  461.  
  462.      case IDM_DEMODLGCOMBOBOXES:
  463.          sIdDlg = IDD_COMBOBOXDLG;
  464.          break;
  465.  
  466.      case IDM_DEMODLGENTRYFIELDS:
  467.          sIdDlg = IDD_ENTRYFIELDDLG;
  468.          break;
  469.  
  470.      case IDM_DEMODLGSTATIC:
  471.          sIdDlg = IDD_STATICDLG;
  472.          break;
  473.  
  474.      case IDM_DEMODLGSLIDER:
  475.          sIdDlg = IDD_SLIDERDLG;
  476.          break;
  477.  
  478.      case IDM_DEMODLGSPINBUTTON:
  479.          sIdDlg = IDD_SPINBUTTONDLG;
  480.          break;
  481.  
  482.      case IDM_DEMODLGVALUESET:
  483.          sIdDlg = IDD_VALUESETDLG;
  484.          break;
  485.  
  486.      case IDM_DEMODLGNOTEBOOK:
  487.          sIdDlg = IDD_NOTEBOOKDLG;
  488.          break;
  489.      case IDM_DEMODLGCONTAINER:
  490.          sIdDlg = IDD_CONTAINERDLG;
  491.          break;
  492.  
  493.      default:    /* unknown menu id */
  494.          return;
  495.          break;
  496.   }
  497.  
  498.   WinDlgBox(HWND_DESKTOP, hwndMain,
  499.            (PFNWP)DemoDlgProc,          /* all demos use DemoDlgProc    */
  500.            (HMODULE)0,
  501.            sIdDlg,                      /* id of template               */
  502.            (PVOID)&sIdDlg);             /* pass id as mp2 of WM_INITDLG */
  503.  
  504. }   /*      End of ShowDemoDlg()                                        */
  505.  
  506.  
  507. /*********************************************************************
  508.  *  Name: ShowDemoMsgBox
  509.  *
  510.  *  Description : Displays the demonstration message box for the menu
  511.  *                id chosen.
  512.  *
  513.  *  Concepts :  Called whenever a menu item from the Message Box menu
  514.  *              of the Demo menu is selected.  Determines the options
  515.  *              for the message box and then creates the box.
  516.  *
  517.  *  API's : WinLoadString
  518.  *          WinMessageBox
  519.  *
  520.  *  Parameters : sIdMenuItem - Id of the menu item.
  521.  *
  522.  *  Returns: VOID
  523.  *
  524.  ****************************************************************/
  525. VOID ShowDemoMsgBox( SHORT sIdMenuItem)
  526. {
  527.   SHORT sOptions, sIdText;
  528.   CHAR szText[MESSAGELEN];
  529.  
  530.   switch(sIdMenuItem)
  531.   {
  532.      case IDM_DEMOMSGBOXOK:
  533.         sOptions = MB_OK | MB_MOVEABLE;
  534.         sIdText = IDS_DEMOMSGBOXOK;
  535.         break;
  536.  
  537.      case IDM_DEMOMSGBOXOKCANCEL:
  538.         sOptions = MB_OKCANCEL | MB_MOVEABLE;
  539.         sIdText = IDS_DEMOMSGBOXOKCANCEL;
  540.         break;
  541.  
  542.      case IDM_DEMOMSGBOXYESNO:
  543.         sOptions = MB_YESNO | MB_MOVEABLE;
  544.         sIdText = IDS_DEMOMSGBOXYESNO;
  545.         break;
  546.  
  547.      case IDM_DEMOMSGBOXYESNOCANCEL:
  548.         sOptions = MB_YESNOCANCEL | MB_MOVEABLE;
  549.         sIdText = IDS_DEMOMSGBOXYESNOCANCEL;
  550.         break;
  551.  
  552.      case IDM_DEMOMSGBOXRETRYCANCEL:
  553.         sOptions = MB_RETRYCANCEL | MB_MOVEABLE;
  554.         sIdText = IDS_DEMOMSGBOXRETRYCANCEL;
  555.         break;
  556.  
  557.      case IDM_DEMOMSGBOXABORT:
  558.         sOptions = MB_ABORTRETRYIGNORE | MB_MOVEABLE;
  559.         sIdText = IDS_DEMOMSGBOXABORT;
  560.         break;
  561.  
  562.      case IDM_DEMOMSGBOXENTER:
  563.         sOptions = MB_ENTER | MB_MOVEABLE;
  564.         sIdText = IDS_DEMOMSGBOXENTER;
  565.         break;
  566.  
  567.      case IDM_DEMOMSGBOXENTERCANCEL:
  568.         sOptions = MB_ENTERCANCEL | MB_MOVEABLE;
  569.         sIdText = IDS_DEMOMSGBOXENTERCANCEL;
  570.         break;
  571.  
  572.      case IDM_DEMOMSGBOXQUERY:
  573.         sOptions = MB_OK | MB_QUERY | MB_MOVEABLE;
  574.         sIdText = IDS_DEMOMSGBOXQUERY;
  575.         break;
  576.  
  577.      case IDM_DEMOMSGBOXWARNING:
  578.         sOptions = MB_OK | MB_WARNING | MB_MOVEABLE;
  579.         sIdText = IDS_DEMOMSGBOXWARNING;
  580.         break;
  581.  
  582.      case IDM_DEMOMSGBOXINFO:
  583.         sOptions = MB_OK | MB_INFORMATION | MB_MOVEABLE;
  584.         sIdText = IDS_DEMOMSGBOXINFO;
  585.         break;
  586.  
  587.      case IDM_DEMOMSGBOXCRITICAL:
  588.         sOptions = MB_OK | MB_CRITICAL | MB_MOVEABLE;
  589.         sIdText = IDS_DEMOMSGBOXCRITICAL;
  590.         break;
  591.  
  592.      case IDM_DEMOMSGBOXAPP:
  593.         sOptions = MB_OK | MB_APPLMODAL | MB_MOVEABLE;
  594.         sIdText = IDS_DEMOMSGBOXAPP;
  595.         break;
  596.  
  597.      case IDM_DEMOMSGBOXSYS:
  598.         sOptions = MB_OK | MB_SYSTEMMODAL | MB_MOVEABLE;
  599.         sIdText = IDS_DEMOMSGBOXSYS;
  600.         break;
  601.  
  602.      case IDM_DEMOMSGBOXHELP:
  603.         sOptions = MB_OK | MB_HELP | MB_MOVEABLE;
  604.         sIdText = IDS_DEMOMSGBOXHELP;
  605.         break;
  606.  
  607.      default:
  608.         /*
  609.         * Unknown menu id
  610.         */
  611.         return;
  612.         break;
  613.   }
  614.  
  615.   /*
  616.   * Get the text for the message box
  617.   */
  618.   if(!WinLoadString(hab, (HMODULE)0, sIdText, MESSAGELEN, (PSZ)szText))
  619.   {
  620.      MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  621.         return;
  622.   }
  623.  
  624.   /* bring up the message box                                           */
  625.   WinMessageBox(HWND_DESKTOP, hwndMain, szText, szAppName, IDD_DEMOMSGBOX,
  626.                 sOptions);
  627.  
  628. }   /*   End of ShowDemoMsgBox()                                        */
  629.  
  630. /*********************************************************************
  631.  *  Name: SetForegroundColor
  632.  *
  633.  *  Description : Allows the user to select a color for the
  634.  *                window foreground
  635.  *
  636.  *  Concepts : Routine is called each time the user selects one
  637.  *             of the Foreground colors listed in the Foreground
  638.  *             Color submenu of the Options menu.  A switch
  639.  *             statement determines which menu item was chosen
  640.  *             and then the appropriate color is placed into
  641.  *             lClrForeground.
  642.  *
  643.  *  API's : WinSendMsg
  644.  *
  645.  *  Parameters : sIdItem - Id of the menu item.
  646.  *
  647.  *  Returns: Void
  648.  *
  649.  ****************************************************************/
  650. VOID SetForegroundColor(SHORT sIdMenu)
  651. {
  652.    switch(sIdMenu)
  653.    {
  654.       case IDM_OPTIONSFORECOLORBLACK:
  655.          lClrForeground = CLR_BLACK;
  656.          break;
  657.  
  658.       case IDM_OPTIONSFORECOLORBLUE:
  659.          lClrForeground = CLR_BLUE;
  660.          break;
  661.  
  662.       case IDM_OPTIONSFORECOLORRED:
  663.          lClrForeground = CLR_RED;
  664.          break;
  665.  
  666.       /*
  667.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  668.        *  the background color to the default back color
  669.        */
  670.       default:
  671.          lClrForeground = lClrDefaultForeground;
  672.          break;
  673.    }
  674.    WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(lClrForeground), NULL);
  675. }   /*   End of SetForegroundColor()                                    */
  676.  
  677. /*********************************************************************
  678.  *  Name: SetBackgroundColor
  679.  *
  680.  *  Description : Allows the user to select a color for the
  681.  *                window Background
  682.  *
  683.  *  Concepts : Routine is called each time the user selects one
  684.  *             of the Background colors listed in the Background
  685.  *             Color submenu of the Options menu.  A switch
  686.  *             statement determines which menu item was chosen
  687.  *             and then the appropriate color is placed into
  688.  *             lClrBackground.
  689.  *
  690.  *  API's : WinSendMsg
  691.  *
  692.  *  Parameters : sIdItem - Id of the menu item.
  693.  *
  694.  *  Returns: Void
  695.  *
  696.  ****************************************************************/
  697. VOID SetBackgroundColor( SHORT idMenu)
  698. {
  699.    switch(idMenu)
  700.    {
  701.       case IDM_OPTIONSBACKCOLORPINK:
  702.          lClrBackground = CLR_PINK;
  703.          break;
  704.  
  705.       case IDM_OPTIONSBACKCOLORCYAN:
  706.          lClrBackground = CLR_CYAN;
  707.          break;
  708.  
  709.       case IDM_OPTIONSBACKCOLORYELLOW:
  710.          lClrBackground = CLR_YELLOW;
  711.          break;
  712.  
  713.       /*
  714.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  715.        *  the background color to the default back color
  716.        */
  717.       default:
  718.          lClrBackground = lClrDefaultBackground;
  719.          break;
  720.    }
  721.    WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(lClrBackground), NULL);
  722. }   /*  End of SetBackgroundColor()                                     */
  723.  
  724.  
  725. /*********************************************************************
  726.  *  Name: SetFont
  727.  *
  728.  *  Description : Allows the user to select a font for the text
  729.  *                displayed in the MLE.
  730.  *
  731.  *  Concepts : Routine is called each time the user selects the
  732.  *             Font menu item from the Options menu.  The
  733.  *             standard font dialog is called with the current
  734.  *             available fonts.  If the user selects one, then
  735.  *             the MLM_SETFONT message is sent to the MLE to
  736.  *             display its text to the font chosen.
  737.  *
  738.  *  API's : WinSendMsg
  739.  *          GpiCreateLogFont
  740.  *          GpiSetCharSet
  741.  *          GpiQueryFontMetrics
  742.  *          GpiDeleteSetId
  743.  *          WinGetPS
  744.  *          WinReleasePS
  745.  *          WinLoadString
  746.  *          WinFontDlg
  747.  *
  748.  *  Parameters :  None
  749.  *
  750.  *  Returns: None
  751.  *
  752.  ****************************************************************/
  753. VOID SetFont(void)
  754. {
  755.    FONTDLG fontDlg;
  756.    HWND hwndFontDlg;
  757.    HPS hpsMLE;
  758.    FONTMETRICS fontMetrics;
  759.    CHAR szTitle[MESSAGELEN];
  760.    CHAR szFamily[CCHMAXPATH];
  761.    static fxPointSize = 0;            /* keep track of this for vector fonts */
  762.  
  763.    memset(&fontDlg, 0, sizeof(fontDlg));            /* initialize all fields */
  764.    /*
  765.     * Get the current font attributes
  766.     */
  767.    hpsMLE = WinGetPS(hwndMLE);
  768.    WinSendMsg(hwndMLE, MLM_QUERYFONT,
  769.       MPFROMP((PFATTRS)&(fontDlg.fAttrs)), NULL);
  770.  
  771.    /* create system default font */
  772.  
  773.    GpiCreateLogFont(
  774.       hpsMLE,
  775.       (PSTR8)fontDlg.fAttrs.szFacename,
  776.       1,
  777.       &(fontDlg.fAttrs));
  778.  
  779.    GpiSetCharSet(hpsMLE, 1);
  780.  
  781.    GpiQueryFontMetrics(hpsMLE, sizeof(FONTMETRICS), &fontMetrics);
  782.  
  783.    GpiSetCharSet(hpsMLE, LCID_DEFAULT);
  784.    GpiDeleteSetId(hpsMLE, 1);
  785.    WinReleasePS(hpsMLE);
  786.    if(!WinLoadString(hab, (HMODULE)0, IDS_FONTDLGTITLE, MESSAGELEN, szTitle))
  787.    {
  788.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  789.       return;
  790.    }
  791.  
  792.    /*
  793.     * Initialize the FONTDLG structure with the current font
  794.     */
  795.    fontDlg.cbSize     = sizeof(FONTDLG);                  /* sizeof(FONTDLG) */
  796.    fontDlg.hpsScreen  = WinGetScreenPS(HWND_DESKTOP);  /* Screen presentation space */
  797.    fontDlg.hpsPrinter = NULLHANDLE;            /* Printer presentation space */
  798.    fontDlg.pszTitle      = szTitle;       /* Application supplied title      */
  799.    fontDlg.pszPreview    = NULL;          /* String to print in preview wndw */
  800.    fontDlg.pszPtSizeList = NULL;          /* Application provided size list  */
  801.    fontDlg.pfnDlgProc    = NULL;          /* Dialog subclass procedure       */
  802.    strcpy(szFamily, fontMetrics.szFamilyname); /* Family name of font        */
  803.    fontDlg.pszFamilyname = szFamily;      /* point to Family name of font    */
  804.    fontDlg.fxPointSize = fxPointSize;     /* Point size the user selected    */
  805.    fontDlg.fl           = FNTS_CENTER |   /* FNTS_* flags - dialog styles    */
  806.                            FNTS_INITFROMFATTRS;
  807.    fontDlg.flFlags      = 0;              /* FNTF_* state flags              */
  808.                                           /* Font type option bits           */
  809.    fontDlg.flType       = (LONG) fontMetrics.fsType;
  810.    fontDlg.flTypeMask   = 0;              /* Mask of which font types to use */
  811.    fontDlg.flStyle      = 0;              /* The selected style bits         */
  812.    fontDlg.flStyleMask  = 0;              /* Mask of which style bits to use */
  813.    fontDlg.clrFore      = lClrForeground; /* Selected foreground color       */
  814.    fontDlg.clrBack      = lClrBackground; /* Selected background color       */
  815.    fontDlg.ulUser       = 0;              /* Blank field for application     */
  816.    fontDlg.lReturn      = 0;              /* Return Value of the Dialog      */
  817.    fontDlg.lSRC;                          /* System return code.             */
  818.    fontDlg.lEmHeight    = 0;              /* Em height of the current font   */
  819.    fontDlg.lXHeight     = 0;              /* X height of the current font    */
  820.    fontDlg.lExternalLeading = 0;          /* External Leading of font        */
  821.    fontDlg.hMod;                          /* Module to load custom template  */
  822.                                           /* Nominal Point Size of font      */
  823.    fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize;
  824.    fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */
  825.    fontDlg.usWidth = fontMetrics.usWidthClass;  /* The width of the font     */
  826.    fontDlg.x            = 0;              /* X coordinate of the dialog      */
  827.    fontDlg.y            = 0;              /* Y coordinate of the dialog      */
  828.    fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */
  829.    fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */
  830.    fontDlg.fAttrs;                        /* Font attribute structure        */
  831.  
  832.    /*
  833.     *   Bring up the standard Font Dialog
  834.     */
  835.  
  836.    hwndFontDlg = WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg); 
  837.  
  838.    if(fontDlg.lReturn != DID_OK)          /* check reason for return         */
  839.    {
  840.       WinReleasePS(fontDlg.hpsScreen);
  841.       return;
  842.    }
  843.    fxPointSize = fontDlg.fxPointSize;     /* save point size for next dialog */
  844.  
  845.    /*
  846.     *   If outline font, calculate the maxbaselineext and
  847.     *   avecharwidth for the point size selected
  848.     */
  849.  
  850.    if ( fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE )
  851.    {
  852.       ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
  853.    }
  854.  
  855.    /*
  856.     *   Query FONTMETRICS again to determine if font has been ISO9241
  857.     *   tested and if it complies to the ISO9241 standard.
  858.     */
  859.  
  860.    hpsMLE = WinGetPS(hwndMLE);
  861.    GpiQueryFontMetrics(hpsMLE, sizeof(FONTMETRICS), &fontMetrics);
  862.  
  863.    if (fontMetrics.fsSelection & FM_SEL_ISO9241_TESTED)
  864.    {
  865.       /*
  866.        *   Values of fbPassed/FailedISO field in the PANOSE structure below
  867.        *   indicate if any displays with ISO support pass/fail compliance test.
  868.        *   If desired, you could also determine the display type to narrow
  869.        *   down which of the following bit tests are necessary.
  870.        */
  871.  
  872.       if ((fontMetrics.panose.fbFailedISO & FM_ISO_9515_640 ) &&
  873.           (fontMetrics.panose.fbFailedISO & FM_ISO_9515_1024) &&
  874.           (fontMetrics.panose.fbFailedISO & FM_ISO_9517_640 ) &&
  875.           (fontMetrics.panose.fbFailedISO & FM_ISO_9517_1024) &&
  876.           (fontMetrics.panose.fbFailedISO & FM_ISO_9518_640 ))
  877.       {
  878.          /*
  879.           *   font selected fails ISO compliance test on all diplays
  880.           *   tested above.
  881.           */
  882.          MessageBox(hwndMain, IDMSG_ISOFAILED, MB_OK | MB_WARNING, FALSE);
  883.       }
  884.    }
  885.    else
  886.    {  /* font isn't tested for ISO compliance */
  887.       MessageBox(hwndMain, IDMSG_ISONOTTESTED, MB_OK | MB_WARNING, FALSE);
  888.    }
  889.  
  890.    WinReleasePS(fontDlg.hpsScreen);
  891.    WinReleasePS(hpsMLE);
  892.    WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), NULL);
  893.  
  894. }   /* End of SetFont()                                                 */
  895.  
  896. /*
  897.  *   Convert vector font size using point size and fAttrs structure and
  898.  *   return it in that structure.
  899.  */
  900.  
  901. VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs)
  902. {
  903.   HPS   hps;
  904.   HDC   hDC;
  905.   LONG  lxFontResolution;
  906.   LONG  lyFontResolution;
  907.   SIZEF sizef;
  908.  
  909.   hps = WinGetScreenPS(HWND_DESKTOP);        /* Screen presentation space */
  910.  
  911.   /*
  912.    *   Query device context for the screen and then query
  913.    *   the resolution of the device for the device context.
  914.    */
  915.  
  916.   hDC = GpiQueryDevice(hps);
  917.   DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lxFontResolution);
  918.   DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lyFontResolution);
  919.  
  920.   /*
  921.    *   Calculate the size of the character box, based on the
  922.    *   point size selected and the resolution of the device.
  923.    *   The size parameters are of type FIXED, NOT int.
  924.    *   NOTE: 1 point == 1/72 of an inch.
  925.    */
  926.  
  927.   sizef.cx = (FIXED)(((fxPointSize) / 72 ) * lxFontResolution );
  928.   sizef.cy = (FIXED)(((fxPointSize) / 72 ) * lyFontResolution );
  929.  
  930.   pfattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( sizef.cy ), 0 );
  931.   pfattrs->lAveCharWidth   = MAKELONG( HIUSHORT( sizef.cx ), 0 );
  932.   WinReleasePS(hps);
  933.  
  934. }   /* end ConvertVectorPointSize() */
  935.