Annotation of os232sdk/toolkt20/c/samples/style/sty_user.c, revision 1.1

1.1     ! root        1: /*==============================================================*\
        !             2:  *  User.c - routines for handling messages not processed
        !             3:  *              by the standard message processing routine
        !             4:  *      Created 1990, Microsoft, IBM  Corp.
        !             5:  *--------------------------------------------------------------
        !             6:  *
        !             7:  *  This module contains the code for processing messages sent
        !             8:  *  to the standard window that the standard window does not
        !             9:  *  process.  The application developer need only modify this
        !            10:  *  file in order to implement new menu items or process
        !            11:  *  messages not handled by the standard message routine.
        !            12:  *
        !            13:  *  This module also contains some routines that demonstate the
        !            14:  *  various dialog box controls and message box types that can
        !            15:  *  be used.  The sample code should be deleted when this
        !            16:  *  module is modified for an application.  The demonstration
        !            17:  *  code is identified by comments.
        !            18:  *
        !            19:  *--------------------------------------------------------------
        !            20:  *
        !            21:  *  This source file contains the following functions:
        !            22:  *
        !            23:  *      UserWndProc(hwnd, msg, mp1, mp2) - user window procedure
        !            24:  *      UserCommand(mp1, mp2) - user WM_COMMAND processor
        !            25:  *      SetForegroundColor(hwnd)
        !            26:  *      SetBackgroundColor(MenuId)
        !            27:  *      SetWindowText(hwnd)
        !            28:  *
        !            29: \*==============================================================*/
        !            30: 
        !            31: /*--------------------------------------------------------------*\
        !            32:  *  Include files, macros, defined constants, and externs
        !            33: \*--------------------------------------------------------------*/
        !            34: 
        !            35: #define INCL_WINMENUS
        !            36: #define INCL_WINWINDOWMGR
        !            37: #define INCL_WINCLIPBOARD
        !            38: #define INCL_WINMLE
        !            39: #define INCL_WINSTDFONT
        !            40: #define INCL_GPILCIDS
        !            41: #define INCL_GPIPRIMITIVES
        !            42: 
        !            43: #include <os2.h>
        !            44: #include "sty_main.h"
        !            45: #include "sty_xtrn.h"
        !            46: #include "sty_dlg.h"
        !            47: #include <string.h>
        !            48: 
        !            49: // #define FONT_DLG_ENABLED
        !            50: 
        !            51: /*--------------------------------------------------------------*\
        !            52:  *  Global variables
        !            53: \*--------------------------------------------------------------*/
        !            54: ULONG clrForeground = CLR_NEUTRAL;          /* color for window text */
        !            55: ULONG clrBackground = CLR_BACKGROUND;       /* color for window background */
        !            56: 
        !            57: /*--------------------------------------------------------------*\
        !            58:  *  Entry point declarations
        !            59: \*--------------------------------------------------------------*/
        !            60: 
        !            61: VOID SetForegroundColor(VOID);
        !            62: VOID SetBackgroundColor(SHORT idMenu);
        !            63: VOID SetFont(VOID);
        !            64: MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg,
        !            65:                                   MPARAM mp1, MPARAM mp2);
        !            66: MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg,
        !            67:                                   MPARAM mp1, MPARAM mp2);
        !            68: VOID ShowDemoDlg(SHORT idMenuItem);
        !            69: VOID ShowDemoMsgBox(SHORT idMenuItem);
        !            70: 
        !            71: 
        !            72: /****************************************************************\
        !            73:  *  Non-standard window message processing routine
        !            74:  *--------------------------------------------------------------
        !            75:  *
        !            76:  *  Name:   UserWndProc(hwnd, msg, mp1, mp2)
        !            77:  *
        !            78:  *  Purpose: Process any messages sent to hwndMain that
        !            79:  *              are not processed by the standard window
        !            80:  *              procedure
        !            81:  *
        !            82:  *  Usage:  Routine is called for each message MainWndProc
        !            83:  *          does not process
        !            84:  *
        !            85:  *  Method: A switch statement branches control based upon
        !            86:  *          the message passed.  Any messages not processed
        !            87:  *          here must be passed onto WinDefWindowProc()
        !            88:  *
        !            89:  *  Returns: Return value depended upon the message processed
        !            90: \****************************************************************/
        !            91: MRESULT UserWndProc(hwnd, msg, mp1, mp2)
        !            92: HWND hwnd;      /* handle of window */
        !            93: USHORT msg;     /* id of message */
        !            94: MPARAM mp1;     /* first message parameter */
        !            95: MPARAM mp2;     /* second message parameter */
        !            96: {
        !            97: 
        !            98:     switch(msg)  {
        !            99: 
        !           100:     /*--------------------------------------------------------------*\
        !           101:      *  Add case statements for message ids you wish to process
        !           102:     \*--------------------------------------------------------------*/
        !           103: 
        !           104:         case WM_SIZE:
        !           105:             /* re-size the MLE to be the same width and height as the
        !           106:                 client window */
        !           107:             WinSetWindowPos(hwndMLE,
        !           108:                             HWND_TOP,
        !           109:                             0,
        !           110:                             0,
        !           111:                             SHORT1FROMMP(mp2),
        !           112:                             SHORT2FROMMP(mp2),
        !           113:                             SWP_SIZE);
        !           114:             break;
        !           115: 
        !           116:         case WM_SETFOCUS:
        !           117:             if(SHORT1FROMMP(mp1))
        !           118:                 WinPostMsg(hwnd, SM_SETFOCUS, NULL, NULL);
        !           119:             break;
        !           120: 
        !           121:         case SM_SETFOCUS:
        !           122:             WinSetFocus(HWND_DESKTOP, hwndMLE);
        !           123:             break;
        !           124: 
        !           125:         default:    /* default must call WinDefWindowProc() */
        !           126:             return(WinDefWindowProc(hwnd, msg, mp1, mp2));
        !           127:             break;
        !           128:     }
        !           129: 
        !           130:     return 0L;
        !           131: 
        !           132: }   /* UserWndProc() */
        !           133: 
        !           134: 
        !           135: /****************************************************************\
        !           136:  *  Non-standard menu item command processing procedure
        !           137:  *--------------------------------------------------------------
        !           138:  *
        !           139:  *  Name:   UserCommand(mp1, mp2)
        !           140:  *
        !           141:  *  Purpose: Process any WM_COMMAND messages send to hwndMain
        !           142:  *              that are not processed by MainCommand
        !           143:  *
        !           144:  *  Usage:  Routine is called for each WM_COMMAND that is
        !           145:  *          not posted by a standard menu item
        !           146:  *
        !           147:  *  Method: A switch statement branches control based upon
        !           148:  *          the id of the control which posted the message
        !           149:  *
        !           150:  *  Returns:
        !           151: \****************************************************************/
        !           152: VOID UserCommand(mp1, mp2)
        !           153: MPARAM mp1;     /* first message parameter */
        !           154: MPARAM mp2;     /* second message parameter */
        !           155: {
        !           156: 
        !           157:     switch(SHORT1FROMMP(mp1))  {
        !           158: 
        !           159:     /*--------------------------------------------------------------*\
        !           160:      *  Add case statements for menuitem ids you wish to process
        !           161:     \*--------------------------------------------------------------*/
        !           162: 
        !           163: 
        !           164: /*--------------------------------------------------------------*\
        !           165:  *  The following code is for the demonstration code only.  It
        !           166:  *  should be removed when modifying this file for your
        !           167:  *  application.
        !           168: \*--------------------------------------------------------------*/
        !           169: 
        !           170: #ifdef PALETTE_DLG_ENABLED
        !           171:         case IDM_OPTIONSFORECOLOR:
        !           172:             SetForegroundColor(hwndMLE);
        !           173:             break;
        !           174: #endif
        !           175: 
        !           176:         case IDM_OPTIONSBACKCOLORPINK:
        !           177:         case IDM_OPTIONSBACKCOLORCYAN:
        !           178:         case IDM_OPTIONSBACKCOLORYELLOW:
        !           179:         case IDM_OPTIONSBACKCOLORDEFAULT:
        !           180:             SetBackgroundColor(SHORT1FROMMP(mp1));
        !           181:             break;
        !           182: 
        !           183: #ifdef FONT_DLG_ENABLED
        !           184:         case IDM_OPTIONSFONT:
        !           185:             SetFont();
        !           186:             break;
        !           187: #endif
        !           188: 
        !           189:         case IDM_DEMODLGBUTTONS:
        !           190:         case IDM_DEMODLGLISTBOXES:
        !           191:         case IDM_DEMODLGCOMBOBOXES:
        !           192:         case IDM_DEMODLGENTRYFIELDS:
        !           193:         case IDM_DEMODLGSTATIC:
        !           194:             ShowDemoDlg(SHORT1FROMMP(mp1));
        !           195:             break;
        !           196: 
        !           197:         case IDM_DEMOMSGBOXOK:
        !           198:         case IDM_DEMOMSGBOXOKCANCEL:
        !           199:         case IDM_DEMOMSGBOXYESNO:
        !           200:         case IDM_DEMOMSGBOXYESNOCANCEL:
        !           201:         case IDM_DEMOMSGBOXRETRYCANCEL:
        !           202:         case IDM_DEMOMSGBOXABORT:
        !           203:         case IDM_DEMOMSGBOXENTER:
        !           204:         case IDM_DEMOMSGBOXENTERCANCEL:
        !           205:         case IDM_DEMOMSGBOXQUERY:
        !           206:         case IDM_DEMOMSGBOXWARNING:
        !           207:         case IDM_DEMOMSGBOXINFO:
        !           208:         case IDM_DEMOMSGBOXCRITICAL:
        !           209:         case IDM_DEMOMSGBOXAPP:
        !           210:         case IDM_DEMOMSGBOXSYS:
        !           211:         case IDM_DEMOMSGBOXMOVEABLE:
        !           212:         case IDM_DEMOMSGBOXHELP:
        !           213:             ShowDemoMsgBox(SHORT1FROMMP(mp1));
        !           214:             break;
        !           215: 
        !           216:         case IDM_DEMODLGPP:
        !           217:             WinDlgBox(hwndMain,
        !           218:                       hwndMain,
        !           219:                       (PFNWP)PresParamDemoDlgProc,
        !           220:                       NULL,
        !           221:                       IDD_PPDEMODLG,
        !           222:                       (PVOID)NULL);
        !           223:             break;
        !           224: 
        !           225: 
        !           226: /*--------------------------------------------------------------*\
        !           227:  *  End of demonstration code
        !           228: \*--------------------------------------------------------------*/
        !           229: 
        !           230: 
        !           231:         default:
        !           232:             break;
        !           233:     }
        !           234: 
        !           235:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           236:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           237:     \*  warning at compile time.                                      */
        !           238:     mp2;
        !           239: 
        !           240: }   /* UserCommand() */
        !           241: 
        !           242: 
        !           243: 
        !           244: /****************************************************************\
        !           245:  *  Menu item intialization routine
        !           246:  *--------------------------------------------------------------
        !           247:  *
        !           248:  *  Name:   InitMenu(mp1, mp2)
        !           249:  *
        !           250:  *  Purpose: Processes the WM_INITMENU message for the main window,
        !           251:  *              disabling any menus that are not active
        !           252:  *
        !           253:  *  Usage:  Routine is called each time a menu is dropped
        !           254:  *
        !           255:  *  Method: A switch statement branches control based upon
        !           256:  *          the id of the menu which is being displayed
        !           257:  *
        !           258:  *  Returns:
        !           259: \****************************************************************/
        !           260: VOID InitMenu(mp1, mp2)
        !           261: MPARAM mp1;     /* first message parameter */
        !           262: MPARAM mp2;     /* second message parameter */
        !           263: {
        !           264:     SHORT  fsFmtInfo;
        !           265:     BOOL fEnable;
        !           266: 
        !           267:     switch(SHORT1FROMMP(mp1))  {
        !           268:         case IDM_FILE:
        !           269:             /*
        !           270:              * The Print, Print Setup, and Page Setup menu items of the
        !           271:              * File menu will be enabled if printing is enabled, otherwise
        !           272:              * they will be disabled
        !           273:              */
        !           274: 
        !           275:             EnableMenuItem(HWNDFROMMP(mp2), IDM_FILEPRINT, fPrintEnabled);
        !           276:             EnableMenuItem(HWNDFROMMP(mp2), IDM_FILEPRINTSETUP, fPrintEnabled);
        !           277:             EnableMenuItem(HWNDFROMMP(mp2), IDM_FILEPAGESETUP, fPrintEnabled);
        !           278: 
        !           279:             break;
        !           280: 
        !           281:         case IDM_HELP:
        !           282:             /*
        !           283:              * Enable or disable the Help menu depending upon whether the
        !           284:              * help manager has been enabled
        !           285:              */
        !           286:             EnableMenuItem(HWNDFROMMP(mp2),
        !           287:                           IDM_HELPHELPFORHELP, fHelpEnabled);
        !           288: 
        !           289:             EnableMenuItem(HWNDFROMMP(mp2),
        !           290:                           IDM_HELPEXTENDED, fHelpEnabled);
        !           291: 
        !           292:             EnableMenuItem(HWNDFROMMP(mp2),
        !           293:                           IDM_HELPKEYS, fHelpEnabled);
        !           294: 
        !           295:             EnableMenuItem(HWNDFROMMP(mp2),
        !           296:                           IDM_HELPINDEX, fHelpEnabled);
        !           297: 
        !           298:             /** REMEMBER: add a case for IDM_HELPTUTORIAL if you include
        !           299:                 the menu item   **/
        !           300: 
        !           301:             break;
        !           302: 
        !           303:         case IDM_EDIT:
        !           304:             /* if text is selected in the MLE, the enable the Cut, Copy,
        !           305:                 and Clear menus.  Otherwise, do not */
        !           306:             fEnable = WinSendMsg(hwndMLE,
        !           307:                                  MLM_QUERYSEL,
        !           308:                                  MPFROMSHORT(MLFQS_MINSEL),
        !           309:                                  NULL) != WinSendMsg(hwndMLE,
        !           310:                                                      MLM_QUERYSEL,
        !           311:                                                      MPFROMSHORT(MLFQS_MAXSEL),
        !           312:                                                      NULL);
        !           313: 
        !           314:             EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCUT, fEnable);
        !           315:             EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCOPY, fEnable);
        !           316:             EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCLEAR, fEnable);
        !           317: 
        !           318: 
        !           319:             /* determine if the MLE can Undo the last action.  If it can't,
        !           320:                 then disable he Undo menu */
        !           321:             fEnable =
        !           322:                 HIUSHORT(WinSendMsg(hwndMLE, MLM_QUERYUNDO, NULL, NULL)) != 0;
        !           323: 
        !           324:             EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITUNDO, fEnable);
        !           325: 
        !           326:             /* determine if the clipboard has some text on it.  If it
        !           327:                 doesn't, then disable the Paste menu */
        !           328:             if(WinOpenClipbrd(hab))  {
        !           329:                 if(WinQueryClipbrdFmtInfo(hab, CF_TEXT, &fsFmtInfo))
        !           330:                     fEnable = TRUE;
        !           331:                 else
        !           332:                     fEnable = FALSE;
        !           333: 
        !           334:                 WinCloseClipbrd(hab);
        !           335:             } else
        !           336:                 fEnable = TRUE;
        !           337: 
        !           338:             EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITPASTE, fEnable);
        !           339: 
        !           340:             break;
        !           341: 
        !           342:         default:
        !           343:             break;
        !           344:     }
        !           345: 
        !           346: }   /* InitMenu() */
        !           347: 
        !           348: /****************************************************************\
        !           349:  *  Enables/Disables the menu item of the given menu
        !           350:  *--------------------------------------------------------------
        !           351:  *
        !           352:  *  Name:   EnableMenuItem(hwndMenu, idItem, fEnable)
        !           353:  *
        !           354:  *  Purpose: Enables or disables the menu item
        !           355:  *
        !           356:  *  Usage:  Called whenever a menu item is to enabled or
        !           357:  *          disabled
        !           358:  *
        !           359:  *  Method: Sends a MM_SETITEMATTR to the menu with the
        !           360:  *          given item id.  Sets the MIA_DISABLED attribute
        !           361:  *          flag if the item is to be disabled, clears the flag
        !           362:  *          if enabling
        !           363:  *
        !           364:  *  Returns:
        !           365:  *
        !           366: \****************************************************************/
        !           367: VOID EnableMenuItem(hwndMenu, idItem, fEnable)
        !           368: HWND hwndMenu;      /* Handle to the menu */
        !           369: SHORT idItem;       /* Id of the menu item to be enabled/disabled */
        !           370: BOOL fEnable;       /* flag to set enable or disable bit */
        !           371: {
        !           372:     SHORT fsFlag;
        !           373: 
        !           374:     if(fEnable)
        !           375:         fsFlag = 0;
        !           376:     else
        !           377:         fsFlag = MIA_DISABLED;
        !           378: 
        !           379:     WinSendMsg(hwndMenu,
        !           380:                MM_SETITEMATTR,
        !           381:                MPFROM2SHORT(idItem, TRUE),
        !           382:                MPFROM2SHORT(MIA_DISABLED, fsFlag));
        !           383: 
        !           384: }   /* EnableMenuItem() */
        !           385: 
        !           386: /****************************************************************\
        !           387:  *  Displays the Demonstration dialog selected
        !           388:  *--------------------------------------------------------------
        !           389:  *
        !           390:  *  Name:   ShowDemoDlg(idMenuItem)
        !           391:  *
        !           392:  *  Purpose: Displays the demonstration dialog for the menu
        !           393:  *           id chosen.
        !           394:  *
        !           395:  *  Usage:  Called whenever a menu item from the Dialog Box
        !           396:  *          menu of the Demo menu is selected.
        !           397:  *
        !           398:  *  Method: Determines the id of the dialog template and
        !           399:  *          creates a dialog of that template.
        !           400:  *
        !           401:  *  Returns:
        !           402:  *
        !           403: \****************************************************************/
        !           404: VOID ShowDemoDlg(idMenuItem)
        !           405: SHORT idMenuItem;   /* Id of the menu item chosen for the dialog */
        !           406: {
        !           407:     SHORT idDlg;
        !           408: 
        !           409:     switch(idMenuItem)  {
        !           410:         case IDM_DEMODLGBUTTONS:
        !           411:             idDlg = IDD_BUTTONSDLG;
        !           412:             break;
        !           413: 
        !           414:         case IDM_DEMODLGLISTBOXES:
        !           415:             idDlg = IDD_LISTBOXDLG;
        !           416:             break;
        !           417: 
        !           418:         case IDM_DEMODLGCOMBOBOXES:
        !           419:             idDlg = IDD_COMBOBOXDLG;
        !           420:             break;
        !           421: 
        !           422:         case IDM_DEMODLGENTRYFIELDS:
        !           423:             idDlg = IDD_ENTRYFIELDDLG;
        !           424:             break;
        !           425: 
        !           426:         case IDM_DEMODLGSTATIC:
        !           427:             idDlg = IDD_STATICDLG;
        !           428:             break;
        !           429: 
        !           430:         default:    /* unknown menu id */
        !           431:             return;
        !           432:             break;
        !           433:     }
        !           434: 
        !           435:     WinDlgBox(hwndMain,
        !           436:               hwndMain,
        !           437:               (PFNWP)DemoDlgProc, /* all demos use DemoDlgProc*/
        !           438:               NULL,
        !           439:               idDlg,              /* id of template */
        !           440:               (PVOID)idDlg);      /* pass id as mp2 of WM_INITDLG */
        !           441: 
        !           442: }   /* ShowDemoDlg() */
        !           443: 
        !           444: 
        !           445: /****************************************************************\
        !           446:  *  Displays the Demonstration message box selected
        !           447:  *--------------------------------------------------------------
        !           448:  *
        !           449:  *  Name:   ShowDemoMsgBox(idMenuItem)
        !           450:  *
        !           451:  *  Purpose: Displays the demonstration message box for the menu
        !           452:  *           id chosen.
        !           453:  *
        !           454:  *  Usage:  Called whenever a menu item from the Message Box
        !           455:  *          menu of the Demo menu is selected.
        !           456:  *
        !           457:  *  Method: Determines the options for the message box and then
        !           458:  *          creates the box.
        !           459:  *
        !           460:  *  Returns:
        !           461:  *
        !           462: \****************************************************************/
        !           463: VOID ShowDemoMsgBox(idMenuItem)
        !           464: SHORT idMenuItem;   /* Id of the menu item chosen for the dialog */
        !           465: {
        !           466:     SHORT fsOptions, idText;
        !           467:     CHAR szText[MESSAGELEN];
        !           468: 
        !           469:     switch(idMenuItem)  {
        !           470:         case IDM_DEMOMSGBOXOK:
        !           471:             fsOptions = MB_OK;
        !           472:             idText = IDS_DEMOMSGBOXOK;
        !           473:             break;
        !           474: 
        !           475:         case IDM_DEMOMSGBOXOKCANCEL:
        !           476:             fsOptions = MB_OKCANCEL;
        !           477:             idText = IDS_DEMOMSGBOXOKCANCEL;
        !           478:             break;
        !           479: 
        !           480:         case IDM_DEMOMSGBOXYESNO:
        !           481:             fsOptions = MB_YESNO;
        !           482:             idText = IDS_DEMOMSGBOXYESNO;
        !           483:             break;
        !           484: 
        !           485:         case IDM_DEMOMSGBOXYESNOCANCEL:
        !           486:             fsOptions = MB_YESNOCANCEL;
        !           487:             idText = IDS_DEMOMSGBOXYESNOCANCEL;
        !           488:             break;
        !           489: 
        !           490:         case IDM_DEMOMSGBOXRETRYCANCEL:
        !           491:             fsOptions = MB_RETRYCANCEL;
        !           492:             idText = IDS_DEMOMSGBOXRETRYCANCEL;
        !           493:             break;
        !           494: 
        !           495:         case IDM_DEMOMSGBOXABORT:
        !           496:             fsOptions = MB_ABORTRETRYIGNORE;
        !           497:             idText = IDS_DEMOMSGBOXABORT;
        !           498:             break;
        !           499: 
        !           500:         case IDM_DEMOMSGBOXENTER:
        !           501:             fsOptions = MB_ENTER;
        !           502:             idText = IDS_DEMOMSGBOXENTER;
        !           503:             break;
        !           504: 
        !           505:         case IDM_DEMOMSGBOXENTERCANCEL:
        !           506:             fsOptions = MB_ENTERCANCEL;
        !           507:             idText = IDS_DEMOMSGBOXENTERCANCEL;
        !           508:             break;
        !           509: 
        !           510:         case IDM_DEMOMSGBOXQUERY:
        !           511:             fsOptions = MB_OK | MB_QUERY;
        !           512:             idText = IDS_DEMOMSGBOXQUERY;
        !           513:             break;
        !           514: 
        !           515:         case IDM_DEMOMSGBOXWARNING:
        !           516:             fsOptions = MB_OK | MB_WARNING;
        !           517:             idText = IDS_DEMOMSGBOXWARNING;
        !           518:             break;
        !           519: 
        !           520:         case IDM_DEMOMSGBOXINFO:
        !           521:             fsOptions = MB_OK | MB_INFORMATION;
        !           522:             idText = IDS_DEMOMSGBOXINFO;
        !           523:             break;
        !           524: 
        !           525:         case IDM_DEMOMSGBOXCRITICAL:
        !           526:             fsOptions = MB_OK | MB_CRITICAL;
        !           527:             idText = IDS_DEMOMSGBOXCRITICAL;
        !           528:             break;
        !           529: 
        !           530:         case IDM_DEMOMSGBOXAPP:
        !           531:             fsOptions = MB_OK | MB_APPLMODAL;
        !           532:             idText = IDS_DEMOMSGBOXAPP;
        !           533:             break;
        !           534: 
        !           535:         case IDM_DEMOMSGBOXSYS:
        !           536:             fsOptions = MB_OK | MB_SYSTEMMODAL;
        !           537:             idText = IDS_DEMOMSGBOXSYS;
        !           538:             break;
        !           539: 
        !           540:         case IDM_DEMOMSGBOXMOVEABLE:
        !           541:             fsOptions = MB_OK | MB_MOVEABLE;
        !           542:             idText = IDS_DEMOMSGBOXMOVEABLE;
        !           543:             break;
        !           544: 
        !           545:         case IDM_DEMOMSGBOXHELP:
        !           546:             fsOptions = MB_OK | MB_HELP;
        !           547:             idText = IDS_DEMOMSGBOXHELP;
        !           548:             break;
        !           549: 
        !           550:         default:    /* unknown menu id */
        !           551:             return;
        !           552:             break;
        !           553:     }
        !           554: 
        !           555:     /* get the text for the message box */
        !           556:     if(!WinLoadString(hab,
        !           557:                       NULL,
        !           558:                       idText,
        !           559:                       MESSAGELEN,
        !           560:                       (PSZ)szText))  {
        !           561: 
        !           562:         MessageBox(hwndMain,
        !           563:                    IDMSG_CANNOTLOADSTRING,
        !           564:                    MB_OK | MB_ERROR,
        !           565:                    FALSE);
        !           566:         return;
        !           567:     }
        !           568: 
        !           569:     /* bring up the message box */
        !           570:     WinMessageBox(HWND_DESKTOP,
        !           571:                   hwndMain,
        !           572:                   szText,
        !           573:                   szAppName,
        !           574:                   IDD_DEMOMSGBOX,
        !           575:                   fsOptions);
        !           576: 
        !           577: 
        !           578: }   /* ShowDemoMsgBox() */
        !           579: 
        !           580: 
        !           581: 
        !           582: /*--------------------------------------------------------------*\
        !           583:  *  The following code is for the demonstration code only.  It
        !           584:  *  should be removed when modifying this file for your
        !           585:  *  application.
        !           586: \*--------------------------------------------------------------*/
        !           587: 
        !           588: #ifdef PALETTE_DLG_ENABLED
        !           589: 
        !           590: /****************************************************************\
        !           591:  *  Sets the foreground color of the application window
        !           592:  *--------------------------------------------------------------
        !           593:  *
        !           594:  *  Name:   SetForegroundColor()
        !           595:  *
        !           596:  *  Purpose: Allows the user to select a color for the text
        !           597:  *              displayed in the MLE
        !           598:  *
        !           599:  *  Usage:  Routine is called each time the user selects the
        !           600:  *          Foreground Color menu item from the Options menu
        !           601:  *
        !           602:  *  Method: The standard color dialog is called with the
        !           603:  *          default color table colors.  If the user selects
        !           604:  *          one, then the MLM_SETTEXTCOLOR message is sent
        !           605:  *          to the MLE to changed its text to the color chosen
        !           606:  *
        !           607:  *  Returns:
        !           608:  *
        !           609: \****************************************************************/
        !           610: VOID SetForegroundColor(VOID)
        !           611: {
        !           612:     COLORDLG cd;
        !           613:     HPS hps;
        !           614:                                     
        !           615:     /* Get the PS for the window */
        !           616:     hps = WinGetPS(hwndMLE);
        !           617:     if(!hps)  {
        !           618:         MessageBox(hwnd, IDMSG_CANNOTGETHPS, TRUE);
        !           619:         return;
        !           620:     }
        !           621: 
        !           622:     /*  Initialize the COLORDLG structure */
        !           623:     cd.kgd.cbSize      = sizeof(COLORDLG);
        !           624:     cd.kgd.flStyle     = PGSS_CENTER;
        !           625:     cd.kgd.pszDlgTitle = "Foreground Color";
        !           626:     cd.kgd.pfnDlgProc  = NULL;
        !           627:     cd.kgd.hmod        = NULL;
        !           628:     cd.kgd.idDlg       = 0;
        !           629:     cd.kgd.lReturn     = 0L;
        !           630:     cd.kgd.x           = 0;
        !           631:     cd.kgd.y           = 0;
        !           632: 
        !           633:     cd.pszButton    = "Ok";
        !           634:     cd.fl           = CDS_STATICPALETTE | CDS_CENTER | CDS_HELPBUTTON;
        !           635:     cd.pflFlags     = NULL;
        !           636:     cd.iclrSel      = clrForeground;
        !           637:     cd.cclrMax      = 0;
        !           638:     cd.hps          = hps;
        !           639:                             
        !           640:     if(KitColorDlg(hwndMain, (PCOLORDLG)&cd) == (HWND)NULL)  {
        !           641:         MessageBox(hwndMain, IDMSG_CANNOTRUNCOLORDLG, TRUE);
        !           642:         WinReleasePS(hps);
        !           643: 
        !           644:         return (HWND)NULL;
        !           645:     }
        !           646: 
        !           647:     /* set the foreground color to the returned value */
        !           648:     WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(cd.iclrSel), NULL);
        !           649:     clrForeground = cd.iclrSel;
        !           650: 
        !           651:     WinReleasePS(hps);
        !           652: 
        !           653: }   /* SetForegroundColor() */
        !           654: 
        !           655: #endif  /* PALETTE_DLG_ENABLED */
        !           656: 
        !           657: /****************************************************************\
        !           658:  *  Sets the background color of the given window
        !           659:  *--------------------------------------------------------------
        !           660:  *
        !           661:  *  Name:   SetBackgroundColor(nMenuId)
        !           662:  *
        !           663:  *  Purpose: Allows the user to select a color for the window
        !           664:  *              background
        !           665:  *
        !           666:  *  Usage:  Routine is called each time the user selects one
        !           667:  *          of the Background colors listed in the Background
        !           668:  *          Color submenu of the Options menu
        !           669:  *
        !           670:  *  Method: A switch statement determines which menu item was
        !           671:  *          chosen and then the appropriate color is placed
        !           672:  *          into clrBackground.
        !           673:  *
        !           674:  *  Returns:
        !           675:  *
        !           676: \****************************************************************/
        !           677: VOID SetBackgroundColor(idMenu)
        !           678: SHORT idMenu;       /* id of menu item selected */
        !           679: {
        !           680: 
        !           681:     switch(idMenu)  {
        !           682:         case IDM_OPTIONSBACKCOLORPINK:
        !           683:             clrBackground = CLR_PINK;
        !           684:             break;
        !           685: 
        !           686:         case IDM_OPTIONSBACKCOLORCYAN:
        !           687:             clrBackground = CLR_CYAN;
        !           688:             break;
        !           689: 
        !           690:         case IDM_OPTIONSBACKCOLORYELLOW:
        !           691:             clrBackground = CLR_YELLOW;
        !           692:             break;
        !           693: 
        !           694:         /*--------------------------------------------------------------*\
        !           695:          *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
        !           696:          *  the background color to the default back color
        !           697:         \*--------------------------------------------------------------*/
        !           698:         default:
        !           699:             clrBackground = CLR_BACKGROUND;
        !           700:             break;
        !           701: 
        !           702:     }
        !           703: 
        !           704:     WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(clrBackground), NULL);
        !           705: 
        !           706: }   /* SetBackgroundColor() */
        !           707: 
        !           708: #ifdef FONT_DLG_ENABLED
        !           709: 
        !           710: /****************************************************************\
        !           711:  *  Sets the font of the MLE
        !           712:  *--------------------------------------------------------------
        !           713:  *
        !           714:  *  Name:   SetFont()
        !           715:  *
        !           716:  *  Purpose: Allows the user to select a font for the text
        !           717:  *              displayed in the MLE
        !           718:  *
        !           719:  *  Usage:  Routine is called each time the user selects the
        !           720:  *          Font menu item from the Options menu
        !           721:  *
        !           722:  *  Method: The standard font dialog is called with the
        !           723:  *          current available fonts.  If the user selects
        !           724:  *          one, then the MLM_SETFONT message is sent to the
        !           725:  *          MLE to display its text to the font chosen
        !           726:  *
        !           727:  *  Returns:
        !           728:  *
        !           729: \****************************************************************/
        !           730: VOID SetFont(VOID)
        !           731: {
        !           732:     FONTDLG fntd;
        !           733:     HPS hps;
        !           734:     FONTMETRICS fm;
        !           735:     CHAR szTitle[MESSAGELEN];
        !           736: 
        !           737:     /* get the current font attributes */
        !           738:     hps = WinGetPS(hwndMLE);
        !           739:     WinSendMsg(hwndMLE, MLM_QUERYFONT, MPFROMP((PFATTRS)&(fntd.fAttrs)), NULL);
        !           740: 
        !           741:     GpiCreateLogFont(hps, (PSTR8)NULL, 1L, &(fntd.fAttrs));
        !           742:     GpiSetCharSet(hps, 1L);
        !           743: 
        !           744:     GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
        !           745: 
        !           746:     GpiSetCharSet(hps, LCID_DEFAULT);
        !           747:     GpiDeleteSetId(hps, 1L);
        !           748:     WinReleasePS(hps);
        !           749: 
        !           750:     /* Initialize the FONTDLG structure with the current font */
        !           751:     fntd.cbSize     = sizeof(FONTDLG);
        !           752:     fntd.hpsScreen  = WinGetScreenPS(HWND_DESKTOP);
        !           753:     fntd.hpsPrinter = NULL;
        !           754: 
        !           755:     if(!WinLoadString(hab, NULL, IDS_FONTDLGTITLE, MESSAGELEN, szTitle))  {
        !           756:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           757:         return;
        !           758:     }
        !           759:     fntd.pszTitle   = szTitle;
        !           760: 
        !           761:     fntd.pszPreview = NULL;
        !           762:     fntd.pszPtSizeList = NULL;
        !           763:     fntd.pfnDlgProc = NULL;
        !           764:     strcpy(fntd.szFamilyname, fm.szFamilyname);
        !           765:     fntd.fxPointSize  = MAKEFIXED(fm.sNominalPointSize, 0);
        !           766:     fntd.fl         = FNTS_CENTER;
        !           767:     fntd.flFlags      = NULL;
        !           768:     fntd.flType       = NULL;
        !           769:     fntd.flTypeMask   = NULL;
        !           770:     fntd.flStyle      = NULL;
        !           771:     fntd.flStyleMask  = NULL;
        !           772:     fntd.flCHSOptions = 0L;
        !           773:     fntd.flCHSMask    = 0L;
        !           774:     fntd.clrFore      = clrForeground;
        !           775:     fntd.clrBack      = clrBackground;
        !           776:     fntd.lUser        = 0L;
        !           777:     fntd.lReturn      = 0L;
        !           778:     fntd.lEmHeight    = 0L;
        !           779:     fntd.lXHeight     = 0L;
        !           780:     fntd.lExternalLeading = 0L;
        !           781:     fntd.sNominalPointSize = 0L;
        !           782:     fntd.usWeight     = fm.usWeightClass;
        !           783:     fntd.usWidth      = fm.usWidthClass;
        !           784:     fntd.x          = 0;
        !           785:     fntd.y          = 0;
        !           786:     fntd.idDlg      = IDD_FONT;
        !           787: 
        !           788: 
        !           789:     /* Bring up the standard Font Dialog */
        !           790:     if(!KitFontDialog(hwndMLE, &fntd))  {
        !           791:         WinReleasePS(fntd.hpsScreen);
        !           792:         return;
        !           793:     }
        !           794: 
        !           795:     WinReleasePS(fntd.hpsScreen);
        !           796: 
        !           797:     WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fntd.fAttrs)), NULL);
        !           798: 
        !           799:     /* Set the new colors */
        !           800:     clrForeground = fntd.clrFore;
        !           801:     clrBackground = fntd.clrBack;
        !           802: 
        !           803:     WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(clrForeground), NULL);
        !           804:     WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(clrBackground), NULL);
        !           805: 
        !           806: }   /* SetFont() */
        !           807: 
        !           808: #endif  /* FONT_DLG_ENABLED */
        !           809: 
        !           810: 
        !           811: /*--------------------------------------------------------------*\
        !           812:  *  End of demonstration code
        !           813: \*--------------------------------------------------------------*/

unix.superglobalmegacorp.com

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