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_dlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-05  |  63.6 KB  |  1,960 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_DLG.C
  4. *
  5. *  Description : This module contains the Dialog Procedures for the user
  6. *                defined dialogs as well as any support code they need.
  7. *
  8. *  Concepts    : Dialog procedures for user defined dialogs,
  9. *                initialization of controls in the dialog boxs,
  10. *                use of presentation parameters.
  11. *
  12. *  API's       :  DosAllocMem             WinQueryFocus
  13. *                 DosFreeMem              WinQueryPointerPos
  14. *                 GpiQueryFonts           WinQueryPresParams
  15. *                 WinCreateWindow         WinQueryWindowText
  16. *                 WinDefDlgProc           WinQueryWindowUShort
  17. *                 WinDismissDlg           WinReleasePS
  18. *                 WinGetPS                WinRemovePresParams
  19. *                 WinLoadMenu             WinSendDlgItemMsg
  20. *                 WinLoadPointer          WinSendMsg
  21. *                 WinLoadString           WinSetDlgItemText
  22. *                 WinMapWindowPoints      WinSetPresParams
  23. *                 WinPopupMenu            WinWindowFromID
  24. *
  25. *  Copyright (C) 1992 IBM Corporation
  26. *
  27. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  28. *      sample code created by IBM Corporation. This sample code is not
  29. *      part of any standard or IBM product and is provided to you solely
  30. *      for  the purpose of assisting you in the development of your
  31. *      applications.  The code is provided "AS IS", without
  32. *      warranty of any kind.  IBM shall not be liable for any damages
  33. *      arising out of your use of the sample code, even if they have been
  34. *      advised of the possibility of such damages.                                                    *
  35. ************************************************************************/
  36.  
  37. /*  Include files, macros, defined constants, and externs              */
  38.  
  39. #define INCL_WINWINDOWMGR
  40. #define INCL_WINFRAMEMGR
  41. #define INCL_WINPOINTERS
  42. #define INCL_WININPUT
  43. #define INCL_WINLISTBOXES
  44. #define INCL_WINENTRYFIELDS
  45. #define INCL_WINSTDSPIN
  46. #define INCL_WINSTDBOOK
  47. #define INCL_WINMLE
  48. #define INCL_WINMENUS
  49. #define INCL_WINSTATICS
  50. #define INCL_WINSTDCNR
  51. #define INCL_WINSTDSLIDER
  52. #define INCL_WINSTDVALSET
  53. #define INCL_WINDIALOGS
  54. #define INCL_WINSYS
  55. #define INCL_GPILCIDS
  56. #define INCL_GPIBITMAPS
  57. #define INCL_DOSMEMMGR
  58.  
  59. #include <os2.h>
  60. #include <string.h>
  61. #include <stdlib.h>
  62. #include "sty_main.h"
  63. #include "sty_dlg.h"
  64. #include "sty_xtrn.h"
  65. #include "sty_help.h"
  66.  
  67. typedef struct _USERRECORD
  68. {
  69.   RECORDCORE  recordCore;
  70.   CDATE       date;
  71.   CTIME       time;
  72.   PSZ         recordData;
  73. } USERRECORD, *PUSERRECORD;
  74.  
  75. #define COLORNAMELEN    20
  76. #define NUMCOLORS       15  /* number of colors used in PP Demo */
  77. #define NUMSPINCOLORS   16  /* number of colors used in SPIN Demo */
  78. #define NUMFONTS         4  /* number of fonts used in PP Demo */
  79. #define FONTPOINTSIZE   80  /* point size to use in PP Demo */
  80. #define PPFONTPOINTSIZE  2              /* length of font point prefix */
  81. #define BUFSIZE         256
  82.  
  83. /*  Global variables                                                   */
  84.                                         /* array of clr names          */
  85. static CHAR apszPresParamColor[NUMCOLORS][COLORNAMELEN];
  86. static PSZ *apszPresParamFont = NULL;
  87. static LONG lNumFonts;
  88. static CNRINFO cnrinfo;
  89. static ULONG ulCnrAttributes;
  90. static RECORDINSERT recordInsert;
  91. static PUSERRECORD pUserRecord;
  92. static PFIELDINFO pFieldInfo, firstFieldInfo;
  93. static FIELDINFOINSERT fieldInfoInsert;
  94. static PFIELDINFOINSERT pFieldInfoInsert;
  95. static CHAR pszViewText[] = "Text for Text View.";
  96. static CHAR pszViewIcon[] = "Text for Icon View.";
  97. static CHAR pszViewName[] = "Text for Name View.";
  98. static CHAR pszColumnText1[]= "Data";
  99. static CHAR pszColumnText2[]= "Date";
  100. static CHAR pszColumnText3[]= "Time";
  101. static CHAR pszSampleData[] = "Sample Data";
  102. static CHAR pszCnrTitle[] = "Sample Container";
  103.  
  104. /*
  105.  * Set up an array of colors in the same order as the stringtable
  106.  * constants
  107.  */
  108. static ULONG aulColor[NUMCOLORS-1] =
  109.               { CLR_BLUE, CLR_RED, CLR_PINK, CLR_GREEN, CLR_CYAN,
  110.                 CLR_YELLOW, CLR_DARKGRAY, CLR_DARKBLUE, CLR_DARKRED,
  111.                 CLR_DARKPINK, CLR_DARKGREEN, CLR_DARKCYAN, CLR_BROWN,
  112.                 CLR_PALEGRAY };
  113.  
  114. /*  Entry point declarations                                           */
  115.  
  116. MRESULT EXPENTRY ProdInfoDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  117. MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  118. MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg, MPARAM mp1,
  119.                                       MPARAM mp2);
  120. BOOL InitializeValueSet(HWND hwnd);
  121. BOOL InitializeSpinButton(HWND hwnd);
  122. BOOL InitializeSlider(HWND hwnd);
  123. BOOL InitializeNoteBook(HWND hwnd);
  124. BOOL InitializeContainer(HWND hwnd);
  125. BOOL LoadListBox(HWND hwnd);
  126. BOOL InitPresParamDemoDlg(HWND hwnd);
  127. BOOL UpdatePresParamDemoDlg(HWND hwnd);
  128. VOID ShowDlgHelp(HWND hwnd);
  129. VOID SetSysMenu(HWND hwnd);
  130.  
  131.  
  132. /*********************************************************************
  133.  *  Name : ProdInfoDlgProc
  134.  *
  135.  *  Description : Processes all messages sent to the Product
  136.  *                Information dialog box.
  137.  *
  138.  *  Concepts : Called for each message sent to the Product
  139.  *             Information dialog box.  The Product
  140.  *             Information box only has a button control so
  141.  *             this routine only processes WM_COMMAND
  142.  *             messages.  Any WM_COMMAND posted must have come
  143.  *             from the Ok button so we dismiss the dialog
  144.  *             upon receiving it.
  145.  *
  146.  *  API's : WinDismissDlg
  147.  *          WinDefDlgProc
  148.  *
  149.  * Parameters   : hwnd - Window handle to which message is addressed
  150.  *                msg - Message type
  151.  *                mp1 - First message parameter
  152.  *                mp2 - Second message parameter
  153.  *
  154.  *  Returns : Dependent upon message sent
  155.  *
  156.  ****************************************************************/
  157. MRESULT EXPENTRY ProdInfoDlgProc( HWND hwnd, USHORT msg, MPARAM mp1,
  158.                                   MPARAM mp2)
  159. {
  160.    switch(msg)
  161.    {
  162.       case WM_COMMAND:
  163.          /*
  164.           * No matter what the command, close the dialog
  165.           */
  166.          WinDismissDlg(hwnd, TRUE);
  167.          break;
  168.  
  169.       case WM_HELP:
  170.          ShowDlgHelp(hwnd);
  171.          break;
  172.  
  173.       default:
  174.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  175.          break;
  176.    }
  177.    return (MRESULT)0;
  178. }           /* End of ProdInfolDlgProc()                               */
  179.  
  180.  
  181. /*********************************************************************
  182.  *  Name : DemoDlgProc
  183.  *
  184.  *  Description : Processes all messages sent to all Demo dialogs.
  185.  *
  186.  *  Concepts : Called for each message sent to a demo dialog box.
  187.  *             A switch statement branches to the routines to be
  188.  *             performed for each message processed.  Any messages
  189.  *             not specifically process are passed to the default
  190.  *             window procedure WinDefDlgProc().
  191.  *
  192.  *  API's : WinDismissDlg
  193.  *          WinLoadMenu
  194.  *          WinQueryPointerPos
  195.  *          WinMapWindowPoints
  196.  *          WinPopupMenu
  197.  *          WinSendDlgItemMsg
  198.  *          WinSetDlgItemText
  199.  *          WinDefDlgProc
  200.  *
  201.  * Parameters   : hwnd - Window handle to which message is addressed
  202.  *                msg - Message type
  203.  *                mp1 - First message parameter
  204.  *                mp2 - Second message parameter
  205.  *
  206.  *  Returns : Dependent upon message sent
  207.  *
  208.  ****************************************************************/
  209. MRESULT EXPENTRY DemoDlgProc( HWND hwnd, USHORT msg, MPARAM mp1,
  210.                               MPARAM mp2)
  211. {
  212.    CHAR      acBuffer[4];
  213.    CHAR      *cData;
  214.    PSHORT    psIdDlg;
  215.    static    SHORT IdDlg;
  216.    CHAR      szTemp[BUFSIZE];
  217.    ULONG     ulSessionId;
  218.  
  219.    cnrinfo.pszCnrTitle = pszCnrTitle;
  220.    ulCnrAttributes = CA_CONTAINERTITLE | CA_TITLESEPARATOR;
  221.    switch(msg)
  222.    {
  223.       case WM_INITDLG:
  224.  
  225.          SetSysMenu(hwnd);
  226.          psIdDlg = (PSHORT) mp2;
  227.          IdDlg   = *psIdDlg;
  228.  
  229.          switch(*psIdDlg)
  230.          {
  231. #if 0
  232.         /*
  233.          * The ShowDemoDlg() filled mp2 with a pointer to the id of
  234.          * the dialog template used to create the dialog box.
  235.          */
  236.             case IDD_LISTBOXDLG:
  237.             /*
  238.              * Load some text into the list boxes.  If any of the
  239.              * LoadListBox() routines fail, abort the dialog
  240.              */
  241.                if (!LoadListBox(WinWindowFromID(hwnd, IDC_LISTBOX)) ||
  242.                    !LoadListBox(WinWindowFromID(hwnd, IDC_MULTISELLISTBOX)))
  243.                {
  244.                   WinDismissDlg(hwnd, FALSE);
  245.                }
  246.                break;
  247.  
  248.             case IDD_COMBOBOXDLG:
  249.             /*
  250.              * Load some text into the combo boxes.  If any of the
  251.              * LoadListBox() routines fail, abort the dialog
  252.              */
  253.                if (!LoadListBox(WinWindowFromID(hwnd, IDC_SIMPLE)) ||
  254.                    !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWN)) ||
  255.                    !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWNLIST)))
  256.                {
  257.                   WinDismissDlg(hwnd, FALSE);
  258.                }
  259.                break;
  260.  
  261.             case IDD_SPINBUTTONDLG:
  262.             /*
  263.              * Initialize the master and servant Spinbuttons.
  264.              * If the initialization routine fails, abort
  265.              * the dialog
  266.              */
  267.                if (!InitializeSpinButton(hwnd))
  268.                {
  269.                   WinDismissDlg(hwnd, FALSE);
  270.                }
  271.                break;
  272.  
  273.             case IDD_VALUESETDLG:
  274.             /*
  275.              * Initialize the Valueset control.
  276.              * If the initialization routine fails, abort
  277.              * the dialog
  278.              */
  279.                if (!InitializeValueSet(hwnd))
  280.                {
  281.                   WinDismissDlg(hwnd, FALSE);
  282.                }
  283.                break;
  284.  
  285.             case IDD_CONTAINERDLG:
  286.             /*
  287.              * Initialize the Container control.
  288.              * If the initialization routine fails, abort
  289.              * the dialog
  290.              */
  291.                cnrinfo.flWindowAttr = CV_ICON | ulCnrAttributes;
  292.                if (!InitializeContainer(hwnd))
  293.                {
  294.                   WinDismissDlg(hwnd, FALSE);
  295.                }
  296.                break;
  297.  
  298.             case IDD_NOTEBOOKDLG:
  299.             /*
  300.              * Initialize the Notebook control.
  301.              * If the initialization routine fails, abort
  302.              * the dialog
  303.              */
  304.                if (!InitializeNoteBook(hwnd))
  305.                {
  306.                   WinDismissDlg(hwnd, FALSE);
  307.                }
  308.                break;
  309.  
  310.             case IDD_SLIDERDLG:
  311.             /*
  312.              * Initialize the Slider control.
  313.              * If the initialization routine fails, abort
  314.              * the dialog
  315.              */
  316.                if (!InitializeSlider(hwnd))
  317.                {
  318.                   WinDismissDlg(hwnd, FALSE);
  319.                }
  320.                break;
  321. #endif
  322.             default:
  323.                break;
  324.          }
  325.          break;
  326.  
  327.       case WM_CONTROL:
  328.          /*
  329.           * Process the WM_CONTROL messages for the slider and valueset
  330.           * set controls.
  331.           */
  332.          switch(SHORT2FROMMP(mp1))
  333.          {
  334.             case CN_CONTEXTMENU:
  335.             {
  336.                POINTL point;
  337.                HWND hwndMenu;
  338.                HWND hwndContainer;
  339.                /*
  340.                 * If we receive a EN_CONTEXTMENU MESSAGE and if the
  341.                 * current dialog if the container dialog, display a
  342.                 * popup menu that allows the user to change the
  343.                 * container view.
  344.                 */
  345.                 hwndContainer = WinWindowFromID(hwnd,IDC_CONTAINER);
  346.  
  347.                 hwndMenu = WinLoadMenu(hwnd, 0, IDD_CONTAINERMENU);
  348.                 WinQueryPointerPos(HWND_DESKTOP, &point);
  349.                 WinMapWindowPoints(HWND_DESKTOP,hwndContainer,&point,1);
  350.  
  351.                 WinPopupMenu(hwndContainer, hwnd, hwndMenu,
  352.                              point.x, point.y,
  353.                              IDM_ICON, PU_NONE | PU_SELECTITEM |
  354.                              PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 | PU_KEYBOARD);
  355.                break;
  356.             }
  357.             case SLN_CHANGE:
  358.             {
  359.                LONG ulValue;
  360.  
  361.                if (SHORT1FROMMP(mp1) == IDC_HSLIDER)
  362.                {
  363.                   ulValue = (ULONG) WinSendDlgItemMsg(hwnd, IDC_HSLIDER,
  364.                      SLM_QUERYSLIDERINFO,
  365.                      MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  366.                      NULL);
  367.                   cData = _ltoa(ulValue,acBuffer,10);
  368.                   WinSetDlgItemText(hwnd,IDC_HSLIDERDATA, cData);
  369.                }
  370.                else
  371.                {
  372.                   ulValue = (ULONG) WinSendDlgItemMsg(hwnd, IDC_VSLIDER,
  373.                      SLM_QUERYSLIDERINFO,
  374.                      MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  375.                      NULL);
  376.                   cData = _ltoa(ulValue,acBuffer,10);
  377.                   WinSetDlgItemText(hwnd,IDC_VSLIDERDATA, cData);
  378.                }
  379.                break;
  380.             }
  381.             case VN_SELECT:
  382.             case VN_ENTER:
  383.             {
  384.                CHAR  pszNotificationTxt[256];
  385.                CHAR  pszTmp[5];
  386.                ULONG ulRowCol;
  387.  
  388.                ulRowCol = (ULONG)WinSendDlgItemMsg(hwnd, IDC_VALUESET,
  389.                   VM_QUERYSELECTEDITEM, NULL, NULL);
  390.  
  391.                if ((SHORT2FROMMP(mp1)) == VN_SELECT)
  392.                   strcpy (pszNotificationTxt, "VN_SELECT for item at row ");
  393.                else
  394.                   strcpy (pszNotificationTxt, "VN_ENTER for item at row ");
  395.  
  396.                _itoa(SHORT1FROMMP(ulRowCol), pszTmp, 10);
  397.                strcat (pszNotificationTxt, pszTmp);
  398.                strcat (pszNotificationTxt, ",Column ");
  399.                _itoa(SHORT2FROMMP(ulRowCol), pszTmp, 10);
  400.                strcat (pszNotificationTxt, pszTmp);
  401.                WinSetDlgItemText(hwnd,IDC_VALUESETTEXT, pszNotificationTxt);
  402.                break;
  403.             }
  404.          }
  405.          break;
  406.       case WM_COMMAND:
  407.          switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  408.          {
  409.             /*
  410.              * Process the command messages from the container popup menu
  411.              */
  412.             case IDM_ICON:
  413.                cnrinfo.flWindowAttr = CV_ICON | ulCnrAttributes;
  414.                WinSendDlgItemMsg(hwnd,IDC_CONTAINER,CM_SETCNRINFO,&cnrinfo,
  415.                               MPFROMLONG(CMA_FLWINDOWATTR));
  416.                break;
  417.  
  418.             case IDM_NAME:
  419.                cnrinfo.flWindowAttr = CV_NAME | ulCnrAttributes;
  420.                WinSendDlgItemMsg(hwnd,IDC_CONTAINER,CM_SETCNRINFO,&cnrinfo,
  421.                              MPFROMLONG(CMA_FLWINDOWATTR));
  422.                break;
  423.  
  424.             case IDM_TEXT:
  425.                cnrinfo.flWindowAttr = CV_TEXT | ulCnrAttributes;
  426.                WinSendDlgItemMsg(hwnd,IDC_CONTAINER,CM_SETCNRINFO,&cnrinfo,
  427.                                 MPFROMLONG(CMA_FLWINDOWATTR));
  428.                break;
  429.  
  430.             case IDM_DETAIL:
  431.                cnrinfo.flWindowAttr = CV_DETAIL | ulCnrAttributes |
  432.                   CA_DETAILSVIEWTITLES;
  433.  
  434.                WinSendDlgItemMsg(hwnd,IDC_CONTAINER,CM_SETCNRINFO,&cnrinfo,
  435.                                 MPFROMLONG(CMA_FLWINDOWATTR));
  436.  
  437.                WinSendDlgItemMsg(hwnd,IDC_CONTAINER,
  438.                                  CM_INVALIDATEDETAILFIELDINFO,      /*@@@RBS*/
  439.                                  NULL, NULL);
  440.  
  441.                break;
  442.                  /*
  443.                   *call and send our message text to our service routine
  444.                   */
  445.             case DID_OK:
  446.                  /*
  447.                   *get the PID if we want to send a message to a
  448.                   *specific process
  449.                   */
  450.                if(IdDlg == IDD_BUTTONSDLG)
  451.                {
  452.                      memset(szTemp,0,BUFSIZE);
  453.                     /*
  454.                      *first off, get the PID of the process to send the
  455.                      *message to
  456.                      */
  457.                     WinQueryDlgItemText(hwnd,IDC_PID,BUFSIZE,szTemp);
  458.                     ulSessionId = atol(szTemp);
  459.                     /*
  460.                      *validate PID
  461.                      *and generate error if out of range
  462.                      */
  463.                     if(ulSessionId < 1 || ulSessionId > 0xFFFF)
  464.                     {
  465.                           /*
  466.                            *error out
  467.                            */
  468.                     }
  469.                }
  470.                else
  471.                {
  472.                     ulSessionId = -1;
  473.                }
  474.                memset(szTemp,0,BUFSIZE);
  475.                WinQueryDlgItemText(hwnd,IDC_ENTRY,BUFSIZE,szTemp);
  476.  
  477.                if(WriteVirtQueue(szTemp,strlen(szTemp),ulSessionId) )
  478.                {
  479.                     /*
  480.                      *unable to send
  481.                      *message through the queue generate error message
  482.                      */
  483.                      MessageBox(HWND_DESKTOP,
  484.                                IDMSG_UNABLETOSEND,
  485.                                MB_OK | MB_ERROR,
  486.                                TRUE);
  487.                }
  488.                DisPlayInComingMessage(szTemp);
  489.                WinDismissDlg( hwnd, TRUE );     /* Removes the dialog box    */
  490.                return (MRESULT)FALSE;
  491.  
  492.             case DID_CANCEL:          /* The Cancel pushbutton or Escape key */
  493.                WinDismissDlg( hwnd, TRUE );     /* Removes the dialog box    */
  494.                return (MRESULT)FALSE;
  495.  
  496.             default:
  497.                break;
  498.          }
  499.          break;
  500.  
  501.       case WM_HELP:
  502.          ShowDlgHelp(hwnd);
  503.          break;
  504.  
  505.       default:
  506.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  507.          break;
  508.    }
  509.    return (MRESULT)0;
  510. }                                            /* End of DemoDlgProc()        */
  511.  
  512. /*********************************************************************
  513.  *  Name : LoadListBox
  514.  *
  515.  *  Description : Loads the demo list box with 0 through 9
  516.  *
  517.  *
  518.  *  Concepts : Called each time a demo list box is
  519.  *             initialized.  A for 0 to 9 loop is converts
  520.  *             the INT to a string which is added to the
  521.  *             listbox via LM_INSERTITEM
  522.  *
  523.  *  API's : WinLoadString
  524.  *          WinSendMsg
  525.  *
  526.  *  Parameters : hwnd - Window handle of the list box.
  527.  *
  528.  *  Returns: TRUE if list box is loaded successfully, FALSE otherwise
  529.  *
  530.  ****************************************************************/
  531. BOOL LoadListBox(HWND hwnd)
  532. {
  533.    ULONG ulCounter;
  534.    CHAR pszTemp[MESSAGELEN];
  535.    SHORT sResult;
  536.  
  537.    for(ulCounter = 0; ulCounter < 10; ulCounter++)
  538.    {
  539.       if (!WinLoadString(hab, (HMODULE)0, (IDS_LISTBOX1 + ulCounter),
  540.                         MESSAGELEN, (PSZ)pszTemp))
  541.       {
  542.          MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  543.          return FALSE;
  544.       }
  545.       sResult = (SHORT) WinSendMsg(hwnd, LM_INSERTITEM,
  546.                                MPFROMSHORT(LIT_SORTASCENDING),
  547.                                MPFROMP((PSZ)pszTemp));
  548.  
  549.       if (sResult == LIT_ERROR || sResult == LIT_MEMERROR)
  550.       {
  551.          MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  552.  
  553.          return FALSE;
  554.       }
  555.     }
  556.     return TRUE;
  557.  
  558. }                                          /*    End of LoadListBox()       */
  559.  
  560.  
  561. /*********************************************************************
  562.  *  Name : PresParamDemoDlgProc
  563.  *
  564.  *  Description : Processes all messages sent to the PresParamDemo
  565.  *                dialog.
  566.  *
  567.  *  Concepts : Called for each message sent to the PresParamDemo
  568.  *             dialog box.  A switch statement branches to the
  569.  *             routines to be performed for each message
  570.  *             processed.  Any messages not specifically process
  571.  *             are passed to the default window procedure
  572.  *             WinDefDlgProc().
  573.  *
  574.  *  API's : WinDismissDlg
  575.  *          WinDefDlgProc
  576.  *
  577.  *  Parameters   : hwnd - Window handle to which message is addressed
  578.  *                 msg - Message type
  579.  *                 mp1 - First message parameter
  580.  *                 mp2 - Second message parameter
  581.  *
  582.  *  Returns: Dependent upon message sent
  583.  *
  584.  ****************************************************************/
  585. MRESULT EXPENTRY PresParamDemoDlgProc( HWND hwnd, USHORT msg,
  586.                                        MPARAM mp1, MPARAM mp2)
  587. {
  588.    switch(msg)
  589.    {
  590.       case WM_INITDLG:
  591.          /*
  592.           * If initialization fails, abort the dialog
  593.           */
  594.          if (!InitPresParamDemoDlg(hwnd))
  595.              WinDismissDlg(hwnd, FALSE);
  596.          return (MRESULT)FALSE;
  597.          break;
  598.  
  599.       case WM_COMMAND:
  600.          switch(SHORT1FROMMP(mp1))
  601.          {
  602.             case IDC_CANCEL:
  603.             /*
  604.              * If done, close the dialog
  605.              */
  606.                WinDismissDlg(hwnd, TRUE);
  607.                break;
  608.  
  609.             case IDC_APPLY:
  610.             /*
  611.              * Update the dialog box
  612.              */
  613.                UpdatePresParamDemoDlg(hwnd);
  614.                break;
  615.  
  616.             default:
  617.                break;
  618.          }
  619.          break;
  620.  
  621.       case WM_HELP:
  622.          ShowDlgHelp(hwnd);
  623.          break;
  624.  
  625.       default:
  626.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  627.          break;
  628.    }
  629.    return (MRESULT)0;
  630. }                                      /* End of PresParamDemoDlgProc() */
  631.  
  632. /*********************************************************************
  633.  *  Name : InitPresParamDemoDlg
  634.  *
  635.  *  Description : Places the colors and fonts into the
  636.  *                PresParamDemoDlg's comboboxes.
  637.  *
  638.  *  Concepts : Called when the PP demo dialog is initialized.
  639.  *             LM_INSERTITEM is sent to each combobox for the
  640.  *             color or font string added to the combobox.
  641.  *
  642.  *  API's : WinLoadString
  643.  *          WinWindowFromID
  644.  *          WinSendMsg
  645.  *          GpiQueryFonts
  646.  *          WinGetPS
  647.  *          WinReleasePS
  648.  *          DosAllocMem
  649.  *          DosFreeMem
  650.  *
  651.  *  Parameters : hwnd - Window handle of the dialog
  652.  *
  653.  *  Returns: TRUE if initialization is successfull, FALSE if not
  654.  *
  655.  ****************************************************************/
  656. BOOL InitPresParamDemoDlg(HWND hwnd)
  657. {
  658.    HWND hwndTemp;
  659.    ULONG ulCounter;
  660.    MRESULT mresult;
  661.    PFONTMETRICS pfm, pfmSave;
  662.    LONG lTemp, lFonts;
  663.    HPS hps;
  664.    PSZ *ppszT;
  665.    BOOL bHaveFont;
  666.  
  667.    /*
  668.     * Load the color table
  669.     */
  670.    for (ulCounter = 0; ulCounter < NUMCOLORS; ulCounter++)
  671.    {
  672.       if (!WinLoadString(hab, (HMODULE)0, (ulCounter + IDS_FIRSTCOLOR),
  673.              COLORNAMELEN, (PSZ)apszPresParamColor[ulCounter]))
  674.       {
  675.          MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  676.          return FALSE;
  677.       }
  678.    }
  679.    /*
  680.     * Load foreground color combo box
  681.     */
  682.    hwndTemp = WinWindowFromID(hwnd, IDC_FORECOLORLIST);
  683.  
  684.    for(ulCounter = 0; ulCounter < NUMCOLORS; ulCounter++)
  685.    {
  686.       mresult = WinSendMsg(hwndTemp, LM_INSERTITEM,
  687.                           MPFROMSHORT(LIT_SORTASCENDING),
  688.                           MPFROMP((PSZ)apszPresParamColor[ulCounter]));
  689.  
  690.       if (((SHORT)mresult) == LIT_ERROR || ((SHORT)mresult) == LIT_MEMERROR)
  691.       {
  692.          MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR,
  693.               FALSE);
  694.          return FALSE;
  695.       }
  696.    }
  697.  
  698.    /*
  699.    * Load background color combo box
  700.    */
  701.    hwndTemp = WinWindowFromID(hwnd, IDC_BACKCOLORLIST);
  702.  
  703.    for(ulCounter = 0; ulCounter < NUMCOLORS; ulCounter++)
  704.    {
  705.       mresult = WinSendMsg(hwndTemp, LM_INSERTITEM,
  706.                             MPFROMSHORT(LIT_SORTASCENDING),
  707.                             MPFROMP((PSZ)apszPresParamColor[ulCounter]));
  708.  
  709.        if (((SHORT)mresult) == LIT_ERROR || ((SHORT)mresult) == LIT_MEMERROR)
  710.        {
  711.           MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR,
  712.                 FALSE);
  713.           return FALSE;
  714.        }
  715.    }
  716.    /*
  717.     * Fonts.  Find all of the fonts of point size desired and normal
  718.     * weight.  Put the facenames in the combo box
  719.     */
  720.    hwndTemp = WinWindowFromID(hwnd, IDC_FONTLIST);
  721.    hps = WinGetPS(hwndTemp);
  722.  
  723.    /*
  724.     * Determine the number of fonts available
  725.     */
  726.    lFonts = 0;
  727.    lTemp = 0;
  728.    lFonts = GpiQueryFonts(hps, QF_PUBLIC, NULL, &lTemp,
  729.                   (ULONG)sizeof(FONTMETRICS), (PFONTMETRICS)NULL);
  730.  
  731.    if (lFonts == GPI_ALTERROR)
  732.    {
  733.        MessageBox(hwndMain, IDMSG_CANNOTLOADFONTS, MB_OK | MB_ERROR, FALSE);
  734.        WinReleasePS(hps);
  735.        return FALSE;
  736.    }
  737.  
  738.    /*
  739.     * Allocate buffer for fontmetric structures
  740.     */
  741.    if (DosAllocMem((PPVOID)&pfm, lFonts * (ULONG)sizeof(FONTMETRICS),
  742.            fALLOC))
  743.    {
  744.       MessageBox(hwndMain, IDMSG_CANNOTALLOCATEMEMORY, MB_OK | MB_ERROR,
  745.             FALSE);
  746.       WinReleasePS(hps);
  747.       return FALSE;
  748.    }
  749.    pfmSave = pfm;
  750.  
  751.    /*
  752.     * Get all fonts
  753.     */
  754.    lTemp = GpiQueryFonts(hps, QF_PUBLIC, NULL, &lFonts,
  755.                 (ULONG)sizeof(FONTMETRICS), (PFONTMETRICS)pfm);
  756.  
  757.    WinReleasePS(hps);
  758.  
  759.    if (lTemp == GPI_ALTERROR)
  760.    {
  761.       MessageBox(hwndMain, IDMSG_CANNOTLOADFONTS, MB_OK | MB_ERROR, FALSE);
  762.       return FALSE;
  763.    }
  764.  
  765.    /*
  766.     * Allocate buffer for array of string names, freeing the first
  767.     * buffer if necessary
  768.     */
  769.    if ((BOOL)apszPresParamFont)
  770.    {
  771.       ppszT = apszPresParamFont;
  772.       while ((BOOL)*ppszT)
  773.       {
  774.          DosFreeMem(*ppszT++);
  775.       }
  776.  
  777.       DosFreeMem(apszPresParamFont);
  778.    }
  779.  
  780.    if (DosAllocMem((PPVOID)&apszPresParamFont,
  781.           (lFonts + 1) * (ULONG)sizeof(PSZ), fALLOC))
  782.    {
  783.       MessageBox(hwndMain, IDMSG_CANNOTALLOCATEMEMORY, MB_OK | MB_ERROR,
  784.            FALSE);
  785.       DosFreeMem((PVOID)pfmSave);
  786.       apszPresParamFont = NULL;
  787.       return FALSE;
  788.    }
  789.  
  790.    /*
  791.     * Initialize array to NULL
  792.     */
  793.    lTemp = 0;
  794.    ppszT = apszPresParamFont;
  795.    while (lTemp++ < lFonts)
  796.        *ppszT++ = (PSZ)NULL;
  797.    *ppszT = (PSZ)NULL;
  798.  
  799.  
  800.    /*
  801.     * Walk through all fonts.  If the font matches the point size
  802.     * desired and has a weight and width class of normal (5) and
  803.     * no special attributes (e. g. italic, underline, etc.).  If
  804.     * it does, then add its string to the combo box
  805.     */
  806.    lNumFonts = 0;
  807.    ppszT = apszPresParamFont;
  808.  
  809.    while (lFonts--)
  810.    {
  811.       if (pfm->sNominalPointSize == FONTPOINTSIZE &&
  812.              pfm->usWeightClass == 5 && pfm->usWidthClass == 5 &&
  813.              pfm->fsSelection == 0)
  814.       {
  815.       /*
  816.        * Make sure we don't have this font.  If we don't,
  817.        * then add the font to the list
  818.        */
  819.          lTemp = 0;
  820.          bHaveFont = FALSE;
  821.          while (lTemp < lNumFonts)
  822.          {
  823.             if (!strcmp(pfm->szFacename, apszPresParamFont[(INT)lTemp]))
  824.             {
  825.                bHaveFont = TRUE;
  826.                break;
  827.             }
  828.             else
  829.                lTemp++;
  830.          }
  831.  
  832.          if (!bHaveFont)
  833.          {
  834.             if (DosAllocMem((PPVOID)ppszT,
  835.                 (LONG)(FACESIZE * sizeof(CHAR)), fALLOC))
  836.             {
  837.                MessageBox(hwndMain, IDMSG_CANNOTALLOCATEMEMORY,
  838.                   MB_OK | MB_ERROR, FALSE);
  839.                DosFreeMem((PVOID)pfmSave);
  840.                return FALSE;
  841.              }
  842.  
  843.              strcpy(*ppszT++, pfm->szFacename);
  844.              lNumFonts++;
  845.          }
  846.       }
  847.       pfm++;
  848.    }
  849.  
  850.    /*
  851.     * Install the name of each font into the combo box
  852.     */
  853.    ppszT = apszPresParamFont;
  854.    while ((BOOL)*ppszT)
  855.    {
  856.       mresult = WinSendMsg(hwndTemp, LM_INSERTITEM,
  857.                  MPFROMSHORT(LIT_SORTASCENDING), MPFROMP((PSZ)*ppszT++));
  858.  
  859.       if (((SHORT)mresult) == LIT_ERROR || ((SHORT)mresult) == LIT_MEMERROR)
  860.       {
  861.          MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR,
  862.               FALSE);
  863.          DosFreeMem((PVOID)pfmSave);
  864.          return FALSE;
  865.       }
  866.    }
  867.  
  868.    /*
  869.     * Add "DefaulTemp" text onto the end
  870.     */
  871.    mresult = WinSendMsg(hwndTemp, LM_INSERTITEM,
  872.              MPFROMSHORT(LIT_SORTASCENDING),
  873.              MPFROMP(apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR]));
  874.  
  875.    if (((SHORT)mresult) == LIT_ERROR || ((SHORT)mresult) == LIT_MEMERROR)
  876.    {
  877.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  878.       DosFreeMem((PVOID)pfmSave);
  879.       return FALSE;
  880.    }
  881.    DosFreeMem((PVOID)pfmSave);
  882.    return TRUE;
  883. }                                      /* End of InitPresParamDemoDlg()   */
  884.  
  885. /*********************************************************************
  886.  *  Name : UpdatePresParamDemoDlg
  887.  *
  888.  *  Description : Sets/Removes the Presentation Parameter of the sample
  889.  *                text window depending upon the parameters chosen,
  890.  *
  891.  *  Concepts : Called when user wants to update the window.  The string
  892.  *             of each combobox is queried and then the color or font
  893.  *             is set depending upon the string chosen.
  894.  *
  895.  *  API's : WinWindowFromID
  896.  *          WinQueryWindowText
  897.  *          WinSendMsg
  898.  *          WinSetPresParams
  899.  *          WinQueryPresParams
  900.  *          WinRemovePresParams
  901.  *
  902.  *  Parameters : hwnd - Handle of Presentation Params dialog
  903.  *
  904.  *  Returns: TRUE if update is successfull, FALSE if not
  905.  *
  906.  ****************************************************************/
  907. BOOL UpdatePresParamDemoDlg(HWND hwnd)
  908. {
  909.    HWND hwndTemp, hwndSampleText, hwndSampleButton;
  910.    CHAR pszTemp[COLORNAMELEN];
  911.    BYTE abBuf[FACESIZE + PPFONTPOINTSIZE];
  912.    ULONG ulColor, ulPresParams;
  913.    SHORT sCounter;
  914.  
  915.    /*
  916.     * Get window handle of the sample text box
  917.     */
  918.    hwndSampleText = WinWindowFromID(hwnd, IDC_SAMPLETEXT);
  919.    hwndSampleButton = WinWindowFromID(hwnd, IDC_CHECKBOX);
  920.  
  921.    /*
  922.     * Get the text of the foreground color combobox
  923.    */
  924.    hwndTemp = WinWindowFromID(hwnd, IDC_FORECOLORLIST);
  925.  
  926.    if(WinQueryWindowText(hwndTemp, COLORNAMELEN, (PSZ)pszTemp))
  927.    {
  928.    /*
  929.     * Find the text in the list of color names
  930.     */
  931.       sCounter = 0;
  932.       while (sCounter < NUMCOLORS)
  933.       {
  934.          if (!strcmp(pszTemp, apszPresParamColor[sCounter]))
  935.          {
  936.             ulColor = aulColor[sCounter];
  937.             break;
  938.          }
  939.          else
  940.             sCounter++;
  941.       }
  942.  
  943.       /*
  944.        * If color is not default, set the color.  If the default is
  945.        * selected, then remove the color presentation parameter if
  946.        * it exists.  If the value is not a valid color, then don't
  947.        * don't do anything
  948.        */
  949.        if (sCounter < NUMCOLORS)
  950.        {
  951.           sCounter += IDS_FIRSTCOLOR;
  952.           if (sCounter < IDS_DEFAULT)
  953.           {
  954.              if (!WinSetPresParam(hwndSampleText, PP_FOREGROUNDCOLORINDEX,
  955.                    (ULONG)sizeof(LONG), (PVOID)&ulColor) ||
  956.                    !WinSetPresParam(hwndSampleButton,
  957.                    PP_FOREGROUNDCOLORINDEX, (ULONG)sizeof(LONG),
  958.                    (PVOID)&ulColor))
  959.              {
  960.                 MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR, FALSE);
  961.              }
  962.           }
  963.           else
  964.           {
  965.           /*
  966.            * If setting presentation parameter to the default, remove
  967.            * the presentation parameter, but only if it has been
  968.            * set
  969.            */
  970.               if (sCounter == IDS_DEFAULT &&
  971.                    WinQueryPresParam(hwndSampleText, PP_FOREGROUNDCOLORINDEX,
  972.                    0, &ulPresParams, (ULONG)sizeof(LONG), (PVOID)&ulColor,
  973.                    QPF_NOINHERIT) != 0)
  974.               {
  975.                  if (!WinRemovePresParam(hwndSampleText,
  976.                      PP_FOREGROUNDCOLORINDEX) ||
  977.                      !WinRemovePresParam(hwndSampleButton,
  978.                      PP_FOREGROUNDCOLORINDEX))
  979.                  {
  980.                     MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR,
  981.                          FALSE);
  982.                  }
  983.               }
  984.           }
  985.        }
  986.    }
  987.  
  988.    /*
  989.     * Do the same for the background color combobox
  990.     */
  991.    hwndTemp = WinWindowFromID(hwnd, IDC_BACKCOLORLIST);
  992.    if (WinQueryWindowText(hwndTemp, COLORNAMELEN, (PSZ)pszTemp))
  993.    {
  994.    /*
  995.     * Find the text in the list of color names
  996.    */
  997.       sCounter = 0;
  998.       while (sCounter < NUMCOLORS)
  999.       {
  1000.          if (!strcmp(pszTemp, apszPresParamColor[sCounter]))
  1001.          {
  1002.             ulColor = aulColor[sCounter];
  1003.             break;
  1004.          }
  1005.          else
  1006.             sCounter++;
  1007.       }
  1008.  
  1009.       /*
  1010.        * If color is not default, set the color.  If the default is
  1011.        * selected, then remove the color presentation parameter.  If
  1012.        * the value is not a valid color, the don't do anything
  1013.        */
  1014.        if (sCounter < NUMCOLORS)
  1015.        {
  1016.           sCounter += IDS_FIRSTCOLOR;
  1017.           if (sCounter < IDS_DEFAULT)
  1018.           {
  1019.              if (!WinSetPresParam(hwndSampleText, PP_BACKGROUNDCOLORINDEX,
  1020.                  (ULONG)sizeof(LONG), (PVOID)&ulColor) ||
  1021.                  !WinSetPresParam(hwndSampleButton, PP_BACKGROUNDCOLORINDEX,
  1022.                  (ULONG)sizeof(LONG), (PVOID)&ulColor))
  1023.              {
  1024.                 MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR,
  1025.                       FALSE);
  1026.              }
  1027.           }
  1028.           else
  1029.           {
  1030.              if (sCounter == IDS_DEFAULT &&
  1031.                   WinQueryPresParam(hwndSampleText,
  1032.                   PP_BACKGROUNDCOLORINDEX, 0, &ulPresParams, (ULONG)sizeof(LONG),
  1033.                   (PVOID)&ulColor, QPF_NOINHERIT) != 0)
  1034.              {
  1035.                 if (!WinRemovePresParam(hwndSampleText,
  1036.                     PP_BACKGROUNDCOLORINDEX) ||
  1037.                     !WinRemovePresParam(hwndSampleButton,
  1038.                     PP_BACKGROUNDCOLORINDEX))
  1039.                 {
  1040.                    MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR,
  1041.                          FALSE);
  1042.                 }
  1043.              }
  1044.           }
  1045.        }
  1046.    }
  1047.  
  1048.    /*
  1049.     * Get the text of the font combobox
  1050.     */
  1051.    hwndTemp = WinWindowFromID(hwnd, IDC_FONTLIST);
  1052.    if (WinQueryWindowText(hwndTemp, FACESIZE, (PSZ)pszTemp))
  1053.    {
  1054.    /*
  1055.     * If Font selected is "Default", remove font pres. param.
  1056.     */
  1057.       if (!strcmp(pszTemp, apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR]))
  1058.       {
  1059.          if (WinQueryPresParam(hwndSampleText, PP_FONTNAMESIZE, 0,
  1060.               &ulPresParams, (ULONG)(FACESIZE + PPFONTPOINTSIZE), (PVOID)abBuf,
  1061.               QPF_NOINHERIT) != 0)
  1062.          {
  1063.             if (!WinRemovePresParam(hwndSampleText, PP_FONTNAMESIZE) ||
  1064.                 !WinRemovePresParam(hwndSampleButton, PP_FONTNAMESIZE))
  1065.             {
  1066.                MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR,
  1067.                     FALSE);
  1068.             }
  1069.          }
  1070.       }
  1071.       else
  1072.       {
  1073.       /*
  1074.        * Font is not default.
  1075.        * AbBuf will hold the font point size and name in
  1076.        * the form <pt>.<name>.  First we fill abBuf with the
  1077.        * font point prefix and then append the font name
  1078.        * retrieved from the combobox.
  1079.        */
  1080.  
  1081.          if (!WinLoadString(hab, (HMODULE)0, IDS_PPFONTPOINT,
  1082.               COLORNAMELEN, (PSZ)abBuf))
  1083.          {
  1084.             MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR,
  1085.                  FALSE);
  1086.             return FALSE;
  1087.          }
  1088.          strcat((PSZ)abBuf, pszTemp);
  1089.  
  1090.          if (!WinSetPresParam(hwndSampleText, PP_FONTNAMESIZE,
  1091.              (ULONG)strlen((PSZ)abBuf) + 1, (PVOID)abBuf) ||
  1092.              !WinSetPresParam(hwndSampleButton, PP_FONTNAMESIZE,
  1093.              (ULONG)strlen((PSZ)abBuf) + 1, (PVOID)abBuf))
  1094.          {
  1095.             MessageBox(hwndMain, IDMSG_CANNOTSETPP, MB_OK | MB_ERROR,
  1096.                  FALSE);
  1097.          }
  1098.       }
  1099.    }
  1100.    return TRUE;
  1101. }                                     /* End of UpdatePresParamDemoDlg() */
  1102.  
  1103. /*********************************************************************
  1104.  *  Name : ShowDlgHelp
  1105.  *
  1106.  *  Description : Displays the help panel for the current selected
  1107.  *                item in the dialog window
  1108.  *
  1109.  *  Concepts : Called each time a WM_HELP message is posted to a
  1110.  *             dialog gets the id value of the window and determine
  1111.  *             which help panel to display.  Then sends a message
  1112.  *             to the help instance to display the panel.  If the
  1113.  *             dialog or item is not included here, then the
  1114.  *             unknown dialog or unknown item panel is displayed.
  1115.  *
  1116.  *  API's : WinQueryFocus
  1117.  *          WinQueryWindowUShort
  1118.  *          WinWindowFromID
  1119.  *
  1120.  *  Parameters : hwnd - Handle of the dialog box
  1121.  *
  1122.  *  Returns: Void
  1123.  *
  1124.  ****************************************************************/
  1125. VOID ShowDlgHelp(HWND hwnd)
  1126. {
  1127.    SHORT idPanel, idDlg, idItem;
  1128.    HWND hwndFocus;
  1129.  
  1130.    /*
  1131.    * Get the id of the dialog box
  1132.    */
  1133.    idDlg = WinQueryWindowUShort(hwnd, QWS_ID);
  1134.  
  1135.    /*
  1136.     * Finds which window has the focus and gets its id
  1137.     */
  1138.    hwndFocus = WinQueryFocus(HWND_DESKTOP);
  1139.    idItem = WinQueryWindowUShort(hwndFocus, QWS_ID);
  1140.  
  1141.    switch(idDlg)
  1142.    {
  1143.       case IDD_BUTTONSDLG:
  1144.          switch(idItem)
  1145.          {
  1146.             case IDC_RADIO1:
  1147.             case IDC_RADIO2:
  1148.             case IDC_RADIO3:
  1149.                idPanel = PANEL_BUTTONSDLG_RADIO;
  1150.                break;
  1151.  
  1152.             case IDC_CHECKBOX:
  1153.                idPanel = PANEL_BUTTONSDLG_CHECKBOX;
  1154.                break;
  1155.  
  1156.             case IDC_3STATE:
  1157.                idPanel = PANEL_BUTTONSDLG_THREESTATE;
  1158.                break;
  1159.  
  1160.             case IDC_PUSHBUTTON:
  1161.                idPanel = PANEL_BUTTONSDLG_PUSHBUTTON;
  1162.                break;
  1163.  
  1164.             case IDC_OK:
  1165.                idPanel = PANEL_BUTTONSDLG_OK;
  1166.                break;
  1167.  
  1168.             case IDC_HELP:
  1169.                idPanel = PANEL_BUTTONSDLG_HELP;
  1170.                break;
  1171.  
  1172.             default:
  1173.                idPanel = PANEL_UNKNOWN;
  1174.                break;
  1175.          }
  1176.          break;
  1177.  
  1178.       case IDD_LISTBOXDLG:
  1179.          switch(idItem)
  1180.          {
  1181.             case IDC_LISTBOX:
  1182.                idPanel = PANEL_LISTBOXDLG_SINGLE;
  1183.                break;
  1184.  
  1185.             case IDC_MULTISELLISTBOX:
  1186.                idPanel = PANEL_LISTBOXDLG_MULTIPLE;
  1187.                break;
  1188.  
  1189.             case IDC_OK:
  1190.                idPanel = PANEL_LISTBOXDLG_OK;
  1191.                break;
  1192.  
  1193.             case IDC_HELP:
  1194.                idPanel = PANEL_LISTBOXDLG_HELP;
  1195.                break;
  1196.  
  1197.             default:
  1198.                idPanel = PANEL_UNKNOWN;
  1199.                break;
  1200.          }
  1201.          break;
  1202.  
  1203.       case IDD_COMBOBOXDLG:
  1204.          switch(idItem)
  1205.          {
  1206.             case IDC_SIMPLE:
  1207.                idPanel = PANEL_COMBOBOXDLG_SIMPLE;
  1208.                break;
  1209.  
  1210.             case IDC_DROPDOWN:
  1211.                idPanel = PANEL_COMBOBOXDLG_DROPDOWN;
  1212.                break;
  1213.  
  1214.             case IDC_DROPDOWNLIST:
  1215.                idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST;
  1216.                break;
  1217.  
  1218.             case IDC_OK:
  1219.                idPanel = PANEL_COMBOBOXDLG_OK;
  1220.                break;
  1221.  
  1222.             case IDC_HELP:
  1223.                idPanel = PANEL_COMBOBOXDLG_HELP;
  1224.                break;
  1225.  
  1226.             default:
  1227.                /*
  1228.                 * Check to see if window that has the focus is the
  1229.                 * entry field of the combobox.  If it is, then
  1230.                 * call the appropriate combobox help panel.  If
  1231.                 * not, then call the unknown panel
  1232.                 */
  1233.                if (WinWindowFromID(WinWindowFromID(hwnd, IDC_SIMPLE),
  1234.                    CBID_EDIT) == hwndFocus)
  1235.                {
  1236.                   idPanel = PANEL_COMBOBOXDLG_SIMPLE;
  1237.                }
  1238.                else
  1239.                   if (WinWindowFromID(WinWindowFromID(hwnd, IDC_DROPDOWN),
  1240.                      CBID_EDIT) == hwndFocus)
  1241.                   {
  1242.                        idPanel = PANEL_COMBOBOXDLG_DROPDOWN;
  1243.                   }
  1244.                   else
  1245.                        if (WinWindowFromID(
  1246.                            WinWindowFromID(hwnd, IDC_DROPDOWNLIST),
  1247.                            CBID_EDIT) == hwndFocus)
  1248.                        {
  1249.                           idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST;
  1250.                        }
  1251.                        else
  1252.                           idPanel = PANEL_UNKNOWN;
  1253.               break;
  1254.          }
  1255.          break;
  1256.  
  1257.       case IDD_ENTRYFIELDDLG:
  1258.          switch(idItem)
  1259.          {
  1260.             case IDC_ENTRY:
  1261.                idPanel = PANEL_ENTRYFIELDDLG_ENTRY;
  1262.                break;
  1263.  
  1264.             case IDC_MLE:
  1265.                idPanel = PANEL_ENTRYFIELDDLG_MLE;
  1266.                break;
  1267.  
  1268.             case IDC_OK:
  1269.                idPanel = PANEL_ENTRYFIELDDLG_OK;
  1270.                break;
  1271.  
  1272.             case IDC_HELP:
  1273.                idPanel = PANEL_ENTRYFIELDDLG_HELP;
  1274.                break;
  1275.  
  1276.             default:
  1277.                idPanel = PANEL_UNKNOWN;
  1278.                break;
  1279.          }
  1280.          break;
  1281.  
  1282.       case IDD_STATICDLG:
  1283.          switch(idItem)
  1284.          {
  1285.             case IDC_OK:
  1286.                idPanel = PANEL_STATICDLG_OK;
  1287.                break;
  1288.  
  1289.             case IDC_HELP:
  1290.                idPanel = PANEL_STATICDLG_HELP;
  1291.                break;
  1292.  
  1293.             default:
  1294.                idPanel = PANEL_UNKNOWN;
  1295.                break;
  1296.          }
  1297.          break;
  1298.  
  1299.       case IDD_PPDEMODLG:
  1300.          switch(idItem)
  1301.          {
  1302.             case IDC_FORECOLORLIST:
  1303.                idPanel = PANEL_PPDEMODLG_FORECOLORLIST;
  1304.                break;
  1305.  
  1306.             case IDC_BACKCOLORLIST:
  1307.                idPanel = PANEL_PPDEMODLG_BACKCOLORLIST;
  1308.                break;
  1309.  
  1310.             case IDC_FONTLIST:
  1311.                idPanel = PANEL_PPDEMODLG_FONTLIST;
  1312.                break;
  1313.  
  1314.             case IDC_CHECKBOX:
  1315.                idPanel = PANEL_PPDEMODLG_TESTBUTTON;
  1316.                break;
  1317.  
  1318.             case IDC_CANCEL:
  1319.                idPanel = PANEL_PPDEMODLG_CANCEL;
  1320.                break;
  1321.  
  1322.             case IDC_APPLY:
  1323.                idPanel = PANEL_PPDEMODLG_APPLY;
  1324.                break;
  1325.  
  1326.             case IDC_HELP:
  1327.                idPanel = PANEL_PPDEMODLG_HELP;
  1328.                break;
  1329.  
  1330.             default:
  1331.             /*
  1332.              * Check to see if window that has the focus is the
  1333.              * entry field of the combobox.  If it is, then
  1334.              * call the appropriate combobox help panel.  If
  1335.              * not, then call the unknown panel
  1336.              */
  1337.                if (WinWindowFromID(
  1338.                    WinWindowFromID(hwnd, IDC_FORECOLORLIST),
  1339.                    CBID_EDIT) == hwndFocus)
  1340.                {
  1341.                   idPanel = PANEL_PPDEMODLG_FORECOLORLIST;
  1342.                }
  1343.                else
  1344.                   if (WinWindowFromID(
  1345.                       WinWindowFromID(hwnd, IDC_BACKCOLORLIST),
  1346.                       CBID_EDIT) == hwndFocus)
  1347.                   {
  1348.                      idPanel = PANEL_PPDEMODLG_BACKCOLORLIST;
  1349.                   }
  1350.                   else
  1351.                      if(WinWindowFromID(
  1352.                         WinWindowFromID(hwnd, IDC_FONTLIST),
  1353.                         CBID_EDIT) == hwndFocus)
  1354.                      {
  1355.                         idPanel = PANEL_PPDEMODLG_FONTLIST;
  1356.                      }
  1357.                      else
  1358.                         idPanel = PANEL_UNKNOWN;
  1359.                break;
  1360.          }
  1361.          break;
  1362.  
  1363.       case IDD_CONTAINERDLG:
  1364.          switch(idItem)
  1365.          {
  1366.             case IDC_CONTAINER:
  1367.                idPanel = PANEL_CONTAINERDLG_CONTAINER;
  1368.                break;
  1369.  
  1370.             case IDC_OK:
  1371.                idPanel = PANEL_CONTAINERDLG_OK;
  1372.                break;
  1373.  
  1374.             case IDC_CANCEL:
  1375.                idPanel = PANEL_CONTAINERDLG_CANCEL;
  1376.                break;
  1377.  
  1378.             case IDC_HELP:
  1379.                idPanel = PANEL_CONTAINERDLG_HELP;
  1380.                break;
  1381.  
  1382.             default:
  1383.                idPanel = PANEL_UNKNOWN;
  1384.                break;
  1385.          }
  1386.          break;
  1387.       case IDD_NOTEBOOKDLG:
  1388.          switch(idItem)
  1389.          {
  1390.             case IDC_NOTEBOOK:
  1391.                idPanel = PANEL_NOTEBOOKDLG_NOTEBOOK;
  1392.                break;
  1393.  
  1394.             case IDC_OK:
  1395.                idPanel = PANEL_NOTEBOOKDLG_OK;
  1396.                break;
  1397.  
  1398.             case IDC_CANCEL:
  1399.                idPanel = PANEL_NOTEBOOKDLG_CANCEL;
  1400.                break;
  1401.  
  1402.             case IDC_HELP:
  1403.                idPanel = PANEL_NOTEBOOKDLG_HELP;
  1404.                break;
  1405.  
  1406.             default:
  1407.                idPanel = PANEL_UNKNOWN;
  1408.                break;
  1409.         }
  1410.         break;
  1411.       case IDD_SLIDERDLG:
  1412.          switch(idItem)
  1413.          {
  1414.             case IDC_VSLIDER:
  1415.                idPanel = PANEL_SLIDERDLG_VSLIDER;
  1416.                break;
  1417.  
  1418.             case IDC_HSLIDER:
  1419.                idPanel = PANEL_SLIDERDLG_HSLIDER;
  1420.                break;
  1421.  
  1422.             case IDC_OK:
  1423.                idPanel = PANEL_SLIDERDLG_OK;
  1424.                break;
  1425.  
  1426.             case IDC_CANCEL:
  1427.                idPanel = PANEL_SLIDERDLG_CANCEL;
  1428.                break;
  1429.  
  1430.             case IDC_HELP:
  1431.                idPanel = PANEL_SLIDERDLG_HELP;
  1432.                break;
  1433.  
  1434.             default:
  1435.                idPanel = PANEL_UNKNOWN;
  1436.                break;
  1437.          }
  1438.          break;
  1439.       case IDD_VALUESETDLG:
  1440.          switch(idItem)
  1441.          {
  1442.             case IDC_VALUESET:
  1443.                idPanel = PANEL_VALUESETDLG_VALUESET;
  1444.                break;
  1445.  
  1446.             case IDC_OK:
  1447.                idPanel = PANEL_VALUESETDLG_OK;
  1448.                break;
  1449.  
  1450.             case IDC_CANCEL:
  1451.                idPanel = PANEL_VALUESETDLG_CANCEL;
  1452.                break;
  1453.  
  1454.             case IDC_HELP:
  1455.                idPanel = PANEL_VALUESETDLG_HELP;
  1456.                break;
  1457.  
  1458.             default:
  1459.                idPanel = PANEL_UNKNOWN;
  1460.                break;
  1461.          }
  1462.          break;
  1463.       case IDD_SPINBUTTONDLG:
  1464.          switch(idItem)
  1465.          {
  1466.             case IDC_MASTER:
  1467.                idPanel = PANEL_SPINBUTTONDLG_MASTER;
  1468.                break;
  1469.  
  1470.             case IDC_SERVANT:
  1471.                idPanel = PANEL_SPINBUTTONDLG_SERVANT;
  1472.                break;
  1473.  
  1474.             case IDC_OK:
  1475.                idPanel = PANEL_SPINBUTTONDLG_OK;
  1476.                break;
  1477.  
  1478.             case IDC_CANCEL:
  1479.                idPanel = PANEL_SPINBUTTONDLG_CANCEL;
  1480.                break;
  1481.  
  1482.             case IDC_HELP:
  1483.                idPanel = PANEL_SPINBUTTONDLG_HELP;
  1484.                break;
  1485.  
  1486.             default:
  1487.                idPanel = PANEL_UNKNOWN;
  1488.                break;
  1489.          }
  1490.          break;
  1491.  
  1492.       case IDD_PRODINFO:
  1493.          idPanel = PANEL_ABOUTBOX;
  1494.          break;
  1495.  
  1496.       default:
  1497.          idPanel = PANEL_UNKNOWNDLG;
  1498.          break;
  1499.    }
  1500.    DisplayHelpPanel(idPanel);
  1501. }                                       /* End of ShowDlgHelp()        */
  1502.  
  1503. /*********************************************************************
  1504.  *  Name : InitializeValueSet
  1505.  *
  1506.  *  Description : Loads the demo Value Set with 4 different icons
  1507.  *                and with 4 colors derived form the color index.
  1508.  *
  1509.  *  Concepts : Called each time a demo Value Set is initialized A
  1510.  *             for 1 to 4 loop sets an Icon in each column of the
  1511.  *             First row of the Value Set via a VM_SETITEM
  1512.  *             message.  The Second row is set to a color by
  1513.  *             sending the VM_SETITEMATTR message.
  1514.  *
  1515.  *  API's : WinSendDlgItemMsg
  1516.  *
  1517.  *  Parameters : hwnd - Handle of the Valueset dialog.
  1518.  *
  1519.  *  Returns: TRUE if Value Set is loaded successfully, FALSE otherwise
  1520.  *
  1521.  ****************************************************************/
  1522. BOOL InitializeValueSet(HWND hwnd)
  1523. {
  1524.    USHORT usIndex;
  1525.    for (usIndex = 1; usIndex <= 4;usIndex++)
  1526.    {
  1527.      if ( !WinSendDlgItemMsg(hwnd, IDC_VALUESET, VM_SETITEM,
  1528.            MPFROM2SHORT(1,usIndex),
  1529.            MPFROMLONG( WinLoadPointer(HWND_DESKTOP, 0,
  1530.            (IDR_MAIN + usIndex)))))
  1531.          return FALSE;
  1532.  
  1533.      if ( !WinSendDlgItemMsg( hwnd,IDC_VALUESET, VM_SETITEMATTR,
  1534.           MPFROM2SHORT(2,usIndex),
  1535.           MPFROM2SHORT( VIA_COLORINDEX, TRUE )))
  1536.         return FALSE;
  1537.  
  1538.      if ( !WinSendDlgItemMsg(hwnd, IDC_VALUESET, VM_SETITEM,
  1539.           MPFROM2SHORT(2,usIndex),
  1540.           MPFROMSHORT(usIndex)))
  1541.         return FALSE;
  1542.    }
  1543.    return TRUE;
  1544. }                                       /* End of InitializeValueset    */
  1545. /*********************************************************************
  1546.  *  Name : InitializeSlider
  1547.  *
  1548.  *  Description :  Set the Sliders Tick size and Scale Text.
  1549.  *
  1550.  *  Concepts : Called each time a demo Slider controls ar initialized
  1551.  *             Ses the he initail value of the sliders output display
  1552.  *             to 0. A for 0 to 10 for loop sets the ruler text and
  1553.  *             tick size for both the Horizontal and Vertical Sliders
  1554.  *             via SLM_SETSCALETEXT and SLM_SETTICKSIZE message.
  1555.  *
  1556.  *  API's : WinSendDlgItemMsg
  1557.  *
  1558.  *  Parameters : hwnd - Handle of the Slider dialog.
  1559.  *
  1560.  *  Returns: TRUE if Sliders are initialized successfully, FALSE otherwise
  1561.  *
  1562.  *******************************************************************/
  1563. BOOL InitializeSlider(HWND hwnd)
  1564. {
  1565.    USHORT usIndex;
  1566.    CHAR   acBuffer[4];
  1567.    CHAR   *cData;
  1568.  
  1569.  
  1570.    cData = _ltoa(0,acBuffer,10);
  1571.    WinSetDlgItemText(hwnd,IDC_HSLIDERDATA, cData);
  1572.    WinSetDlgItemText(hwnd,IDC_VSLIDERDATA, cData);
  1573.    for (usIndex = 0;usIndex < 10 ;usIndex ++ )
  1574.    {
  1575.       _itoa(usIndex,acBuffer,10);
  1576.       if ( !WinSendDlgItemMsg(hwnd, IDC_HSLIDER, SLM_SETTICKSIZE,
  1577.                MPFROM2SHORT(usIndex, 5), NULL))
  1578.         return FALSE;
  1579.  
  1580.       if ( !WinSendDlgItemMsg(hwnd, IDC_HSLIDER, SLM_SETSCALETEXT,
  1581.                MPFROMSHORT(usIndex), MPFROMP(acBuffer)))
  1582.         return FALSE;
  1583.  
  1584.       if ( !WinSendDlgItemMsg(hwnd, IDC_VSLIDER, SLM_SETTICKSIZE,
  1585.                MPFROM2SHORT(usIndex, 5), NULL))
  1586.         return FALSE;
  1587.  
  1588.       if ( !WinSendDlgItemMsg(hwnd, IDC_VSLIDER, SLM_SETSCALETEXT,
  1589.                  MPFROMSHORT(usIndex), MPFROMP(acBuffer)))
  1590.         return FALSE;
  1591.    }
  1592.    return TRUE;
  1593. }                                       /* End of InitializeSlider      */
  1594.  
  1595. /*********************************************************************
  1596.  *  Name : InitializeSpinButton
  1597.  *
  1598.  *  Description : Set the intital values for the spin button controls.
  1599.  *
  1600.  *  Concepts : Sends a SPBM_SETARRAY to the Master Spin Button to set
  1601.  *             the values (text strings) available to the control.
  1602.  *             Sets the initial value to the array index of 0 by
  1603.  *             sending a SPBM_SETCURRENTVALUE.  The Servant Spin Button
  1604.  *             is initialized to the range 0 to 100 by sending a
  1605.  *             SPBM_SETLIMITS message.  Sends a SPBM_SETMASTER message
  1606.  *             to set the MASTER/SERVANT relationship between the two
  1607.  *             spin buttons.
  1608.  *
  1609.  *  API's : WinSendDlgItemMsg
  1610.  *          WinWindowFromID
  1611.  *
  1612.  *  Parameters : hwnd - Handle of the Spinnbutton dialog.
  1613.  *
  1614.  *  Returns: TRUE if Spinbuttons are initialized successfully, FALSE otherwise
  1615.  *
  1616.  ****************************************************************/
  1617. BOOL InitializeSpinButton(HWND hwnd)
  1618. {
  1619.    static PSZ   spinColors[] = {"White", "Black", "Blue", "Red"," Pink",
  1620.                      "Green", "Cyan", "Yellow", "Dark Grey", "Dark Blue",
  1621.                      "Dark Red", "Dark Pink", "Dark Green", "Dark Cyan",
  1622.                      "Brown", "Pale Grey"};
  1623.  
  1624.    if ( !WinSendDlgItemMsg( hwnd, IDC_MASTER, SPBM_SETARRAY, spinColors,
  1625.              MPFROMLONG(NUMSPINCOLORS)))
  1626.       return FALSE;
  1627.  
  1628.    if ( !WinSendDlgItemMsg( hwnd, IDC_MASTER, SPBM_SETCURRENTVALUE,
  1629.              MPFROMLONG(0), NULL))
  1630.       return FALSE;
  1631.  
  1632.    if ( !WinSendDlgItemMsg( hwnd, IDC_SERVANT, SPBM_SETLIMITS,
  1633.              MPFROMLONG(100), MPFROMLONG(0)))
  1634.       return FALSE;
  1635.  
  1636.    if ( !WinSendDlgItemMsg( hwnd, IDC_SERVANT, SPBM_SETCURRENTVALUE,
  1637.              MPFROMLONG(0), NULL))
  1638.       return FALSE;
  1639.  
  1640.    if (!WinSendDlgItemMsg(
  1641.            hwnd,
  1642.            IDC_SERVANT,
  1643.            SPBM_SETMASTER,
  1644.            MPFROMHWND( WinWindowFromID(hwnd, IDC_MASTER)),
  1645.            MPVOID)
  1646.       )
  1647.       return FALSE;
  1648.    return TRUE;
  1649. }                                       /* End of InitializeSpinbutton  */
  1650.  
  1651. /*********************************************************************
  1652.  *  Name : InitializeNotebook
  1653.  *
  1654.  *  Description : Set the intital pages for a notebook control.
  1655.  *
  1656.  *  Concepts : Called each time a demo NoteBook Control is
  1657.  *             initialized Sends a BKM_INSERTPAGE message to the
  1658.  *             notebook control to insert the first page into the
  1659.  *             control.  Sets the status line text for the first page
  1660.  *             by sending a BKM_SETSTATUSLINETEXT message.  Creates a
  1661.  *             window containing a bitmap and associates the whidow
  1662.  *             with the notebook by sending a BKM_SETPAGEWINDOWHWND
  1663.  *             message.  Repeats these steps with the execption of
  1664.  *             createing a MLE for use in the second notebook page.
  1665.  *
  1666.  *  API's : WinSendDlgItemMsg
  1667.  *          WinCreateWindow
  1668.  *          WinSendMsg
  1669.  *
  1670.  *  Parameters :  hwnd - Handle of the Notebook dialog
  1671.  *
  1672.  *  Returns: TRUE if The NoteBook is initialized successfully, FALSE otherwise
  1673.  *
  1674.  ****************************************************************/
  1675. BOOL InitializeNoteBook(HWND hwnd)
  1676. {
  1677.    HWND hwndPage;
  1678.    ULONG ulPageId;
  1679.    ULONG ipt = 0;
  1680.    CHAR pszMleBuffer[512];
  1681.    PSZ   pszNoteBookText =
  1682.    {"Applications written for the Presentation Manager have full\
  1683.     access to the complete set of user interface tools: menus,\
  1684.     icons, scroll bars, etc., and often present a WYSIWYG\
  1685.     (what-you-see-is-what-you-get) view of their data.\
  1686.     Presentation Manager programs often make extensive use\
  1687.     of a mouse and display, and they have access to all the\
  1688.     32-bit features of version 2.0."};
  1689.  
  1690.    /*
  1691.     * Insert the first page.
  1692.     */
  1693.    ulPageId = (LONG)WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1694.         BKM_INSERTPAGE, NULL,
  1695.         MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  1696.         BKA_LAST));
  1697.  
  1698.    if ( !ulPageId)
  1699.      return FALSE;
  1700.  
  1701.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1702.         BKM_SETSTATUSLINETEXT, MPFROMLONG(ulPageId),
  1703.         MPFROMP("Page 1 of 2")))
  1704.      return FALSE;
  1705.  
  1706.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1707.         BKM_SETTABTEXT, MPFROMLONG(ulPageId),
  1708.         MPFROMP("~1")))
  1709.      return FALSE;
  1710.  
  1711.    hwndPage =
  1712.    WinCreateWindow(               /* parent-window handle                    */
  1713.       hwnd,                       /* pointer to registered class name        */
  1714.       WC_STATIC,                  /* pointer to window text                  */
  1715.       "#6",                       /* window style                            */
  1716.       WS_VISIBLE | SS_BITMAP,     /* horizontal position of window           */
  1717.       0,                          /* vertical position of window             */
  1718.       0,                          /* window width                            */
  1719.       0,                          /* window height                           */
  1720.       0,                          /* owner-window handle                     */
  1721.       NULLHANDLE,                 /* handle to sibling window                */
  1722.       HWND_TOP,                   /* window identifier                       */
  1723.       0,                          /* pointer to buffer                       */
  1724.       NULL,                       /* pointer to structure with pres. params. */
  1725.       NULL);
  1726.  
  1727.    if (!hwndPage)
  1728.      return FALSE;
  1729.  
  1730.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1731.          BKM_SETPAGEWINDOWHWND, MPFROMLONG(ulPageId),
  1732.          MPFROMHWND(hwndPage)))
  1733.      return FALSE;
  1734.  
  1735.    /*
  1736.     * Insert the second page.
  1737.     */
  1738.     ulPageId = (LONG)WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1739.          BKM_INSERTPAGE, NULL,
  1740.          MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  1741.          BKA_LAST));
  1742.  
  1743.    if (!ulPageId)
  1744.      return FALSE;
  1745.  
  1746.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1747.          BKM_SETSTATUSLINETEXT, MPFROMLONG(ulPageId),
  1748.          MPFROMP("Page 2 of 2")))
  1749.      return FALSE;
  1750.  
  1751.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1752.         BKM_SETTABTEXT, MPFROMLONG(ulPageId),
  1753.         MPFROMP("~2")))
  1754.      return FALSE;
  1755.  
  1756.    hwndPage =
  1757.    WinCreateWindow(
  1758.       hwnd,                       /* parent-window handle                    */
  1759.       WC_MLE,                     /* pointer to registered class name        */
  1760.       NULL,                       /* pointer to window text                  */
  1761.       WS_VISIBLE | MLS_WORDWRAP | /* window style                            */
  1762.          MLS_READONLY,
  1763.       0,                          /* horizontal position of window           */
  1764.       0,                          /* vertical position of window             */
  1765.       0,                          /* window width                            */
  1766.       0,                          /* window height                           */
  1767.       NULLHANDLE,                 /* owner-window handle                     */
  1768.       HWND_TOP,                   /* handle to sibling window                */
  1769.       0,                          /* window identifier                       */
  1770.       NULL,                       /* pointer to buffer                       */
  1771.       NULL);                      /* pointer to structure with pres. params. */
  1772.  
  1773.    if (!hwndPage)
  1774.      return FALSE;
  1775.  
  1776.    if ( !WinSendMsg(hwndPage, MLM_SETIMPORTEXPORT,
  1777.          MPFROMP(pszMleBuffer),
  1778.          MPFROMSHORT(sizeof(pszMleBuffer))))
  1779.      return FALSE;
  1780.  
  1781.      memset(pszMleBuffer,'\0',sizeof(pszMleBuffer));
  1782.      strcpy(pszMleBuffer, pszNoteBookText);
  1783.  
  1784.    if ( !WinSendMsg(hwndPage, MLM_IMPORT, &ipt,
  1785.          MPFROMSHORT(sizeof(pszMleBuffer))))
  1786.      return FALSE;
  1787.  
  1788.    if( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  1789.          BKM_SETPAGEWINDOWHWND, MPFROMLONG(ulPageId),
  1790.          MPFROMHWND(hwndPage)))
  1791.      return FALSE;
  1792.  
  1793.    return TRUE;
  1794. }                                       /* End of InitializeNotebook    */
  1795.  
  1796. /*********************************************************************
  1797.  *  Name : InitializeContainer
  1798.  *
  1799.  *  Description : Initialize and insert a record into the container.
  1800.  *
  1801.  *
  1802.  *  Concepts : Called each time a demo Container Control is initialized.
  1803.  *             Allocates and inserts a user record into a container.
  1804.  *             Allocates and inserst  details view information.
  1805.  *             Sets the containers info.
  1806.  *
  1807.  *  API's : WinLoadPointer
  1808.  *          WinSendDlgItemMsg
  1809.  *
  1810.  *  Parameters : hwnd - Handle of the container dialog.
  1811.  *
  1812.  *  Returns: TRUE if The Container is initialized successfully, FALSE otherwise
  1813.  *
  1814.  ****************************************************************/
  1815. BOOL InitializeContainer(HWND hwnd)
  1816. {
  1817.  
  1818.   USHORT            nRecords = 1;
  1819.   HPOINTER          hptr;
  1820.   ULONG             cbRecordData;
  1821.  
  1822.   hptr = WinLoadPointer(HWND_DESKTOP, 0, IDR_MAIN);
  1823.  
  1824.   cbRecordData = (LONG) (sizeof(USERRECORD) - sizeof(RECORDCORE));
  1825.   pUserRecord = WinSendDlgItemMsg(hwnd,IDC_CONTAINER,
  1826.                    CM_ALLOCRECORD, MPFROMLONG(cbRecordData) ,
  1827.                    MPFROMSHORT(nRecords));
  1828.  
  1829.   pUserRecord->recordCore.cb = sizeof(RECORDCORE);              /*RBS*/
  1830.   pUserRecord->recordCore.pszText = pszViewText;
  1831.   pUserRecord->recordCore.pszIcon = pszViewIcon;
  1832.   pUserRecord->recordCore.pszName = pszViewName;
  1833.   pUserRecord->recordCore.hptrIcon = hptr;
  1834.  
  1835.   pUserRecord->date.day = 11;
  1836.   pUserRecord->date.month = 11;
  1837.   pUserRecord->date.year = 11;
  1838.   pUserRecord->time.seconds    = 12;
  1839.   pUserRecord->time.minutes    = 12;
  1840.   pUserRecord->time.hours      = 12;
  1841.   pUserRecord->recordData = (PSZ)pszSampleData;
  1842.  
  1843.   recordInsert.cb = sizeof(RECORDINSERT);                   /*RBS*/
  1844.   recordInsert.pRecordParent= NULL;
  1845.   recordInsert.pRecordOrder = (PRECORDCORE)CMA_END;
  1846.   recordInsert.zOrder = CMA_TOP;
  1847.   recordInsert.cRecordsInsert = 1;
  1848.   recordInsert.fInvalidateRecord = TRUE;
  1849.  
  1850.   WinSendDlgItemMsg(hwnd,IDC_CONTAINER, CM_INSERTRECORD,
  1851.                    (PRECORDCORE)pUserRecord, &recordInsert);
  1852.  
  1853.   pFieldInfo = WinSendDlgItemMsg(hwnd, IDC_CONTAINER,
  1854.                         CM_ALLOCDETAILFIELDINFO,MPFROMLONG(3), NULL);
  1855.  
  1856.   firstFieldInfo = pFieldInfo;
  1857.  
  1858.   pFieldInfo->cb = sizeof(FIELDINFO);                       /*RBS*/
  1859.   pFieldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_CENTER |
  1860.                          CFA_SEPARATOR;
  1861.   pFieldInfo->flTitle = CFA_CENTER;
  1862.   pFieldInfo->pTitleData = (PVOID) pszColumnText1;
  1863.   pFieldInfo->offStruct = FIELDOFFSET(USERRECORD,recordData);
  1864.   pFieldInfo = pFieldInfo->pNextFieldInfo;
  1865.  
  1866.   pFieldInfo->cb = sizeof(FIELDINFO);                       /*RBS*/
  1867.   pFieldInfo->flData = CFA_DATE | CFA_HORZSEPARATOR | CFA_CENTER |
  1868.                          CFA_SEPARATOR;
  1869.   pFieldInfo->flTitle = CFA_CENTER;
  1870.   pFieldInfo->pTitleData =  (PVOID) pszColumnText2;
  1871.   pFieldInfo->offStruct = FIELDOFFSET(USERRECORD,date);
  1872.   pFieldInfo = pFieldInfo->pNextFieldInfo;
  1873.  
  1874.   pFieldInfo->cb = sizeof(FIELDINFO);                       /*RBS*/
  1875.   pFieldInfo->flData = CFA_TIME | CFA_HORZSEPARATOR | CFA_CENTER |
  1876.                          CFA_SEPARATOR;
  1877.   pFieldInfo->flTitle = CFA_CENTER;
  1878.   pFieldInfo->pTitleData = (PVOID) pszColumnText3;
  1879.   pFieldInfo->offStruct = FIELDOFFSET(USERRECORD,time);
  1880.  
  1881.  
  1882.   fieldInfoInsert.cb = (ULONG)(sizeof(FIELDINFOINSERT));    /*RBS*/
  1883.   fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST;
  1884.   fieldInfoInsert.cFieldInfoInsert = 3;
  1885.   fieldInfoInsert.fInvalidateFieldInfo = TRUE;              /*RBS*/
  1886.  
  1887.   pFieldInfoInsert = &fieldInfoInsert;
  1888.  
  1889.   WinSendDlgItemMsg(hwnd,IDC_CONTAINER, CM_INSERTDETAILFIELDINFO,
  1890.                     MPFROMP(firstFieldInfo),
  1891.                     MPFROMP(pFieldInfoInsert));
  1892.  
  1893.   WinSendDlgItemMsg(hwnd,IDC_CONTAINER,CM_SETCNRINFO,&cnrinfo,
  1894.                      MPFROMLONG(CMA_FLWINDOWATTR | CMA_CNRTITLE));
  1895.  
  1896. return TRUE;
  1897. }                                       /* End of InitializeContainer    */
  1898. /***********************************************************
  1899.  * Name         : SetSysMenu
  1900.  *
  1901.  * Description  : Procedure to remove unselectable items from
  1902.  *                the window system menu.
  1903.  *
  1904.  * Concepts     : This routine determines the number of items
  1905.  *                in the system menu, loops through those
  1906.  *                items removing disabled menu items and menu
  1907.  *                seperators.
  1908.  *
  1909.  * API's        : WinMessageBox
  1910.  *
  1911.  * Parameters   : None
  1912.  *
  1913.  * Return       : None
  1914.  *
  1915.  **************************************************************/
  1916. VOID SetSysMenu(HWND hwndDlg)
  1917. {
  1918.   SHORT sMenuItems;
  1919.   USHORT usItemid;
  1920.   MENUITEM menuItem;
  1921.   HWND  hwndSubMenu;
  1922.  
  1923.   /* Determine the definition of the system menu */
  1924.   WinSendDlgItemMsg(hwndDlg, FID_SYSMENU, MM_QUERYITEM,
  1925.                     MPFROM2SHORT((SHORT)SC_SYSMENU,FALSE),
  1926.                     MPFROMP(&menuItem));
  1927.  
  1928.   hwndSubMenu = menuItem.hwndSubMenu;
  1929.  
  1930.   /* Find the number of items in the in the submenu */
  1931.   sMenuItems = (SHORT)WinSendMsg(hwndSubMenu,
  1932.                                  MM_QUERYITEMCOUNT,NULL,NULL);
  1933.   /*
  1934.    * Loop through the submenu items and remove disabled
  1935.    * menu items and menu separators.
  1936.    */
  1937.   for (sMenuItems - 1 ; sMenuItems >= 0 ;sMenuItems-- )
  1938.   {
  1939.     /* Find the item ID for the current position. */
  1940.     usItemid = (USHORT)WinSendMsg(hwndSubMenu,MM_ITEMIDFROMPOSITION,
  1941.                          MPFROMSHORT(sMenuItems), NULL);
  1942.  
  1943.     /* Query the definition of the current item*/
  1944.     WinSendMsg(hwndSubMenu, MM_QUERYITEM,
  1945.                MPFROM2SHORT(usItemid,FALSE), MPFROMP(&menuItem));
  1946.  
  1947.    /*
  1948.     * If the menu item is disabled or the item has a style
  1949.     * of MIS_SEPARATOR - delete it.
  1950.     */
  1951.     if ((BOOL)(WinSendMsg(hwndSubMenu, MM_QUERYITEMATTR,
  1952.           MPFROM2SHORT(usItemid,FALSE), (MPARAM)MIA_DISABLED)) ||
  1953.           (menuItem.afStyle & MIS_SEPARATOR))
  1954.     {
  1955.       WinSendMsg(hwndSubMenu, MM_DELETEITEM,
  1956.                 MPFROM2SHORT(usItemid,FALSE),NULL);
  1957.     }
  1958.   }
  1959. }                                       /* End of SetSysMenu()           */
  1960.