home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / devnews / vol2 / sample3 / sty_user.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-05  |  31.4 KB  |  1,002 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_DEMODLG:
  187.       case IDM_DEMODLGBUTTONS:
  188.       case IDM_DEMODLGLISTBOXES:
  189.       case IDM_DEMODLGCOMBOBOXES:
  190.       case IDM_DEMODLGENTRYFIELDS:
  191.       case IDM_DEMODLGSTATIC:
  192.       case IDM_DEMODLGSLIDER:
  193.       case IDM_DEMODLGSPINBUTTON:
  194.       case IDM_DEMODLGVALUESET:
  195.       case IDM_DEMODLGNOTEBOOK:
  196.       case IDM_DEMODLGCONTAINER:
  197.       case IDM_DEMOBROADCASTDLG:
  198.           ShowDemoDlg(SHORT1FROMMP(mp1));
  199.           break;
  200.  
  201.       case IDM_DEMOMSGBOXOK:
  202.       case IDM_DEMOMSGBOXOKCANCEL:
  203.       case IDM_DEMOMSGBOXYESNO:
  204.       case IDM_DEMOMSGBOXYESNOCANCEL:
  205.       case IDM_DEMOMSGBOXRETRYCANCEL:
  206.       case IDM_DEMOMSGBOXABORT:
  207.       case IDM_DEMOMSGBOXENTER:
  208.       case IDM_DEMOMSGBOXENTERCANCEL:
  209.       case IDM_DEMOMSGBOXQUERY:
  210.       case IDM_DEMOMSGBOXWARNING:
  211.       case IDM_DEMOMSGBOXINFO:
  212.       case IDM_DEMOMSGBOXCRITICAL:
  213.       case IDM_DEMOMSGBOXAPP:
  214.       case IDM_DEMOMSGBOXSYS:
  215.       case IDM_DEMOMSGBOXHELP:
  216.           ShowDemoMsgBox(SHORT1FROMMP(mp1));
  217.           break;
  218.       /*
  219.        *message dialog box
  220.        *to send/receive messages
  221.        */
  222.       case IDM_DEMODLGPP:
  223.           WinDlgBox(hwndMain, hwndMain, (PFNWP)PresParamDemoDlgProc,
  224.                     (HMODULE)0, IDD_PPDEMODLG, (PVOID)NULL);
  225.           break;
  226.  
  227.       default:
  228.           break;
  229.    }
  230.  /*
  231.   * This routine currently doesn't use the mp2 parameter but
  232.   * it is referenced here to prevent an 'Unreferenced Parameter'
  233.   * warning at compile time.
  234.   */
  235.   mp2;
  236. }   /*    End of UserCommand()                                          */
  237.  
  238. /*********************************************************************
  239.  *  Name: InitMenu
  240.  *
  241.  *  Description : Processes the WM_INITMENU message for the main
  242.  *                window, disabling any menus that are not active
  243.  *
  244.  *  Concepts : Routine is called each time a menu is selected.  A
  245.  *             switch statement branches control based upon the
  246.  *             id of the menu which is being displayed.
  247.  *
  248.  *  API's : WinSendMsg
  249.  *          WinOpenClipbrd
  250.  *          WinQueryClipbrdFmtInfo
  251.  *          WinCloseClipbrd
  252.  *
  253.  *  Parameters :  mp1 - First message parameter
  254.  *                mp2 - Second message parameter
  255.  *
  256.  *  Returns: Nome
  257.  *
  258.  ****************************************************************/
  259. VOID InitMenu( MPARAM mp1, MPARAM mp2)
  260. {
  261.    ULONG  ulFmtInfo;
  262.    BOOL bEnable;
  263.    MRESULT mr1, mr2;
  264.  
  265.    switch(SHORT1FROMMP(mp1))
  266.    {
  267.       case IDM_HELP:
  268.       /*
  269.        * Enable or disable the Help menu depending upon whether the
  270.        * help manager has been enabled
  271.        */
  272.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPUSINGHELP, fHelpEnabled);
  273.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPGENERAL, fHelpEnabled);
  274.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPKEYS, fHelpEnabled);
  275.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPINDEX, fHelpEnabled);
  276.          break;
  277.  
  278.       case IDM_EDIT:
  279.       /*
  280.        * if text is selected in the MLE, the enable the Cut, Copy,
  281.        * and Clear menus.  Otherwise, do not
  282.        */
  283.          mr1 = WinSendMsg(hwndMLE, MLM_QUERYSEL,
  284.                            MPFROMSHORT(MLFQS_MINSEL), NULL);
  285.  
  286.          mr2 = WinSendMsg(hwndMLE, MLM_QUERYSEL,
  287.                            MPFROMSHORT(MLFQS_MAXSEL), NULL);
  288.  
  289.          if (mr1 != mr2)
  290.             bEnable = TRUE;
  291.          else
  292.             bEnable = FALSE;
  293.  
  294.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCUT, bEnable);
  295.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCOPY, bEnable);
  296.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCLEAR, bEnable);
  297.  
  298.          /*
  299.           * determine if the MLE can Undo the last action.  If it can't,
  300.           * then disable he Undo menu
  301.           */
  302.  
  303.          mr1 =  WinSendMsg(hwndMLE, MLM_QUERYUNDO, NULL, NULL);
  304.          if (mr1 != 0)
  305.             bEnable = TRUE;
  306.          else
  307.             bEnable = FALSE;
  308.  
  309.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITUNDO, bEnable);
  310.  
  311.          /*
  312.           * determine if the clipboard has some text on it.  If it
  313.           * doesn't, then disable the Paste menu
  314.           */
  315.          if(WinOpenClipbrd(hab))
  316.          {
  317.            if (WinQueryClipbrdFmtInfo(hab, CF_TEXT, &ulFmtInfo))
  318.               bEnable = TRUE;
  319.            else
  320.               bEnable = FALSE;
  321.            WinCloseClipbrd(hab);
  322.          }
  323.          else
  324.             bEnable = TRUE;
  325.  
  326.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITPASTE, bEnable);
  327.          break;
  328.  
  329.       case IDM_OPTIONSFORECOLOR:
  330.          {
  331.           LONG lColor;
  332.           BOOL bBlack = TRUE;
  333.           BOOL bBlue = TRUE;
  334.           BOOL bRed = TRUE;
  335.           BOOL bDefault = TRUE;
  336.  
  337.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYTEXTCOLOR, NULL, NULL);
  338.           switch (lColor)
  339.           {
  340.              case CLR_BLACK:
  341.                 bBlack = FALSE;
  342.                 break;
  343.              case CLR_BLUE:
  344.                 bBlue = FALSE;
  345.                 break;
  346.              case CLR_RED:
  347.                 bRed = FALSE;
  348.                 break;
  349.              default:
  350.                 bDefault = FALSE;
  351.                 break;
  352.            }
  353.  
  354.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLACK,
  355.                            bBlack);
  356.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLUE, bBlue);
  357.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORRED, bRed);
  358.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORDEFAULT,
  359.                            bDefault);
  360.          }
  361.          break;
  362.       case IDM_OPTIONSBACKCOLOR:
  363.          {
  364.           LONG lColor;
  365.           BOOL bYellow = TRUE;
  366.           BOOL bPink = TRUE;
  367.           BOOL bCyan = TRUE;
  368.           BOOL bDefault = TRUE;
  369.  
  370.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYBACKCOLOR, NULL, NULL);
  371.           switch (lColor)
  372.           {
  373.              case CLR_YELLOW:
  374.                 bYellow = FALSE;
  375.                 break;
  376.              case CLR_PINK:
  377.                 bPink = FALSE;
  378.                 break;
  379.              case CLR_CYAN:
  380.                 bCyan = FALSE;
  381.                 break;
  382.              default:
  383.                 bDefault = FALSE;
  384.                 break;
  385.            }
  386.  
  387.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORYELLOW,
  388.                            bYellow);
  389.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORPINK, bPink);
  390.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORCYAN, bCyan);
  391.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORDEFAULT,
  392.                            bDefault);
  393.          }
  394.          break;
  395.  
  396.       default:
  397.           break;
  398.    }
  399. }   /*       End of InitMenu()                                          */
  400.  
  401. /*********************************************************************
  402.  *  Name: EnableMenuItem
  403.  *
  404.  *  Description : Enables or disables menu item.
  405.  *
  406.  *  Concepts : Called whenever a menu item is to be enabled or
  407.  *             disabled.  Sends a MM_SETITEMATTR to the menu with
  408.  *             the given item id.  Sets the MIA_DISABLED
  409.  *             attribute flag if the item is to be disabled,
  410.  *             clears the flag if enabling.
  411.  *
  412.  *  API's : WinSendMsg
  413.  *
  414.  *  Parameters   : hwnd - Window handle of the menu
  415.  *                 sIditem  - Id of the menu item.
  416.  *                 bEnable - Enable/Disable flag
  417.  *
  418.  *  Returns: Void
  419.  *
  420.  ****************************************************************/
  421. VOID EnableMenuItem( HWND hwndMenu, SHORT sIditem, BOOL bEnable)
  422. {
  423.   SHORT sFlag;
  424.  
  425.   if(bEnable)
  426.     sFlag = 0;
  427.   else
  428.     sFlag = MIA_DISABLED;
  429.  
  430.   WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(sIditem, TRUE),
  431.                MPFROM2SHORT(MIA_DISABLED, sFlag));
  432.  
  433. }   /*         End of EnableMenuItem()                                  */
  434.  
  435. /*********************************************************************
  436.  *  Name: ShowDemoDlg
  437.  *
  438.  *  Description : Displays the demonstration dialog for the menu
  439.  *                id chosen.
  440.  *
  441.  *  Concepts : Called whenever a menu item from the Dialog Box
  442.  *             menu of the Demo menu is selected.  Determines the
  443.  *             id of the dialog template and creates a dialog of
  444.  *             that template.
  445.  *
  446.  *  API's : WinDlgBox
  447.  *
  448.  *  Parameters :   sIdMenuItem - Id of the menu item.
  449.  *
  450.  *  Returns: Void
  451.  *
  452.  ****************************************************************/
  453. VOID ShowDemoDlg( SHORT sIdMenuItem)
  454. {
  455.   static SHORT sIdDlg;
  456.  
  457.   switch(sIdMenuItem)
  458.   {
  459.      case IDM_DEMODLG:
  460.          sIdDlg = IDD_BUTTONSDLG;
  461.          break;
  462.  
  463.      case IDM_DEMOBROADCASTDLG:
  464.          sIdDlg = IDD_BROADCASTDLG;
  465.          break;
  466. #if 0
  467.      case IDM_DEMODLGLISTBOXES:
  468.          sIdDlg = IDD_LISTBOXDLG;
  469.          break;
  470.  
  471.      case IDM_DEMODLGCOMBOBOXES:
  472.          sIdDlg = IDD_COMBOBOXDLG;
  473.          break;
  474.  
  475.      case IDM_DEMODLGENTRYFIELDS:
  476.          sIdDlg = IDD_ENTRYFIELDDLG;
  477.          break;
  478.  
  479.      case IDM_DEMODLGSTATIC:
  480.          sIdDlg = IDD_STATICDLG;
  481.          break;
  482.  
  483.      case IDM_DEMODLGSLIDER:
  484.          sIdDlg = IDD_SLIDERDLG;
  485.          break;
  486.  
  487.      case IDM_DEMODLGSPINBUTTON:
  488.          sIdDlg = IDD_SPINBUTTONDLG;
  489.          break;
  490.  
  491.      case IDM_DEMODLGVALUESET:
  492.          sIdDlg = IDD_VALUESETDLG;
  493.          break;
  494.  
  495.      case IDM_DEMODLGNOTEBOOK:
  496.          sIdDlg = IDD_NOTEBOOKDLG;
  497.          break;
  498.      case IDM_DEMODLGCONTAINER:
  499.          sIdDlg = IDD_CONTAINERDLG;
  500.          break;
  501. #endif
  502.  
  503.      default:    /* unknown menu id */
  504.          return;
  505.          break;
  506.   }
  507.  
  508.   WinDlgBox(HWND_DESKTOP, hwndMain,
  509.            (PFNWP)DemoDlgProc,          /* all demos use DemoDlgProc    */
  510.            (HMODULE)0,
  511.            sIdDlg,                      /* id of template               */
  512.            (PVOID)&sIdDlg);             /* pass id as mp2 of WM_INITDLG */
  513.  
  514. }   /*      End of ShowDemoDlg()                                        */
  515.  
  516.  
  517. /*********************************************************************
  518.  *  Name: ShowDemoMsgBox
  519.  *
  520.  *  Description : Displays the demonstration message box for the menu
  521.  *                id chosen.
  522.  *
  523.  *  Concepts :  Called whenever a menu item from the Message Box menu
  524.  *              of the Demo menu is selected.  Determines the options
  525.  *              for the message box and then creates the box.
  526.  *
  527.  *  API's : WinLoadString
  528.  *          WinMessageBox
  529.  *
  530.  *  Parameters : sIdMenuItem - Id of the menu item.
  531.  *
  532.  *  Returns: VOID
  533.  *
  534.  ****************************************************************/
  535. VOID ShowDemoMsgBox( SHORT sIdMenuItem)
  536. {
  537.   SHORT sOptions, sIdText;
  538.   CHAR szText[MESSAGELEN];
  539.  
  540.   switch(sIdMenuItem)
  541.   {
  542.      case IDM_DEMOMSGBOXOK:
  543.         sOptions = MB_OK | MB_MOVEABLE;
  544.         sIdText = IDS_DEMOMSGBOXOK;
  545.         break;
  546.  
  547.      case IDM_DEMOMSGBOXOKCANCEL:
  548.         sOptions = MB_OKCANCEL | MB_MOVEABLE;
  549.         sIdText = IDS_DEMOMSGBOXOKCANCEL;
  550.         break;
  551.  
  552.      case IDM_DEMOMSGBOXYESNO:
  553.         sOptions = MB_YESNO | MB_MOVEABLE;
  554.         sIdText = IDS_DEMOMSGBOXYESNO;
  555.         break;
  556.  
  557.      case IDM_DEMOMSGBOXYESNOCANCEL:
  558.         sOptions = MB_YESNOCANCEL | MB_MOVEABLE;
  559.         sIdText = IDS_DEMOMSGBOXYESNOCANCEL;
  560.         break;
  561.  
  562.      case IDM_DEMOMSGBOXRETRYCANCEL:
  563.         sOptions = MB_RETRYCANCEL | MB_MOVEABLE;
  564.         sIdText = IDS_DEMOMSGBOXRETRYCANCEL;
  565.         break;
  566.  
  567.      case IDM_DEMOMSGBOXABORT:
  568.         sOptions = MB_ABORTRETRYIGNORE | MB_MOVEABLE;
  569.         sIdText = IDS_DEMOMSGBOXABORT;
  570.         break;
  571.  
  572.      case IDM_DEMOMSGBOXENTER:
  573.         sOptions = MB_ENTER | MB_MOVEABLE;
  574.         sIdText = IDS_DEMOMSGBOXENTER;
  575.         break;
  576.  
  577.      case IDM_DEMOMSGBOXENTERCANCEL:
  578.         sOptions = MB_ENTERCANCEL | MB_MOVEABLE;
  579.         sIdText = IDS_DEMOMSGBOXENTERCANCEL;
  580.         break;
  581.  
  582.      case IDM_DEMOMSGBOXQUERY:
  583.         sOptions = MB_OK | MB_QUERY | MB_MOVEABLE;
  584.         sIdText = IDS_DEMOMSGBOXQUERY;
  585.         break;
  586.  
  587.      case IDM_DEMOMSGBOXWARNING:
  588.         sOptions = MB_OK | MB_WARNING | MB_MOVEABLE;
  589.         sIdText = IDS_DEMOMSGBOXWARNING;
  590.         break;
  591.  
  592.      case IDM_DEMOMSGBOXINFO:
  593.         sOptions = MB_OK | MB_INFORMATION | MB_MOVEABLE;
  594.         sIdText = IDS_DEMOMSGBOXINFO;
  595.         break;
  596.  
  597.      case IDM_DEMOMSGBOXCRITICAL:
  598.         sOptions = MB_OK | MB_CRITICAL | MB_MOVEABLE;
  599.         sIdText = IDS_DEMOMSGBOXCRITICAL;
  600.         break;
  601.  
  602.      case IDM_DEMOMSGBOXAPP:
  603.         sOptions = MB_OK | MB_APPLMODAL | MB_MOVEABLE;
  604.         sIdText = IDS_DEMOMSGBOXAPP;
  605.         break;
  606.  
  607.      case IDM_DEMOMSGBOXSYS:
  608.         sOptions = MB_OK | MB_SYSTEMMODAL | MB_MOVEABLE;
  609.         sIdText = IDS_DEMOMSGBOXSYS;
  610.         break;
  611.  
  612.      case IDM_DEMOMSGBOXHELP:
  613.         sOptions = MB_OK | MB_HELP | MB_MOVEABLE;
  614.         sIdText = IDS_DEMOMSGBOXHELP;
  615.         break;
  616.  
  617.      default:
  618.         /*
  619.         * Unknown menu id
  620.         */
  621.         return;
  622.         break;
  623.   }
  624.  
  625.   /*
  626.   * Get the text for the message box
  627.   */
  628.   if(!WinLoadString(hab, (HMODULE)0, sIdText, MESSAGELEN, (PSZ)szText))
  629.   {
  630.      MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  631.         return;
  632.   }
  633.  
  634.   /* bring up the message box                                           */
  635.   WinMessageBox(HWND_DESKTOP, hwndMain, szText, szAppName, IDD_DEMOMSGBOX,
  636.                 sOptions);
  637.  
  638. }   /*   End of ShowDemoMsgBox()                                        */
  639.  
  640. /*********************************************************************
  641.  *  Name: SetForegroundColor
  642.  *
  643.  *  Description : Allows the user to select a color for the
  644.  *                window foreground
  645.  *
  646.  *  Concepts : Routine is called each time the user selects one
  647.  *             of the Foreground colors listed in the Foreground
  648.  *             Color submenu of the Options menu.  A switch
  649.  *             statement determines which menu item was chosen
  650.  *             and then the appropriate color is placed into
  651.  *             lClrForeground.
  652.  *
  653.  *  API's : WinSendMsg
  654.  *
  655.  *  Parameters : sIdItem - Id of the menu item.
  656.  *
  657.  *  Returns: Void
  658.  *
  659.  ****************************************************************/
  660. VOID SetForegroundColor(SHORT sIdMenu)
  661. {
  662.    switch(sIdMenu)
  663.    {
  664.       case IDM_OPTIONSFORECOLORBLACK:
  665.          lClrForeground = CLR_BLACK;
  666.          break;
  667.  
  668.       case IDM_OPTIONSFORECOLORBLUE:
  669.          lClrForeground = CLR_BLUE;
  670.          break;
  671.  
  672.       case IDM_OPTIONSFORECOLORRED:
  673.          lClrForeground = CLR_RED;
  674.          break;
  675.  
  676.       /*
  677.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  678.        *  the background color to the default back color
  679.        */
  680.       default:
  681.          lClrForeground = lClrDefaultForeground;
  682.          break;
  683.    }
  684.    WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(lClrForeground), NULL);
  685. }   /*   End of SetForegroundColor()                                    */
  686.  
  687. /*********************************************************************
  688.  *  Name: SetBackgroundColor
  689.  *
  690.  *  Description : Allows the user to select a color for the
  691.  *                window Background
  692.  *
  693.  *  Concepts : Routine is called each time the user selects one
  694.  *             of the Background colors listed in the Background
  695.  *             Color submenu of the Options menu.  A switch
  696.  *             statement determines which menu item was chosen
  697.  *             and then the appropriate color is placed into
  698.  *             lClrBackground.
  699.  *
  700.  *  API's : WinSendMsg
  701.  *
  702.  *  Parameters : sIdItem - Id of the menu item.
  703.  *
  704.  *  Returns: Void
  705.  *
  706.  ****************************************************************/
  707. VOID SetBackgroundColor( SHORT idMenu)
  708. {
  709.    switch(idMenu)
  710.    {
  711.       case IDM_OPTIONSBACKCOLORPINK:
  712.          lClrBackground = CLR_PINK;
  713.          break;
  714.  
  715.       case IDM_OPTIONSBACKCOLORCYAN:
  716.          lClrBackground = CLR_CYAN;
  717.          break;
  718.  
  719.       case IDM_OPTIONSBACKCOLORYELLOW:
  720.          lClrBackground = CLR_YELLOW;
  721.          break;
  722.  
  723.       /*
  724.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  725.        *  the background color to the default back color
  726.        */
  727.       default:
  728.          lClrBackground = lClrDefaultBackground;
  729.          break;
  730.    }
  731.    WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(lClrBackground), NULL);
  732. }   /*  End of SetBackgroundColor()                                     */
  733.  
  734.  
  735. /*********************************************************************
  736.  *  Name: SetFont
  737.  *
  738.  *  Description : Allows the user to select a font for the text
  739.  *                displayed in the MLE.
  740.  *
  741.  *  Concepts : Routine is called each time the user selects the
  742.  *             Font menu item from the Options menu.  The
  743.  *             standard font dialog is called with the current
  744.  *             available fonts.  If the user selects one, then
  745.  *             the MLM_SETFONT message is sent to the MLE to
  746.  *             display its text to the font chosen.
  747.  *
  748.  *  API's : WinSendMsg
  749.  *          GpiCreateLogFont
  750.  *          GpiSetCharSet
  751.  *          GpiQueryFontMetrics
  752.  *          GpiDeleteSetId
  753.  *          WinGetPS
  754.  *          WinReleasePS
  755.  *          WinLoadString
  756.  *          WinFontDlg
  757.  *
  758.  *  Parameters :  None
  759.  *
  760.  *  Returns: None
  761.  *
  762.  ****************************************************************/
  763. VOID SetFont(void)
  764. {
  765.    FONTDLG fontDlg;
  766.    HWND hwndFontDlg;
  767.    HPS hpsMLE;
  768.    FONTMETRICS fontMetrics;
  769.    CHAR szTitle[MESSAGELEN];
  770.    CHAR szFamily[CCHMAXPATH];
  771.    static fxPointSize = 0;            /* keep track of this for vector fonts */
  772.  
  773.    memset(&fontDlg, 0, sizeof(fontDlg));            /* initialize all fields */
  774.    /*
  775.     * Get the current font attributes
  776.     */
  777.    hpsMLE = WinGetPS(hwndMLE);
  778.    WinSendMsg(hwndMLE, MLM_QUERYFONT,
  779.       MPFROMP((PFATTRS)&(fontDlg.fAttrs)), NULL);
  780.  
  781.    /* create system default font */
  782.  
  783.    GpiCreateLogFont(
  784.       hpsMLE,
  785.       (PSTR8)fontDlg.fAttrs.szFacename,
  786.       1,
  787.       &(fontDlg.fAttrs));
  788.  
  789.    GpiSetCharSet(hpsMLE, 1);
  790.  
  791.    GpiQueryFontMetrics(hpsMLE, sizeof(FONTMETRICS), &fontMetrics);
  792.  
  793.    GpiSetCharSet(hpsMLE, LCID_DEFAULT);
  794.    GpiDeleteSetId(hpsMLE, 1);
  795.    WinReleasePS(hpsMLE);
  796.    if(!WinLoadString(hab, (HMODULE)0, IDS_FONTDLGTITLE, MESSAGELEN, szTitle))
  797.    {
  798.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  799.       return;
  800.    }
  801.  
  802.    /*
  803.     * Initialize the FONTDLG structure with the current font
  804.     */
  805.    fontDlg.cbSize     = sizeof(FONTDLG);                  /* sizeof(FONTDLG) */
  806.    fontDlg.hpsScreen  = WinGetScreenPS(HWND_DESKTOP);  /* Screen presentation space */
  807.    fontDlg.hpsPrinter = NULLHANDLE;            /* Printer presentation space */
  808.    fontDlg.pszTitle      = szTitle;       /* Application supplied title      */
  809.    fontDlg.pszPreview    = NULL;          /* String to print in preview wndw */
  810.    fontDlg.pszPtSizeList = NULL;          /* Application provided size list  */
  811.    fontDlg.pfnDlgProc    = NULL;          /* Dialog subclass procedure       */
  812.    strcpy(szFamily, fontMetrics.szFamilyname); /* Family name of font        */
  813.    fontDlg.pszFamilyname = szFamily;      /* point to Family name of font    */
  814.    fontDlg.fxPointSize = fxPointSize;     /* Point size the user selected    */
  815.    fontDlg.fl           = FNTS_CENTER |   /* FNTS_* flags - dialog styles    */
  816.                            FNTS_INITFROMFATTRS;
  817.    fontDlg.flFlags      = 0;              /* FNTF_* state flags              */
  818.                                           /* Font type option bits           */
  819.    fontDlg.flType       = (LONG) fontMetrics.fsType;
  820.    fontDlg.flTypeMask   = 0;              /* Mask of which font types to use */
  821.    fontDlg.flStyle      = 0;              /* The selected style bits         */
  822.    fontDlg.flStyleMask  = 0;              /* Mask of which style bits to use */
  823.    fontDlg.clrFore      = lClrForeground; /* Selected foreground color       */
  824.    fontDlg.clrBack      = lClrBackground; /* Selected background color       */
  825.    fontDlg.ulUser       = 0;              /* Blank field for application     */
  826.    fontDlg.lReturn      = 0;              /* Return Value of the Dialog      */
  827.    fontDlg.lSRC;                          /* System return code.             */
  828.    fontDlg.lEmHeight    = 0;              /* Em height of the current font   */
  829.    fontDlg.lXHeight     = 0;              /* X height of the current font    */
  830.    fontDlg.lExternalLeading = 0;          /* External Leading of font        */
  831.    fontDlg.hMod;                          /* Module to load custom template  */
  832.                                           /* Nominal Point Size of font      */
  833.    fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize;
  834.    fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */
  835.    fontDlg.usWidth = fontMetrics.usWidthClass;  /* The width of the font     */
  836.    fontDlg.x            = 0;              /* X coordinate of the dialog      */
  837.    fontDlg.y            = 0;              /* Y coordinate of the dialog      */
  838.    fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */
  839.    fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */
  840.    fontDlg.fAttrs;                        /* Font attribute structure        */
  841.  
  842.    /*
  843.     *   Bring up the standard Font Dialog
  844.     */
  845.  
  846.    hwndFontDlg = WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg);
  847.  
  848.    if(fontDlg.lReturn != DID_OK)          /* check reason for return         */
  849.    {
  850.       WinReleasePS(fontDlg.hpsScreen);
  851.       return;
  852.    }
  853.    fxPointSize = fontDlg.fxPointSize;     /* save point size for next dialog */
  854.  
  855.    /*
  856.     *   If outline font, calculate the maxbaselineext and
  857.     *   avecharwidth for the point size selected
  858.     */
  859.  
  860.    if ( fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE )
  861.    {
  862.       ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
  863.    }
  864.  
  865.    /*
  866.     *   Query FONTMETRICS again to determine if font has been ISO9241
  867.     *   tested and if it complies to the ISO9241 standard.
  868.     */
  869.  
  870.    hpsMLE = WinGetPS(hwndMLE);
  871.    GpiQueryFontMetrics(hpsMLE, sizeof(FONTMETRICS), &fontMetrics);
  872.  
  873.    if (fontMetrics.fsSelection & FM_SEL_ISO9241_TESTED)
  874.    {
  875.       /*
  876.        *   Values of fbPassed/FailedISO field in the PANOSE structure below
  877.        *   indicate if any displays with ISO support pass/fail compliance test.
  878.        *   If desired, you could also determine the display type to narrow
  879.        *   down which of the following bit tests are necessary.
  880.        */
  881.  
  882.       if ((fontMetrics.panose.fbFailedISO & FM_ISO_9515_640 ) &&
  883.           (fontMetrics.panose.fbFailedISO & FM_ISO_9515_1024) &&
  884.           (fontMetrics.panose.fbFailedISO & FM_ISO_9517_640 ) &&
  885.           (fontMetrics.panose.fbFailedISO & FM_ISO_9517_1024) &&
  886.           (fontMetrics.panose.fbFailedISO & FM_ISO_9518_640 ))
  887.       {
  888.          /*
  889.           *   font selected fails ISO compliance test on all diplays
  890.           *   tested above.
  891.           */
  892.          MessageBox(hwndMain, IDMSG_ISOFAILED, MB_OK | MB_WARNING, FALSE);
  893.       }
  894.    }
  895.    else
  896.    {  /* font isn't tested for ISO compliance */
  897.       MessageBox(hwndMain, IDMSG_ISONOTTESTED, MB_OK | MB_WARNING, FALSE);
  898.    }
  899.  
  900.    WinReleasePS(fontDlg.hpsScreen);
  901.    WinReleasePS(hpsMLE);
  902.    WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), NULL);
  903.  
  904. }   /* End of SetFont()                                                 */
  905.  
  906. /*
  907.  *   Convert vector font size using point size and fAttrs structure and
  908.  *   return it in that structure.
  909.  */
  910.  
  911. VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs)
  912. {
  913.   HPS   hps;
  914.   HDC   hDC;
  915.   LONG  lxFontResolution;
  916.   LONG  lyFontResolution;
  917.   SIZEF sizef;
  918.  
  919.   hps = WinGetScreenPS(HWND_DESKTOP);        /* Screen presentation space */
  920.  
  921.   /*
  922.    *   Query device context for the screen and then query
  923.    *   the resolution of the device for the device context.
  924.    */
  925.  
  926.   hDC = GpiQueryDevice(hps);
  927.   DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lxFontResolution);
  928.   DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lyFontResolution);
  929.  
  930.   /*
  931.    *   Calculate the size of the character box, based on the
  932.    *   point size selected and the resolution of the device.
  933.    *   The size parameters are of type FIXED, NOT int.
  934.    *   NOTE: 1 point == 1/72 of an inch.
  935.    */
  936.  
  937.   sizef.cx = (FIXED)(((fxPointSize) / 72 ) * lxFontResolution );
  938.   sizef.cy = (FIXED)(((fxPointSize) / 72 ) * lyFontResolution );
  939.  
  940.   pfattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( sizef.cy ), 0 );
  941.   pfattrs->lAveCharWidth   = MAKELONG( HIUSHORT( sizef.cx ), 0 );
  942.   WinReleasePS(hps);
  943.  
  944. }   /* end ConvertVectorPointSize() */
  945.  
  946.  
  947. /****************************************************************\
  948.  *
  949.  *--------------------------------------------------------------
  950.  *
  951.  *  Name:
  952.  *
  953.  *  Purpose:
  954.  *
  955.  *
  956.  *
  957.  *  Usage:
  958.  *
  959.  *  Method:
  960.  *          -
  961.  *
  962.  *          -
  963.  *          -
  964.  *
  965.  *          -
  966.  *          -
  967.  *
  968.  *  Returns:
  969.  *          1 - if sucessful execution completed
  970.  *          0 - if error
  971. \****************************************************************/
  972. BOOL DisPlayInComingMessage(PSZ pszNewMessage)
  973. {
  974.       static IPT iptOffset =0;
  975.  
  976.      strcat(pszNewMessage,"\r\n");
  977.       /*
  978.        * Set the file into the MLE
  979.        */
  980.       WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT, MPFROMP((PBYTE)pszNewMessage),
  981.           MPFROMSHORT(strlen(pszNewMessage)+1 ));
  982.  
  983.       /*
  984.        * Import to MLE starting at current pos
  985.        */
  986.       WinSendMsg(hwndMLE, MLM_IMPORT, MPFROMP(&iptOffset),
  987.           MPFROMSHORT(strlen(pszNewMessage) +1));
  988.  
  989.  
  990.       /*
  991.        * Reset the changed flag
  992.        */
  993.      WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), NULL);
  994.      return(TRUE);
  995. }
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.