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