Annotation of os232sdk/toolkt20/c/samples/vmm/vmm_main.c, revision 1.1.1.1

1.1       root        1: /*==============================================================*\
                      2:  *  Vmm_main.c - Sample PM application                         *
                      3:  *
                      4:  *     Created 1990, Microsoft, IBM Corp.                              *
                      5:  *
                      6:  *     DISCLAIMER OF WARRANTIES.  The following [enclosed] code is 
                      7:  *     sample code created by Microsoft Corporation and/or IBM 
                      8:  *     Corporation. This sample code is not part of any standard 
                      9:  *     Microsoft or IBM product and is provided to you solely for 
                     10:  *     the purpose of assisting you in the development of your 
                     11:  *     applications.  The code is provided "AS IS", without 
                     12:  *     warranty of any kind.  Neither Microsoft nor IBM shall be 
                     13:  *     liable for any damages arising out of your use of the sample 
                     14:  *     code, even if they have been advised of the possibility of 
                     15:  *     such damages.
                     16:  *
                     17:  *--------------------------------------------------------------*
                     18:  *                                                             *
                     19:  *  This application serves two distinct purposes.  First, it  *
                     20:  *  demonstrates the standard menus and dialogs that most PM   *
                     21:  *  applications will contain. The Demo menu calls dialog      *
                     22:  *  boxes that demonstrate all of the controls available for   *
                     23:  *  use in a dialog box.  There is also a dialog box which     *
                     24:  *  demonstrates the setting and removing of control           *
                     25:  *  Presentation Parameters.  Finally, the demo menu also has  *
                     26:  *  menu items that demonstrate the various types of message   *
                     27:  *  boxes that the system supports.                            *
                     28:  *                                                             *
                     29:  *  This application also serves as a template than can be     *
                     30:  *  easily modified by an application developer.  The source   *
                     31:  *  files are organized so that the overhead code that should  *
                     32:  *  be in all applications is located in the same files so     *
                     33:  *  that these files do not need to be modified.  The routines *
                     34:  *  that deal with application specific code are also located  *
                     35:  *  in their own modules.  An application developer need only  *
                     36:  *  change these files in order to modify this template for    *
                     37:  *  his application.                                           *
                     38:  *                                                             *
                     39:  *--------------------------------------------------------------*
                     40:  *                                                             *
                     41:  *  This source file contains the following functions:         *
                     42:  *                                                             *
                     43:  *     main() - main routine                                   *
                     44:  *     MainWndProc(hwnd, msg, mp1, mp2) - main window procedure*
                     45:  *     MessageBox(hwnd nId, bBeep) - Warning box routine       *
                     46:  *     MainCommand(mp1, mp2) - WM_COMMAND processing of Main   *
                     47:  *                                                             *
                     48: \*==============================================================*/
                     49: 
                     50: /*--------------------------------------------------------------*\
                     51:  *  Include files, macros, defined constants, and externs      *
                     52: \*--------------------------------------------------------------*/
                     53: 
                     54: #define  LINT_ARGS
                     55: 
                     56: #define  INCL_WIN
                     57: #define  INCL_DOSPROCESS
                     58: #include <os2.h>
                     59: #include "vmm_main.h"
                     60: #include "vmm_help.h"
                     61: #include "vmm_xtrn.h"
                     62: 
                     63: #define RETURN_SUCCESS     0   /* successful return in DosExit */
                     64: #define RETURN_ERROR       1   /* error return in DosExit */
                     65: #define BEEP_WARN_FREQ     60  /* frequency of warning beep */
                     66: #define BEEP_WARN_DUR     100  /* duration of warning beep */
                     67: 
                     68: /*--------------------------------------------------------------*\
                     69:  *  Global variables                                           *
                     70: \*--------------------------------------------------------------*/
                     71: HWND hwndMainFrame;                /* handle to the main frame window */
                     72: HWND hwndMain;                     /* handle to the main client window */
                     73: HAB hab;                           /* anchor block for the process */
                     74: HMQ hmq;                           /* handle to the process' message queue */
                     75: CHAR szAppName[MAXAPPNAMELEN];     /* buffer for application name string */
                     76: 
                     77: /*--------------------------------------------------------------*\
                     78:  *  Entry point declarations                                   *
                     79: \*--------------------------------------------------------------*/
                     80: 
                     81: /****************************************************************\
                     82:  *  Main routine                                               *
                     83:  *--------------------------------------------------------------*
                     84:  *                                                             *
                     85:  *  Name:   main()                                             *
                     86:  *                                                             *
                     87:  *  Purpose: Initializes the PM environment, calls the         *
                     88:  *             initialization routine, creates the main        *
                     89:  *             window,  and polls the message queue            *
                     90:  *                                                             *
                     91:  *  Usage:                                                     *
                     92:  *                                                             *
                     93:  *  Method:                                                    *
                     94:  *         - obtains anchor block handle and creates message   *
                     95:  *             queue                                           *
                     96:  *         - calls the initialization routine                  *
                     97:  *         - creates the main frame window which creates the   *
                     98:  *             main client window                              *
                     99:  *         - polls the message queue via Get/Dispatch Msg loop *
                    100:  *         - upon exiting the loop, exits                      *
                    101:  *                                                             *
                    102:  *  Returns: (via DosExit)                                     *
                    103:  *         1 - if sucessful execution completed                *
                    104:  *         0 - if error                                        *
                    105: \****************************************************************/
                    106: 
                    107: VOID cdecl main(VOID)
                    108: {
                    109:     QMSG qmsg;         /* message structure */
                    110:     ULONG ctlData;     /* frame control data */
                    111: 
                    112:     hab = WinInitialize(0);
                    113:     if(!hab)  {
                    114:        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
                    115:        DosExit(EXIT_PROCESS, RETURN_ERROR);
                    116:     }
                    117:        /* find a define for this v */
                    118:     hmq = WinCreateMsgQueue(hab, 0);
                    119:     if(!hmq)  {
                    120:        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
                    121:        WinTerminate(hab);
                    122:        DosExit(EXIT_PROCESS, RETURN_ERROR);
                    123:     }
                    124: 
                    125:     if(!Init())  {
                    126:        MessageBox(HWND_DESKTOP, IDMSG_INITFAILED, TRUE);
                    127:        DosExit(EXIT_PROCESS, RETURN_ERROR);
                    128:     }
                    129: 
                    130:     /* create the main window */
                    131: 
                    132: 
                    133: #ifdef VER630
                    134:     ctlData = FCF_STANDARD /* & ~FCF_ICON */ ;
                    135: #else
                    136: 
                    137:     ctlData = FCF_STANDARD;
                    138: 
                    139: #endif
                    140: 
                    141:     hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP,
                    142:                        WS_VISIBLE,
                    143:                        (PVOID)&ctlData,
                    144:                        (PSZ)szAppName,
                    145:                        (PSZ)NULL,
                    146:                        WS_VISIBLE,
                    147:                        (HMODULE)NULL,
                    148:                        IDR_SAMPLE,
                    149:                        (PHWND)&hwndMain);
                    150: 
                    151:     if(!hwndMainFrame) {
                    152:        MessageBox(HWND_DESKTOP, IDMSG_MAINWINCREATEFAILED, TRUE);
                    153:        DosExit(EXIT_PROCESS, RETURN_ERROR);
                    154:     }
                    155: 
                    156: //  InitHelp();
                    157: 
                    158:     /* Get/Dispatch Message loop */
                    159: 
                    160:     while(WinGetMsg(hmq, (PQMSG)&qmsg, NULL, NULL, NULL))
                    161:        WinDispatchMsg(hmq, (PQMSG)&qmsg);
                    162: 
                    163: 
                    164: #ifdef VER630
                    165:     /* will normally be put in ExitProc */
                    166:     WinDestroyWindow(hwndMainFrame);
                    167: 
                    168:     /*--------------------------------------------------*\
                    169:      *     Any other system resources used             *
                    170:      *     (e.g. memory or files) should be freed here *
                    171:     \*--------------------------------------------------*/
                    172: 
                    173:     WinDestroyMsgQueue(hmq);
                    174: 
                    175:     WinTerminate(hab);
                    176: 
                    177: #endif
                    178: 
                    179:     DosExit(EXIT_PROCESS, RETURN_SUCCESS);
                    180: 
                    181: }   /* main() */
                    182: 
                    183: 
                    184: /****************************************************************\
                    185:  *  Main client window procedure                               *
                    186:  *--------------------------------------------------------------*
                    187:  *                                                             *
                    188:  *  Name:   MainWndProc(hwnd, msg, mp1, mp2)                   *
                    189:  *                                                             *
                    190:  *  Purpose: Processes the messages sent to the main client    *
                    191:  *             window.  This routine processes the basic       *
                    192:  *             messages all client windows should process      *
                    193:  *             and passes all others onto UserWndProc where    *
                    194:  *             the developer can process any others.           *
                    195:  *                                                             *
                    196:  *  Usage:  Called for each message placed in the main         *
                    197:  *         window's message queue                              *
                    198:  *                                                             *
                    199:  *  Method: a switch statement branches to the routines to be  *
                    200:  *         performed for each message processed.  Any messages *
                    201:  *         not specifically process are passed to the user's   *
                    202:  *         message processing procedure UserWndProc().         *
                    203:  *                                                             *
                    204:  *  Returns:  Return values are determined by each message     *
                    205:  *                                                             *
                    206: \****************************************************************/
                    207: 
                    208: MRESULT EXPENTRY MainWndProc(hwnd, msg, mp1, mp2)
                    209: HWND hwnd;     /* handle of window */
                    210: USHORT msg;    /* id of message */
                    211: MPARAM mp1;    /* first message parameter */
                    212: MPARAM mp2;    /* second message parameter */
                    213: {
                    214: 
                    215:     switch(msg)  {
                    216:        case WM_PAINT:
                    217:            MainPaint(hwnd);
                    218:            break;
                    219: 
                    220:        case WM_COMMAND:
                    221:            MainCommand(mp1, mp2);
                    222:            break;
                    223: 
                    224:        case HM_QUERY_KEYS_HELP:
                    225:            return (MRESULT)PANEL_HELPKEYS;     /* return id of key help panel */
                    226:            break;
                    227: 
                    228:     /*--------------------------------------------------*\
                    229:      *     Any messages not processed are passed on    *
                    230:      *     to the user's window proc.  It is           *
                    231:      *     responsible for passing any messages it     *
                    232:      *     doesn't handle onto WinDefWindowProc()      *
                    233:     \*--------------------------------------------------*/
                    234: 
                    235:        default:
                    236:            return(UserWndProc(hwnd, msg, mp1, mp2));
                    237:            break;
                    238: 
                    239:     }
                    240:     return 0L;     /* all window procedures should return 0 as a default */
                    241: 
                    242: }   /* MainWndProc() */
                    243: 
                    244: /****************************************************************\
                    245:  *  Message Box procedure                                      *
                    246:  *--------------------------------------------------------------*
                    247:  *                                                             *
                    248:  *  Name:   MessageBox(hwndOwner, nIdMsg, bBeep)               *
                    249:  *                                                             *
                    250:  *  Purpose: Displays the warning message box with the message *
                    251:  *             given in nIdMsg retrived from the message table *
                    252:  *                                                             *
                    253:  *  Usage:  Called whever an error occurs and a message wishes *
                    254:  *         to be displayed to the user                         *
                    255:  *                                                             *
                    256:  *  Method: - Message string is loaded from the process'        *
                    257:  *             message table                                   *
                    258:  *         - Alarm beep is sounded if desired                  *
                    259:  *         - Message box with the message is displayed         *
                    260:  *                                                             *
                    261:  *  Returns:                                                   *
                    262:  *                                                             *
                    263: \****************************************************************/
                    264: 
                    265: VOID MessageBox(hwndOwner, nIdMsg, bBeep)
                    266: HWND hwndOwner;     /* handle of the message box's owner */
                    267: SHORT nIdMsg;      /* id if the message in the message table */
                    268: BOOL bBeep;        /* if TRUE, beep before message box is displayed */
                    269: {
                    270:     CHAR szText[MESSAGELEN];
                    271: 
                    272:     if(!WinLoadMessage(hab, (HMODULE)NULL, nIdMsg, MESSAGELEN, (PSZ)szText)) {
                    273:        WinAlarm(HWND_DESKTOP, WA_ERROR);
                    274:        return;
                    275:     }
                    276: 
                    277:     if(bBeep)
                    278:        WinAlarm(HWND_DESKTOP, WA_ERROR);
                    279: 
                    280:     WinMessageBox(HWND_DESKTOP,
                    281:                  hwndOwner,
                    282:                  szText,
                    283:                  (PSZ)NULL,
                    284:                  1,
                    285:                  MB_OK | MB_ERROR);
                    286: 
                    287: }   /* MessageBox() */
                    288: 
                    289: /****************************************************************\
                    290:  *  Main window WM_COMMAND processing procedure                *
                    291:  *--------------------------------------------------------------*
                    292:  *                                                             *
                    293:  *  Name:   MainCommand(mp1, mp2)                              *
                    294:  *                                                             *
                    295:  *  Purpose: Calls the appropriate procedures that deal with   *
                    296:  *             the selected menu item.                         *
                    297:  *                                                             *
                    298:  *  Usage:  Routine is called whenever a WM_COMMAND message    *
                    299:  *         is posted to the main window.                       *
                    300:  *                                                             *
                    301:  *  Method: a switch statement branches on the id of the       *
                    302:  *         menu item that posted the message and the           *
                    303:  *         appropriate action for that item is taken.  Any     *
                    304:  *         menu ids that are not part of the standard menu     *
                    305:  *         set are passed onto the user defined WM_COMMAND     *
                    306:  *         processing procedure.                               *
                    307:  *                                                             *
                    308:  *  Returns:                                                   *
                    309:  *                                                             *
                    310: \****************************************************************/
                    311: VOID MainCommand(mp1, mp2)
                    312: MPARAM mp1;    /* first parameter of WM_COMMAND message */
                    313: MPARAM mp2;    /* second parameter of WM_COMMAND message */
                    314: {
                    315: 
                    316:     switch(SHORT1FROMMP(mp1))  {
                    317: 
                    318: #ifdef LATER
                    319:        case IDM_FILENEW:
                    320:            FileNew(mp2);
                    321:            break;
                    322: 
                    323:        case IDM_FILEOPEN:
                    324:            FileOpen(mp2);
                    325:            break;
                    326: 
                    327:        case IDM_FILESAVE:
                    328:            FileSave(mp2);
                    329:            break;
                    330: 
                    331:        case IDM_FILESAVEAS:
                    332:            FileSaveAs(mp2);
                    333:            break;
                    334: 
                    335:        case IDM_EDITUNDO:
                    336:            EditUndo(mp2);
                    337:            break;
                    338: 
                    339:        case IDM_EDITCUT:
                    340:            EditCut(mp2);
                    341:            break;
                    342: 
                    343:        case IDM_EDITCOPY:
                    344:            EditCopy(mp2);
                    345:            break;
                    346: 
                    347:        case IDM_EDITPASTE:
                    348:            EditPaste(mp2);
                    349:            break;
                    350: 
                    351:        case IDM_EDITCLEAR:
                    352:            EditClear(mp2);
                    353:            break;
                    354: 
                    355:        case IDM_WINDOWTILE:
                    356:            WindowTile(mp2);
                    357:            break;
                    358: 
                    359:        case IDM_WINDOWCASCADE:
                    360:            WindowCascade(mp2);
                    361:            break;
                    362: 
                    363:        case IDM_HELPFORHELP:
                    364:            HelpHelpForHelp(mp2);
                    365:            break;
                    366: 
                    367:        case IDM_HELPEXTENDED:
                    368:            HelpExtended(mp2);
                    369:            break;
                    370: 
                    371:        case IDM_HELPKEYS:
                    372:            HelpKeys(mp2);
                    373:            break;
                    374: 
                    375:        case IDM_HELPINDEX:
                    376:            HelpIndex(mp2);
                    377:            break;
                    378: 
                    379:        case IDM_HELPTUTORIAL:
                    380:            HelpTutorial(mp2);
                    381:            break;
                    382: 
                    383:        case IDM_FILEPRINT:
                    384:            FilePrint(mp2);
                    385:            break;
                    386: 
                    387:        case IDM_FILEPAGESETUP:
                    388:            FilePageSetup(mp2);
                    389:            break;
                    390: 
                    391:        case IDM_FILEPRINTSETUP:
                    392:            FilePrintSetup(mp2);
                    393:            break;
                    394: 
                    395:        case IDM_HELPHELPFORHELP:
                    396:            HelpHelpForHelp(mp2);
                    397:            break;
                    398: #endif
                    399: 
                    400:        case IDM_HELPABOUT:
                    401:            HelpAbout(mp2);
                    402:            break;
                    403: 
                    404: 
                    405:        case IDM_FILEEXIT:
                    406:            FileExit(mp2);
                    407:            break;
                    408: 
                    409: 
                    410:     /*--------------------------------------------------*\
                    411:      *     User command processing routine is called   *
                    412:      *     here so any ids not procecessed here can be *
                    413:      *     processed                                   *
                    414:     \*--------------------------------------------------*/
                    415:        default:
                    416:            UserCommand(mp1, mp2);
                    417:            break;
                    418:     }
                    419: 
                    420: }   /* MainCommand() */

unix.superglobalmegacorp.com

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