File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / style / sty_dlg.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:30 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  Dialog.c - window procedures for the dialog boxes as well
 *              as utility procedures used by them
 *      Created 1990, Microsoft, IBM  Corp.
 *--------------------------------------------------------------
 *
 *  This module contains the Dialog Procedures for the user
 *  defined dialogs as well as any support code they need
 *
 *--------------------------------------------------------------
 *
 *  This source file contains the following functions:
 *
 *           DemoDlgProc(hwnd, msg, mp1, mp2)
 *           PresParamDemoDlgProc(hwnd, msg, mp1, mp2)
 *           AboutBoxDlgProc(hwnd, msg, mp1, mp2)
 *           LoadListBox(hwnd)
 *           InitPresParamDemoDlg(hwnd)
 *           UpdatePresParamDemoDlg(hwnd)
 *
\*==============================================================*/

/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs
\*--------------------------------------------------------------*/

#define INCL_WINWINDOWMGR
#define INCL_WININPUT
#define INCL_WINLISTBOXES
#define INCL_WINENTRYFIELDS
#define INCL_WINSYS
#define INCL_GPILCIDS
#define INCL_DOSMEMMGR

#include <os2.h>
#include <string.h>
#include "sty_main.h"
#include "sty_dlg.h"
#include "sty_xtrn.h"
#include "sty_help.h"

#define COLORNAMELEN    20
#define NUMCOLORS       15  /* number of colors used in PP Demo */
#define NUMFONTS         4  /* number of fonts used in PP Demo */
#define FONTPOINTSIZE   80  /* point size to use in PP Demo */
#define PPFONTPOINTSIZE  2  /* length of font point prefix */

/*--------------------------------------------------------------*\
 *  Global variables
\*--------------------------------------------------------------*/
static CHAR apszPresParamColor[NUMCOLORS][COLORNAMELEN]; /* array of clr names */
static PSZ *apszPresParamFont = NULL;
static LONG lNumFonts;

/* set up an array of colors in the same order as the stringtable
    constants */
static ULONG aulColor[NUMCOLORS-1] = {  CLR_BLUE,
                                        CLR_RED,
                                        CLR_PINK,
                                        CLR_GREEN,
                                        CLR_CYAN,
                                        CLR_YELLOW,
                                        CLR_DARKGRAY,
                                        CLR_DARKBLUE,
                                        CLR_DARKRED,
                                        CLR_DARKPINK,
                                        CLR_DARKGREEN,
                                        CLR_DARKCYAN,
                                        CLR_BROWN,
                                        CLR_PALEGRAY
                                      };


/*--------------------------------------------------------------*\
 *  Entry point declarations
\*--------------------------------------------------------------*/

MRESULT EXPENTRY AboutBoxDlgProc(HWND hwnd, USHORT msg,
                                  MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg,
                                  MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg,
                                  MPARAM mp1, MPARAM mp2);
BOOL LoadListBox(HWND hwnd);
BOOL InitPresParamDemoDlg(HWND hwnd);
BOOL UpdatePresParamDemoDlg(HWND hwnd);
VOID ShowDlgHelp(HWND hwnd);


/****************************************************************\
 *  Dialog procedure for the About dialog box
 *--------------------------------------------------------------
 *
 *  Name:   AboutBoxDlgProc(hwnd, msg, mp1, mp2)
 *
 *  Purpose: Processes all messages sent to the About Box
 *
 *  Usage:  Called for each message sent to the About Box
 *          dialog box.
 *
 *  Method: the about box only has a button control so this
 *          routine only processes WM_COMMAND messages.  Any
 *          WM_COMMAND posted must have come from the Ok
 *          button so we dismiss the dialog upon receiving it.
 *
 *  Returns: Dependent upon message sent
 *
\****************************************************************/
MRESULT EXPENTRY AboutBoxDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;      /* handle of window */
USHORT msg;     /* id of message */
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{
    switch(msg)  {
        case WM_COMMAND:
            /* no matter what the command, close the dialog */
            WinDismissDlg(hwnd, TRUE);
            break;

        case WM_HELP:
            ShowDlgHelp(hwnd);
            break;

        default:
            return(WinDefDlgProc(hwnd, msg, mp1, mp2));
            break;
    }

    return 0L;

}   /* AboutBoxDlgProc() */

/****************************************************************\
 *  Dialog procedure for the Dialog control demo dialogs
 *--------------------------------------------------------------
 *
 *  Name:   DemoDlgProc(hwnd, msg, mp1, mp2)
 *
 *  Purpose: Processes all messages sent to all Demo dialogs.
 *          The Demo dialogs only have an Ok and a Help button
 *          so they can all share this dialog proc.
 *
 *  Usage:  Called for each message sent to a demo dialog box.
 *
 *  Method: a switch statement branches to the routines to be
 *          performed for each message processed.  Any messages
 *          not specifically process are passed to the default
 *          window procedure WinDefDlgProc()
 *
 *  Returns: Dependent upon message sent
 *
\****************************************************************/
MRESULT EXPENTRY DemoDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;      /* handle of window */
USHORT msg;     /* id of message */
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{
    switch(msg)  {
        case WM_INITDLG:
            switch(SHORT1FROMMP(mp2))  {
                /*---------------------------------------------*
                 * The ShowDemoDlg() filled mp2 with the id of
                 * the dialog template used to create the
                 * dialog box.  If the dialog contains listboxes
                 * or comboboxes, fill them with text.
                 *---------------------------------------------*/

                case IDD_LISTBOXDLG:
                    /* Load some text into the list boxes.  If any of the
                        LoadListBox() routines fail, abort the dialog */
                    if(
                    !LoadListBox(WinWindowFromID(hwnd, IDC_LISTBOX)) ||
                    !LoadListBox(WinWindowFromID(hwnd, IDC_MULTISELLISTBOX)))
                        WinDismissDlg(hwnd, FALSE);
                    break;

                case IDD_COMBOBOXDLG:
                    /* Load some text into the combo boxes.  If any of the
                        LoadListBox() routines fail, abort the dialog */
                    if(!LoadListBox(WinWindowFromID(hwnd, IDC_SIMPLE)) ||
                       !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWN)) ||
                       !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWNLIST)))
                        WinDismissDlg(hwnd, FALSE);
                    break;

                default:
                    break;
            }
            return FALSE;
            break;

        case WM_COMMAND:
            if(SHORT1FROMMP(mp1) == IDC_OK || SHORT1FROMMP(mp1) == IDC_CANCEL)
                /* close the dialog if the Ok button is presssed */
                WinDismissDlg(hwnd, TRUE);
            break;

        case WM_HELP:
            ShowDlgHelp(hwnd);
            break;

        default:
            return(WinDefDlgProc(hwnd, msg, mp1, mp2));
            break;
    }

    return 0L;

}   /* DemoDlgProc() */

/****************************************************************\
 *  Loads the given listbox with strings of 0 to 9
 *--------------------------------------------------------------
 *
 *  Name:   LoadListBox(hwnd)
 *
 *  Purpose: Loads the demo list box with 0 through 9
 *
 *  Usage:  Called each time a demo list box is initialized
 *
 *  Method: a for 0 to 9 loop is converts the INT to a string
 *          which is added to the listbo via LM_INSERTITEM
 *
 *  Returns: TRUE if list box is loaded successfully, FALSE otherwise
 *
\****************************************************************/
BOOL LoadListBox(hwnd)
HWND hwnd;      /* handle of list box window */
{
    register SHORT sT;
    CHAR szT[MESSAGELEN];
    SHORT sRet;

    for(sT = 0; sT < 10; sT++)  {
        if(!WinLoadString(hab,
                          NULL,
                          IDS_LISTBOX1 + sT,
                          MESSAGELEN,
                          (PSZ)szT))  {

            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
        }

        sRet = (SHORT)WinSendMsg(hwnd,
                                 LM_INSERTITEM,
                                 MPFROMSHORT(LIT_SORTASCENDING),
                                 MPFROMP((PSZ)szT));

        if(sRet == LIT_ERROR || sRet == LIT_MEMERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
        }
    }

    return TRUE;

}   /* LoadListBox() */


/****************************************************************\
 *  Dialog procedure for the Presentation Parameter demo dialog
 *--------------------------------------------------------------
 *
 *  Name:   PresParamDemoDlgProc(hwnd, msg, mp1, mp2)
 *
 *  Purpose: Processes all messages sent to the PresParamDemo dialog
 *
 *  Usage:  Called for each message sent to the PresParamDemo
 *          dialog box.
 *
 *  Method: a switch statement branches to the routines to be
 *          performed for each message processed.  Any messages
 *          not specifically process are passed to the default
 *          window procedure WinDefDlgProc()
 *
 *  Returns: Dependent upon message sent
 *
\****************************************************************/
MRESULT EXPENTRY PresParamDemoDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;      /* handle of window */
USHORT msg;     /* id of message */
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{
    switch(msg)  {
        case WM_INITDLG:
            /* if initialization fails, abort the dialog */
            if(!InitPresParamDemoDlg(hwnd))
                WinDismissDlg(hwnd, FALSE);
            return FALSE;
            break;

        case WM_COMMAND:
            switch(SHORT1FROMMP(mp1))  {
                case IDC_CANCEL:      /* if done, close the dialog */
                    WinDismissDlg(hwnd, TRUE);
                    break;

                case IDC_APPLY:     /* update the dialog */
                    UpdatePresParamDemoDlg(hwnd);
                    break;

                default:
                    break;
            }
            break;

        case WM_HELP:
            ShowDlgHelp(hwnd);
            break;

        default:
            return(WinDefDlgProc(hwnd, msg, mp1, mp2));
            break;
    }

    return 0L;

}   /* PresParamDemoDlgProc() */

/****************************************************************\
 *  Initializes the Presentation Parameter Dialog
 *--------------------------------------------------------------
 *
 *  Name:   InitPresParamDemoDlg(hwnd)
 *
 *  Purpose: Places the colors and fonts into the PresParamDemoDlg's
 *          comboboxes
 *
 *  Usage:  Called when the PP demo dialog is initialized
 *
 *  Method: LM_INSERTITEM is sent to each combobox for the
 *          color or font string added to the combobox
 *
 *  Returns: TRUE if initialization is successfull, FALSE if not
 *
\****************************************************************/
BOOL InitPresParamDemoDlg(hwnd)
HWND hwnd;      /* handle of the dialog window */
{
    HWND hwndT;
    register SHORT sT;
    SHORT sRet;
    PFONTMETRICS pfm, pfmSave;
    LONG lT, lFonts;
    HPS hps;
    PSZ *ppszT;
    BOOL fHaveFont;


    /* load the color table */
    for(sT = 0; sT < NUMCOLORS; sT++)  {
        if(!WinLoadString(hab,
                          NULL,
                          sT + IDS_FIRSTCOLOR,
                          COLORNAMELEN,
                          (PSZ)apszPresParamColor[sT]))  {

            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
        }
    }

    /* load foreground color combo box */
    hwndT = WinWindowFromID(hwnd, IDC_FORECOLORLIST);

    for(sT = 0; sT < NUMCOLORS; sT++)  {
        sRet = (SHORT)WinSendMsg(hwndT,
                                 LM_INSERTITEM,
                                 MPFROMSHORT(LIT_SORTASCENDING),
                                 MPFROMP((PSZ)apszPresParamColor[sT]));

        if(sT == LIT_ERROR || sT == LIT_MEMERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
        }

    }

    /* load background color combo box */
    hwndT = WinWindowFromID(hwnd, IDC_BACKCOLORLIST);

    for(sT = 0; sT < NUMCOLORS; sT++)  {
        sRet = (SHORT)WinSendMsg(hwndT,
                                 LM_INSERTITEM,
                                 MPFROMSHORT(LIT_SORTASCENDING),
                                 MPFROMP((PSZ)apszPresParamColor[sT]));

        if(sT == LIT_ERROR || sT == LIT_MEMERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
        }
    }


    /* Fonts.  Find all of the fonts of point size desired and normal
        weight.  Put the facenames in the combo box */
    hwndT = WinWindowFromID(hwnd, IDC_FONTLIST);
    hps = WinGetPS(hwndT);

    /* determine the number of fonts available */
    lFonts = 0L;
    lT = 0L;
    lFonts = GpiQueryFonts(hps,
                           QF_PUBLIC,
                           NULL,
                           &lT,
                           (ULONG)sizeof(FONTMETRICS),
                           (PFONTMETRICS)NULL);

    if(lFonts == GPI_ALTERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADFONTS,
                       MB_OK | MB_ERROR,
                       FALSE);

            WinReleasePS(hps);
            return FALSE;
    }


    /* allocate buffer for fontmetric structures */
    if(DosAllocMem((PPVOID)&pfm,
                    lFonts * (ULONG)sizeof(FONTMETRICS),
                    fALLOC))  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTALLOCATEMEMORY,
                       MB_OK | MB_ERROR,
                       FALSE);

            WinReleasePS(hps);
            return FALSE;
    }
    pfmSave = pfm;

    /* get all fonts */
    lT = GpiQueryFonts(hps,
                       QF_PUBLIC,
                       NULL,
                       &lFonts,
                       (ULONG)sizeof(FONTMETRICS),
                       (PFONTMETRICS)pfm);

    WinReleasePS(hps);

    if(lT == GPI_ALTERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADFONTS,
                       MB_OK | MB_ERROR,
                       FALSE);

            return FALSE;
    }

    /* allocate buffer for array of string names, freeing the first
        buffer if necessary */
    if(apszPresParamFont)  {
        ppszT = apszPresParamFont;
        while(*ppszT)  {
            DosFreeMem(*ppszT++);
        }

        DosFreeMem(apszPresParamFont);
    }

    if(DosAllocMem((PPVOID)&apszPresParamFont,
                    (lFonts + 1L) * (ULONG)sizeof(PSZ),
                    fALLOC))  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTALLOCATEMEMORY,
                       MB_OK | MB_ERROR,
                       FALSE);

            DosFreeMem((PVOID)pfmSave);
            apszPresParamFont = NULL;
            return FALSE;
    }

    /* initialize array to NULL */
    lT = 0L;
    ppszT = apszPresParamFont;
    while(lT++ < lFonts)
        *ppszT++ = (PSZ)NULL;
    *ppszT = (PSZ)NULL;


    /* walk through all fonts.  If the font matches the point size
        desired and has a weight and width class of normal (5) and
        no special attributes (e. g. italic, underline, etc.).  If
        it does, then add its string to the combo box */
    lNumFonts = 0L;
    ppszT = apszPresParamFont;

    while(lFonts--)  {
        if(pfm->sNominalPointSize == FONTPOINTSIZE &&
           pfm->usWeightClass == 5 &&
           pfm->usWidthClass == 5 &&
           pfm->fsSelection == 0)  {

            /* make sure we don't have this font.  If we don't,
                then add the font to the list */
            lT = 0L;
            fHaveFont = FALSE;
            while(lT < lNumFonts)  {
                if(!strcmp(pfm->szFacename,
                            apszPresParamFont[(INT)lT]))  {
                    fHaveFont = TRUE;
                    break;
                } else
                    lT++;
            }

            if(!fHaveFont)  {
                if(DosAllocMem((PPVOID)ppszT,
                                (LONG)(FACESIZE * sizeof(CHAR)),
                                fALLOC))  {

                        MessageBox(hwndMain,
                                   IDMSG_CANNOTALLOCATEMEMORY,
                                   MB_OK | MB_ERROR,
                                   FALSE);

                        DosFreeMem((PVOID)pfmSave);
                        return FALSE;
                }

                strcpy(*ppszT++, pfm->szFacename);
                lNumFonts++;
            }
        }

        pfm++;
    }


    /* install the name of each font into the combo box */
    ppszT = apszPresParamFont;
    while(*ppszT)  {
        lT = (LONG)WinSendMsg(hwndT,
                              LM_INSERTITEM,
                              MPFROMSHORT(LIT_SORTASCENDING),
                              MPFROMP((PSZ)*ppszT++));

        if(sT == LIT_ERROR || sT == LIT_MEMERROR)  {
            MessageBox(hwndMain,
                       IDMSG_CANNOTLOADSTRING,
                       MB_OK | MB_ERROR,
                       FALSE);

            DosFreeMem((PVOID)pfmSave);
            return FALSE;
        }
    }

    /* add "Default" text onto the end */
    lT = (LONG)WinSendMsg(hwndT,
                  LM_INSERTITEM,
                  MPFROMSHORT(LIT_SORTASCENDING),
                  MPFROMP(apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR]));

    if(sT == LIT_ERROR || sT == LIT_MEMERROR)  {
        MessageBox(hwndMain,
                   IDMSG_CANNOTLOADSTRING,
                   MB_OK | MB_ERROR,
                   FALSE);

        DosFreeMem((PVOID)pfmSave);
        return FALSE;
    }


    DosFreeMem((PVOID)pfmSave);

    return TRUE;

}   /* InitPresParamDemoDlg() */

/****************************************************************\
 *  Updates the Presentation Parameters in the PP Demo Dialog
 *--------------------------------------------------------------
 *
 *  Name:   UpdatePresParamDemoDlg(hwnd)
 *
 *  Purpose: Sets/Removes the Presentation Parameter of the
 *          sample text window depending upon the parameters
 *          chosen
 *
 *  Usage:  Called when user wants to update the window
 *
 *  Method: The string of each combobox is queried and then the
 *          color or font is set depending upon the string
 *          chosen
 *
 *  Returns:
 *
\****************************************************************/
BOOL UpdatePresParamDemoDlg(hwnd)
HWND hwnd;      /* handle of the dialog window */
{
    HWND hwndT, hwndSampleText, hwndSampleButton;
    CHAR szT[COLORNAMELEN];
    BYTE abBuf[FACESIZE + PPFONTPOINTSIZE];
    LONG clr, lPP;
    SHORT sT;

    /* get window handle of the sample text box */
    hwndSampleText = WinWindowFromID(hwnd, IDC_SAMPLETEXT);
    hwndSampleButton = WinWindowFromID(hwnd, IDC_CHECKBOX);

    /* get the text of the foreground color combobox */
    hwndT = WinWindowFromID(hwnd, IDC_FORECOLORLIST);

    if(WinQueryWindowText(hwndT, COLORNAMELEN, (PSZ)szT))  {

        /* find the text in the list of color names */
        sT = 0;
        while(sT < NUMCOLORS)  {
            if(!strcmp(szT, apszPresParamColor[sT]))  {
                clr = aulColor[sT];
                break;
            } else
                sT++;
        }

        /* if color is not default, set the color.  If the default is
            selected, then remove the color presentation parameter if
            it exists.  If the value is not a valid color, then don't
            don't do anything */
        if(sT < NUMCOLORS)  {
            sT += IDS_FIRSTCOLOR;
            if(sT < IDS_DEFAULT)  {
                if(!WinSetPresParam(hwndSampleText,
                                    PP_FOREGROUNDCOLORINDEX,
                                    (ULONG)sizeof(LONG),
                                    (PVOID)&clr) ||
                   !WinSetPresParam(hwndSampleButton,
                                    PP_FOREGROUNDCOLORINDEX,
                                    (ULONG)sizeof(LONG),
                                    (PVOID)&clr))  {

                        MessageBox(hwndMain,
                                   IDMSG_CANNOTSETPP,
                                   MB_OK | MB_ERROR,
                                   FALSE);
                }


            } else {
                /* If setting presentation parameter to the default, remove
                    the presentation parameter, but only if it has been
                    set */
                if(sT == IDS_DEFAULT &&
                   WinQueryPresParam(hwndSampleText,
                                     PP_FOREGROUNDCOLORINDEX,
                                     0L,
                                     &lPP,
                                     (LONG)sizeof(LONG),
                                     (PVOID)&clr,
                                     QPF_NOINHERIT) != NULL)  {

                   if(!WinRemovePresParam(hwndSampleText,
                                          PP_FOREGROUNDCOLORINDEX) ||
                      !WinRemovePresParam(hwndSampleButton,
                                          PP_FOREGROUNDCOLORINDEX))  {

                       MessageBox(hwndMain,
                                  IDMSG_CANNOTSETPP,
                                  MB_OK | MB_ERROR,
                                  FALSE);
                   }
                }
            }
        }
    }



    /* Do the same for the background color combobox */
    hwndT = WinWindowFromID(hwnd, IDC_BACKCOLORLIST);
    if(WinQueryWindowText(hwndT, COLORNAMELEN, (PSZ)szT))  {

        /* find the text in the list of color names */
        sT = 0;
        while(sT < NUMCOLORS)  {
            if(!strcmp(szT, apszPresParamColor[sT])) {
                clr = aulColor[sT];
                break;
            } else
                sT++;
        }

        /* if color is not default, set the color.  If the default is
            selected, then remove the color presentation parameter.  If
            the value is not a valid color, the don't do anything */
        if(sT < NUMCOLORS)  {
            sT += IDS_FIRSTCOLOR;
            if(sT < IDS_DEFAULT)  {
                if(!WinSetPresParam(hwndSampleText,
                                    PP_BACKGROUNDCOLORINDEX,
                                    (ULONG)sizeof(LONG),
                                    (PVOID)&clr) ||
                   !WinSetPresParam(hwndSampleButton,
                                    PP_BACKGROUNDCOLORINDEX,
                                    (ULONG)sizeof(LONG),
                                    (PVOID)&clr))  {

                        MessageBox(hwndMain,
                                   IDMSG_CANNOTSETPP,
                                   MB_OK | MB_ERROR,
                                   FALSE);
                }

            } else {
                if(sT == IDS_DEFAULT &&
                   WinQueryPresParam(hwndSampleText,
                                     PP_BACKGROUNDCOLORINDEX,
                                     0L,
                                     &lPP,
                                     (LONG)sizeof(LONG),
                                     (PVOID)&clr,
                                     QPF_NOINHERIT) != NULL)  {

                    if(!WinRemovePresParam(hwndSampleText,
                                           PP_BACKGROUNDCOLORINDEX) ||
                       !WinRemovePresParam(hwndSampleButton,
                                           PP_BACKGROUNDCOLORINDEX))  {

                            MessageBox(hwndMain,
                                       IDMSG_CANNOTSETPP,
                                       MB_OK | MB_ERROR,
                                       FALSE);
                    }
                }
            }
        }
    }


    /* get the text of the font combobox */
    hwndT = WinWindowFromID(hwnd, IDC_FONTLIST);
    if(WinQueryWindowText(hwndT, FACESIZE, (PSZ)szT))  {

        /* if Font selected is "Default", remove font pres. param. */
        if(!strcmp(szT, apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR]))  {
            if(WinQueryPresParam(hwndSampleText,
                                 PP_FONTNAMESIZE,
                                 0L,
                                 &lPP,
                                 (LONG)(FACESIZE + PPFONTPOINTSIZE),
                                 (PVOID)abBuf,
                                 QPF_NOINHERIT) != NULL)  {
                if(!WinRemovePresParam(hwndSampleText, PP_FONTNAMESIZE) ||
                   !WinRemovePresParam(hwndSampleButton, PP_FONTNAMESIZE))  {
                        MessageBox(hwndMain,
                                   IDMSG_CANNOTSETPP,
                                   MB_OK | MB_ERROR,
                                   FALSE);
                }
            }
        } else {    /* font is not default */

            /*----------------------------------------------------*\
             *  abBuf will hold the font point size and name in
             *  the form <pt>.<name>.  First we fill abBuf with the
             *  font point prefix and then append the font name
             *  retrieved from the combobox.
            \*----------------------------------------------------*/

            if(!WinLoadString(hab,
                              NULL,
                              IDS_PPFONTPOINT,
                              COLORNAMELEN,
                              (PSZ)abBuf))  {

                MessageBox(hwndMain,
                           IDMSG_CANNOTLOADSTRING,
                           MB_OK | MB_ERROR,
                           FALSE);

                return FALSE;
            }

            strcat((PSZ)abBuf, szT);

            if(!WinSetPresParam(hwndSampleText,
                                PP_FONTNAMESIZE,
                                (ULONG)strlen((PSZ)abBuf) + 1L,
                                (PVOID)abBuf) ||
               !WinSetPresParam(hwndSampleButton,
                                PP_FONTNAMESIZE,
                                (ULONG)strlen((PSZ)abBuf) + 1L,
                                (PVOID)abBuf))  {

                        MessageBox(hwndMain,
                                   IDMSG_CANNOTSETPP,
                                   MB_OK | MB_ERROR,
                                   FALSE);
            }
        }
    }

    return TRUE;

}   /* UpdatePresParamDemoDlg() */

/****************************************************************\
 *  Shows the help panel for the given dialog window
 *--------------------------------------------------------------
 *
 *  Name:   ShowDlgHelp(hwnd)
 *
 *  Purpose: Displays the help panel for the current selected
 *           item in the dialog window
 *
 *  Usage:  Called each time a WM_HELP message is posted to
 *          a dialog
 *
 *  Method: gets the id value of the window and determine which
 *          help panel to display.  Then sends a message to
 *          the help instance to display the panel.  If the dialog
 *          or item is not included here, then the unknown dialog
 *          or unknown item panel is displayed.
 *
 *  Returns:
 *
\****************************************************************/
VOID ShowDlgHelp(hwnd)
HWND hwnd;      /* handle of list box window */
{
    SHORT idPanel, idDlg, idItem;
    HWND hwndFocus;

    /* get the id of the dialog box */
    idDlg = WinQueryWindowUShort(hwnd, QWS_ID);

    /* finds which window has the focus and gets its id */
    hwndFocus = WinQueryFocus(HWND_DESKTOP, FALSE);
    idItem = WinQueryWindowUShort(hwndFocus, QWS_ID);

    switch(idDlg)  {
        case IDD_BUTTONSDLG:
            switch(idItem)  {
                case IDC_RADIO1:
                case IDC_RADIO2:
                case IDC_RADIO3:
                    idPanel = PANEL_BUTTONSDLG_RADIO;
                    break;

                case IDC_CHECKBOX:
                    idPanel = PANEL_BUTTONSDLG_CHECKBOX;
                    break;

                case IDC_3STATE:
                    idPanel = PANEL_BUTTONSDLG_THREESTATE;
                    break;

                case IDC_PUSHBUTTON:
                    idPanel = PANEL_BUTTONSDLG_PUSHBUTTON;
                    break;

                case IDC_OK:
                    idPanel = PANEL_BUTTONSDLG_OK;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_BUTTONSDLG_HELP;
                    break;

                default:
                    idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_LISTBOXDLG:
            switch(idItem)  {
                case IDC_LISTBOX:
                    idPanel = PANEL_LISTBOXDLG_SINGLE;
                    break;

                case IDC_MULTISELLISTBOX:
                    idPanel = PANEL_LISTBOXDLG_MULTIPLE;
                    break;

                case IDC_OK:
                    idPanel = PANEL_LISTBOXDLG_OK;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_LISTBOXDLG_HELP;
                    break;

                default:
                    idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_COMBOBOXDLG:
            switch(idItem)  {
                case IDC_SIMPLE:
                    idPanel = PANEL_COMBOBOXDLG_SIMPLE;
                    break;

                case IDC_DROPDOWN:
                    idPanel = PANEL_COMBOBOXDLG_DROPDOWN;
                    break;

                case IDC_DROPDOWNLIST:
                    idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST;
                    break;

                case IDC_OK:
                    idPanel = PANEL_COMBOBOXDLG_OK;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_COMBOBOXDLG_HELP;
                    break;

                default:
                    /* check to see if window that has the focus is the
                        entry field of the combobox.  If it is, then
                        call the appropriate combobox help panel.  If
                        not, then call the unknown panel */
                    if(WinWindowFromID(WinWindowFromID(hwnd, IDC_SIMPLE),
                                        CBID_EDIT) == hwndFocus)
                        idPanel = PANEL_COMBOBOXDLG_SIMPLE;
                    else
                        if(WinWindowFromID(WinWindowFromID(hwnd, IDC_DROPDOWN),
                                            CBID_EDIT) == hwndFocus)
                            idPanel = PANEL_COMBOBOXDLG_DROPDOWN;
                        else
                            if(WinWindowFromID(
                                  WinWindowFromID(hwnd, IDC_DROPDOWNLIST),
                                                CBID_EDIT) == hwndFocus)
                                idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST;
                            else
                                idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_ENTRYFIELDDLG:
            switch(idItem)  {
                case IDC_ENTRY:
                    idPanel = PANEL_ENTRYFIELDDLG_ENTRY;
                    break;

                case IDC_MLE:
                    idPanel = PANEL_ENTRYFIELDDLG_MLE;
                    break;

                case IDC_OK:
                    idPanel = PANEL_ENTRYFIELDDLG_OK;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_ENTRYFIELDDLG_HELP;
                    break;

                default:
                    idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_STATICDLG:
            switch(idItem)  {
                case IDC_OK:
                    idPanel = PANEL_STATICDLG_OK;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_STATICDLG_HELP;
                    break;

                default:
                    idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_PPDEMODLG:
            switch(idItem)  {
                case IDC_FORECOLORLIST:
                    idPanel = PANEL_PPDEMODLG_FORECOLORLIST;
                    break;

                case IDC_BACKCOLORLIST:
                    idPanel = PANEL_PPDEMODLG_BACKCOLORLIST;
                    break;

                case IDC_FONTLIST:
                    idPanel = PANEL_PPDEMODLG_FONTLIST;
                    break;

                case IDC_CHECKBOX:
                    idPanel = PANEL_PPDEMODLG_TESTBUTTON;
                    break;

                case IDC_CANCEL:
                    idPanel = PANEL_PPDEMODLG_CANCEL;
                    break;

                case IDC_APPLY:
                    idPanel = PANEL_PPDEMODLG_APPLY;
                    break;

                case IDC_HELP:
                    idPanel = PANEL_PPDEMODLG_HELP;
                    break;

                default:
                    /* check to see if window that has the focus is the
                        entry field of the combobox.  If it is, then
                        call the appropriate combobox help panel.  If
                        not, then call the unknown panel */
                    if(WinWindowFromID(
                        WinWindowFromID(hwnd, IDC_FORECOLORLIST),
                                        CBID_EDIT) == hwndFocus)
                        idPanel = PANEL_PPDEMODLG_FORECOLORLIST;
                    else
                        if(WinWindowFromID(
                            WinWindowFromID(hwnd, IDC_BACKCOLORLIST),
                                            CBID_EDIT) == hwndFocus)
                            idPanel = PANEL_PPDEMODLG_BACKCOLORLIST;
                        else
                            if(WinWindowFromID(
                                WinWindowFromID(hwnd, IDC_FONTLIST),
                                                CBID_EDIT) == hwndFocus)
                                idPanel = PANEL_PPDEMODLG_FONTLIST;
                            else
                                idPanel = PANEL_UNKNOWN;
                    break;
            }
            break;

        case IDD_ABOUTBOX:
            idPanel = PANEL_ABOUTBOX;
            break;

        default:
            idPanel = PANEL_UNKNOWNDLG;
            break;

    }

    DisplayHelpPanel(idPanel);

}   /* ShowDlgHelp() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.