Annotation of pmsdk/samples/dlgsamp/dlgsamp.c, revision 1.1

1.1     ! root        1: /***************************************************************************
        !             2: *
        !             3: *  MODULE NAME: DLGSAMP
        !             4: *
        !             5: *  Presentation Manager Dialog Sample Application
        !             6: *
        !             7: *  Created by Microsoft Corp., 1988
        !             8: *
        !             9: ****************************************************************************
        !            10:  
        !            11: /***************************************************************************
        !            12: *
        !            13: *  CALL NAME                              COUNT
        !            14: *  =========                              =====
        !            15: *
        !            16: *  GpiCharStringAt                           4
        !            17: *  GpiSetColor                               1
        !            18: *  WinBeginPaint                             1
        !            19: *  WinCreateMsgQueue                         1
        !            20: *  WinCreateStdWindow                        1
        !            21: *  WinDefDlgProc                             6
        !            22: *  WinDefWindowProc                          1
        !            23: *  WinDestroyMsgQueue                        1
        !            24: *  WinDestroyWindow                          3
        !            25: *  WinDismissDlg                             4
        !            26: *  WinDispatchMsg                            1
        !            27: *  WinDlgBox                                 1
        !            28: *  WinEndPaint                               1
        !            29: *  WinFillRect                               1
        !            30: *  WinGetMsg                                 1
        !            31: *  WinInitialize                             1
        !            32: *  WinInvalidateRect                         6
        !            33: *  WinIsWindow                               1
        !            34: *  WinLoadDlg                                1
        !            35: *  WinLoadString                             2
        !            36: *  WinMessageBox                             2
        !            37: *  WinPostMsg                               20
        !            38: *  WinQueryDlgItemShort                      1
        !            39: *  WinQuerySysValue                          2
        !            40: *  WinQueryWindow                            1
        !            41: *  WinQueryWindowPos                         1
        !            42: *  WinQueryWindowText                        4
        !            43: *  WinRegisterClass                          1
        !            44: *  WinSendDlgItemMsg                         5
        !            45: *  WinSendMsg                                1
        !            46: *  WinSetFocus                               1
        !            47: *  WinSetWindowPos                           1
        !            48: *  WinTerminate                              1
        !            49: *  WinWindowFromID                          16
        !            50: *
        !            51: *  Number of unique calls =                 34
        !            52: *
        !            53: ***************************************************************************/
        !            54:  
        !            55: /***************************************************************************
        !            56: *
        !            57: *  Include relevant sections of the PM header file.
        !            58: *
        !            59: ***************************************************************************/
        !            60:  
        !            61: #define INCL_WINBUTTONS
        !            62: #define INCL_WINDIALOGS
        !            63: #define INCL_WINERRORS
        !            64: #define INCL_WINFRAMEMGR
        !            65: #define INCL_WININPUT
        !            66: #define INCL_WINLISTBOXES
        !            67: #define INCL_WINMENUS
        !            68: #define INCL_WINMESSAGEMGR
        !            69: #define INCL_WINRECTANGLES
        !            70: #define INCL_WINSWITCHLIST
        !            71: #define INCL_WINSYS
        !            72: #define INCL_WINWINDOWMGR
        !            73: #define M_I86L
        !            74: #include <os2.h>
        !            75:  
        !            76: /***************************************************************************
        !            77: *
        !            78: *  Include C library routine header files
        !            79: *
        !            80: ***************************************************************************/
        !            81:  
        !            82: #include <string.h>
        !            83: #include <stdlib.h>
        !            84:  
        !            85: /***************************************************************************
        !            86: *
        !            87: *  Include application header files
        !            88: *
        !            89: *  dlgsamp.h  is header for dialog editor ids
        !            90: *  dlgsamp.h1 is standard application header for everything not in .h
        !            91: *
        !            92: ***************************************************************************/
        !            93:  
        !            94: #include "dlgsamp.h"
        !            95: #include "dlgsamp1.h"
        !            96:  
        !            97: /***************************************************************************
        !            98: *
        !            99: *  Function prototypes for private C functions
        !           100: *
        !           101: ***************************************************************************/
        !           102:  
        !           103: VOID NEAR cdecl main( VOID );
        !           104:  
        !           105: VOID cdecl CentreDlgBox( HWND hwnd );
        !           106: VOID cdecl CheckColor( HWND hwndDlg, SHORT iDlgItem, COLOR *colorClient );
        !           107: VOID cdecl EnableModality( HWND hwnd, BOOL bModal );
        !           108: BOOL cdecl IsIntInRange( HWND hwndDlg, SHORT idEntryField,
        !           109:                          SHORT iLoRange, SHORT iHiRange,
        !           110:                          SHORT idErrMsg, SHORT idMessageBox );
        !           111: VOID cdecl LoadDialog( HWND hwndParent, HWND hwndOwner,
        !           112:                        SHORT idDlg, PFNWP fnwpDlgProc,
        !           113:                        BOOL bModality );
        !           114: VOID cdecl MainWndCommand( HWND hwnd, USHORT command, BOOL *bModality );
        !           115: VOID cdecl MainWndPaint( HWND hwnd );
        !           116: VOID cdecl SetModality( HWND hwnd, BOOL bModal );
        !           117: VOID cdecl Trace( PSZ szCaption, PSZ szMessage );
        !           118:  
        !           119: /**************************************************************************
        !           120: *
        !           121: *   Function protypes for private WinProcs.
        !           122: *
        !           123: **************************************************************************/
        !           124:  
        !           125: MRESULT EXPENTRY fnwpMainWnd( HWND hwnd, USHORT message,
        !           126:                               MPARAM mp1, MPARAM mp2 );
        !           127: MRESULT EXPENTRY fnwpEntryFieldDlg( HWND hwnd, USHORT message,
        !           128:                                     MPARAM mp1, MPARAM mp2 );
        !           129: MRESULT EXPENTRY fnwpAutoRadioButtonDlg( HWND hwnd, USHORT message,
        !           130:                                          MPARAM mp1, MPARAM mp2 );
        !           131: MRESULT EXPENTRY fnwpCheckBoxDlg( HWND hwnd, USHORT message,
        !           132:                                   MPARAM mp1, MPARAM mp2 );
        !           133: MRESULT EXPENTRY fnwpListBoxDlg( HWND hwnd, USHORT message,
        !           134:                                  MPARAM mp1, MPARAM mp2 );
        !           135:  
        !           136: /*************************************************************************
        !           137: *
        !           138: *   Global variables
        !           139: *
        !           140: *************************************************************************/
        !           141:  
        !           142: COLOR colorClient = CLR_RED | CLR_BLUE;    /* Color of client area    */
        !           143:  
        !           144: CHAR  szEntryField1[10] = "";              /* Used to pass back info  */
        !           145: CHAR  szEntryField2[10] = "";              /* from entry fields       */
        !           146:                                            /* in EntryFieldDlg        */
        !           147:  
        !           148: BOOL  bModality = TRUE;                    /* Does the user want modal*/
        !           149:                                            /* or modeless dialogs?    */
        !           150: COLOR colorSave;
        !           151: CHAR  szSelection[LEN_LISTBOXENTRY] = "";  /* Used to pass back       */
        !           152:                                            /* list box item selected  */
        !           153:                                            /* in ListBoxDlg           */
        !           154:  
        !           155: HAB   hab;                                 /* Anchor block handle     */
        !           156: HWND  hwndClient;                          /* Client Window handle    */
        !           157: HWND  hwndFrame;                           /* Frame Window handle     */
        !           158: HWND  hwndModelessDlg;                     /* Modeless Dialog handle  */
        !           159:  
        !           160: /**************************************************************************
        !           161: *
        !           162: *   FUNCTION: main
        !           163: *
        !           164: *   Typical PM main function which initialises PM, creates a message queue,
        !           165: *   registers a window class, creates a window, gets and dispatches
        !           166: *   messages to its winproc until its time to quit, and then tidies up
        !           167: *   before terminating.
        !           168: *
        !           169: *   Side effects:
        !           170: *
        !           171: *   Sets the values of the following globals:-
        !           172: *
        !           173: *   hab, hwndClient, hwndFrame.
        !           174: *
        !           175: **************************************************************************/
        !           176:  
        !           177: VOID NEAR cdecl main(  )
        !           178: {
        !           179:   HMQ     hmq;                        /* Message Queue handle         */
        !           180:   QMSG    qmsg;                       /* Message                      */
        !           181:   ULONG   flCreate;
        !           182:  
        !           183:   hab   = WinInitialize( NULL );      /* Initialise PM                */
        !           184:   hmq   = WinCreateMsgQueue( hab, 0 );/* Create application msg queue */
        !           185:  
        !           186:   WinRegisterClass(                   /* Register Window Class        */
        !           187:       hab,                            /* Anchor block handle          */
        !           188:       "DlgSamp Class",                /* Window Class name            */
        !           189:       fnwpMainWnd,                    /* Address of Window Procedure  */
        !           190:       NULL,                           /* No special class style       */
        !           191:       0                               /* No extra window words        */
        !           192:       );
        !           193:  
        !           194:   flCreate = FCF_STANDARD;
        !           195:  
        !           196:   hwndFrame = WinCreateStdWindow(
        !           197:         HWND_DESKTOP,                   /* Desktop Window is parent     */
        !           198:         WS_VISIBLE  |
        !           199:         FS_TASKLIST |
        !           200:         FS_ICON,                        /* Window styles                */
        !           201:         (PVOID)&flCreate,               /* Window creation parameters   */
        !           202:         "DlgSamp Class",                /* Window Class name            */
        !           203:         "",                             /* Window Text                  */
        !           204:         0L,                             /* Client style                 */
        !           205:         NULL,                           /* Module handle                */
        !           206:         ID_MAINWND,                     /* Window ID                    */
        !           207:         (HWND FAR *)&hwndClient         /* Client Window handle         */
        !           208:         );
        !           209:  
        !           210:  
        !           211:   while( WinGetMsg( hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
        !           212:     WinDispatchMsg( hab, (PQMSG)&qmsg );
        !           213:  
        !           214:   WinDestroyWindow( hwndFrame );
        !           215:   WinDestroyMsgQueue( hmq );
        !           216:   WinTerminate( hab );
        !           217: }
        !           218:  
        !           219: /***********************************************************************
        !           220: *
        !           221: *   WinProc: fnwpMainWnd
        !           222: *
        !           223: *   Controls the state of the menu, and loads various dialogs.  The
        !           224: *   dialogs will be modal or modeless depending on the setting of the
        !           225: *   Modality menuitem.
        !           226: *
        !           227: *   Side Effects.
        !           228: *
        !           229: *   Modifies the values of the following globals:-
        !           230: *
        !           231: *   szEntryField1, szEntryField2, szSelection
        !           232: *
        !           233: ***********************************************************************/
        !           234:  
        !           235: MRESULT  EXPENTRY fnwpMainWnd( hwnd, message, mp1, mp2 )
        !           236: HWND    hwnd;
        !           237: USHORT  message;
        !           238: MPARAM  mp1;
        !           239: MPARAM  mp2;
        !           240: {
        !           241:   USHORT   Command;   /* Command passed by WM_COMMAND */
        !           242:   SHORT    id;        /* ID of item selected from the list box */
        !           243:  
        !           244:   switch(message)
        !           245:   {
        !           246:     case WM_PAINT:
        !           247:       MainWndPaint( hwnd );  /* Invoke window painting routine */
        !           248:       break;
        !           249:     case WM_HELP:
        !           250: /*********************************************************************
        !           251: *
        !           252: *   This will be received when either:-
        !           253: *
        !           254: *   1. The user depresses F1
        !           255: *   2. The user clicks on the action bar item F1=Help
        !           256: *
        !           257: *********************************************************************/
        !           258:       WinMessageBox( HWND_DESKTOP,
        !           259:                      hwndFrame,
        !           260:                      (PSZ)"Dialog Sample Application: Help",
        !           261:                     (PSZ)"Try out the pulldown menus, or Alt+selection",
        !           262:                      ID_MB,
        !           263:                      MB_OK );
        !           264:       break;
        !           265:     case WM_COMMAND:
        !           266:       Command = SHORT1FROMMP( mp1 );
        !           267:       MainWndCommand( hwnd, Command, &bModality );
        !           268:       break;
        !           269:     case DLGSAMP_EFCOMPLETE:
        !           270:       WinQueryWindowText( WinWindowFromID( hwndModelessDlg, EF_1 ),
        !           271:                           sizeof( szEntryField1 ), szEntryField1 );
        !           272:       WinQueryWindowText( WinWindowFromID( hwndModelessDlg, EF_2 ),
        !           273:                           sizeof( szEntryField2 ), szEntryField2 );
        !           274:       WinInvalidateRect( hwnd, NULL, FALSE );/* Request whole window repaint */
        !           275:       break;
        !           276:     case DLGSAMP_LBCOMPLETE:
        !           277:       id = SHORT1FROMMR( WinSendDlgItemMsg( hwndModelessDlg,
        !           278:                                             LB_1,
        !           279:                                             LM_QUERYSELECTION,
        !           280:                                             0L,
        !           281:                                             0L ) );
        !           282:       if( id == LIT_NONE )
        !           283:         strcpy( szSelection, "" );
        !           284:       else
        !           285:         WinSendDlgItemMsg( hwndModelessDlg,
        !           286:                            LB_1,
        !           287:                            LM_QUERYITEMTEXT,
        !           288:                            MPFROM2SHORT( id, sizeof( szSelection ) ),
        !           289:                            MPFROMP( szSelection ) );
        !           290:       break;
        !           291:     case DLGSAMP_RBCOMPLETE:
        !           292:     case DLGSAMP_CBCOMPLETE:
        !           293:       break;
        !           294:     case DLGSAMP_DESTROYDLG:
        !           295:       WinDestroyWindow( hwndModelessDlg );
        !           296:       EnableModality( hwndFrame, TRUE );
        !           297:       WinInvalidateRect( hwnd, NULL, FALSE );/* Request whole window repaint */
        !           298:       break;
        !           299:     case WM_CLOSE:
        !           300:       WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination    */
        !           301:       break;
        !           302:     default:
        !           303:       return WinDefWindowProc( hwnd, message, mp1, mp2 );
        !           304:   }
        !           305:   return FALSE;
        !           306: }
        !           307:  
        !           308: /***********************************************************************
        !           309: *
        !           310: *  DlgProc:  fnwpEntryFieldDlg
        !           311: *
        !           312: *  A dialog proc which captures and validates the contents of two
        !           313: *  entry fields.
        !           314: *
        !           315: *  Side effects.
        !           316: *
        !           317: *  Modifies the globals szEntryField1, szEntryField2.
        !           318: *
        !           319: ***********************************************************************/
        !           320:  
        !           321: MRESULT EXPENTRY fnwpEntryFieldDlg( hwndDlg, message, mp1, mp2 )
        !           322: HWND    hwndDlg;
        !           323: USHORT  message;
        !           324: MPARAM  mp1;
        !           325: MPARAM  mp2;
        !           326: {
        !           327:   switch (message)
        !           328:   {
        !           329:     case WM_INITDLG:
        !           330:       CentreDlgBox( hwndDlg );
        !           331:       break;
        !           332:     case WM_COMMAND:
        !           333:       switch( SHORT1FROMMP( mp1 ) )
        !           334:       {
        !           335:         case DID_OK: /* Enter key or pushbutton pressed/ selected */
        !           336:  
        !           337: /***************************************************************************
        !           338: *
        !           339: *   Validate the contents of the two entry fields
        !           340: *
        !           341: ***************************************************************************/
        !           342:  
        !           343:           if( !IsIntInRange( hwndDlg, EF_1, 1, 100, ERR_EFINVALID, ID_MB ) )
        !           344:             return FALSE;
        !           345:           if( !IsIntInRange( hwndDlg, EF_2, 1, 100, ERR_EFINVALID, ID_MB ) )
        !           346:             return FALSE;
        !           347:  
        !           348: /***************************************************************************
        !           349: *
        !           350: *   A modal dialog is destroyed before control is returned to the
        !           351: *   invoking winproc, so it must pass the contents of its Entry Fields etc.
        !           352: *   back to the invoking window before it returns.
        !           353: *
        !           354: *   When a modeless dialog box returns it still continues to exist. It
        !           355: *   could pass the contents of its Entry Fields etc. back to the
        !           356: *   invoking window in several ways.
        !           357: *
        !           358: *   Here a user message is posted to the invoking window to say that the
        !           359: *   dialog has completed. The invoking window then has an opportunity
        !           360: *   to extract the contents of the Entry Fields etc.
        !           361: *
        !           362: ***************************************************************************/
        !           363:  
        !           364:           if( bModality )
        !           365:           {
        !           366:             WinQueryWindowText( WinWindowFromID( hwndDlg, EF_1 ),
        !           367:                                 sizeof( szEntryField1),
        !           368:                                 szEntryField1 );
        !           369:             WinQueryWindowText( WinWindowFromID( hwndDlg, EF_2 ),
        !           370:                                 sizeof( szEntryField2),
        !           371:                                 szEntryField2 );
        !           372:           }
        !           373:           else
        !           374:             WinPostMsg( hwndClient, DLGSAMP_EFCOMPLETE, 0L, 0L );
        !           375:  
        !           376:         case DID_CANCEL:/* Escape key or CANCEL pushbutton pressed/selected */
        !           377:           if( bModality )
        !           378:             WinDismissDlg( hwndDlg,TRUE );
        !           379:           else
        !           380:             WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );
        !           381:           return FALSE;
        !           382:         default:
        !           383:           break;
        !           384:       }
        !           385:       break;
        !           386:  
        !           387:     default:  /* Pass all other messages to the default dialog proc */
        !           388:       return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           389:   }
        !           390:   return FALSE;
        !           391: }
        !           392:  
        !           393: /***********************************************************************
        !           394: *
        !           395: *  DlgProc:  fnwpAutoRadioButtonDlg
        !           396: *
        !           397: *  A dialog procedure which uses auto radio buttons to change the
        !           398: *  color of the Client Area window.
        !           399: *
        !           400: *  Side effects.
        !           401: *
        !           402: * Modifies the Client Area color and the global colorClient
        !           403: *
        !           404: ***********************************************************************/
        !           405:  
        !           406: MRESULT EXPENTRY fnwpAutoRadioButtonDlg( hwndDlg, message, mp1, mp2 )
        !           407: HWND    hwndDlg;
        !           408: USHORT  message;
        !           409: MPARAM  mp1;
        !           410: MPARAM  mp2;
        !           411: {
        !           412:   switch (message)
        !           413:   {
        !           414:     case WM_INITDLG:
        !           415:       colorSave = colorClient;
        !           416:       CentreDlgBox( hwndDlg );
        !           417:       break;
        !           418:     case WM_CONTROL:
        !           419:       if( SHORT2FROMMP( mp1 ) == BN_CLICKED )
        !           420:         switch( SHORT1FROMMP( mp1 ) )
        !           421:         {
        !           422:           case RB_RED:
        !           423:             colorClient = CLR_RED;
        !           424:             break;
        !           425:           case RB_GREEN:
        !           426:             colorClient = CLR_GREEN;
        !           427:             break;
        !           428:           case RB_BLUE:
        !           429:             colorClient = CLR_BLUE;
        !           430:             break;
        !           431:           default:
        !           432:            return FALSE;
        !           433:         }
        !           434:         WinInvalidateRect( hwndClient, NULL, FALSE );
        !           435:         break;
        !           436:     case WM_COMMAND:
        !           437:       switch( SHORT1FROMMP( mp1 ) )
        !           438:       {
        !           439:         case DID_OK:     /* Enter key or pushbutton pressed/ selected        */
        !           440:           if( !bModality )
        !           441:             WinPostMsg( hwndClient, DLGSAMP_RBCOMPLETE, 0L, 0L );
        !           442:           break;
        !           443:         case DID_CANCEL: /* Escape key or CANCEL pushbutton pressed/selected */
        !           444:           colorClient = colorSave;
        !           445:           break;
        !           446:         default:
        !           447:           return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           448:       }
        !           449:       if( bModality )
        !           450:         WinDismissDlg( hwndDlg, TRUE );
        !           451:       else
        !           452:         WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );
        !           453:       break;
        !           454:  
        !           455:     default:  /* Pass all other messages to the default dialog proc */
        !           456:       return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           457:   }
        !           458:   return FALSE;
        !           459: }
        !           460:  
        !           461:  
        !           462: /***********************************************************************
        !           463: *
        !           464: *  DlgProc:  fnwpCheckBoxDlg
        !           465: *
        !           466: *  A dialog procedure to which use checkboxes to change the color
        !           467: *  of the Client Area Window.
        !           468: *
        !           469: *  Side effects
        !           470: *
        !           471: *  Modifies the Client Area color and the global colorClient
        !           472: *
        !           473: ***********************************************************************/
        !           474:  
        !           475: MRESULT EXPENTRY fnwpCheckBoxDlg( hwndDlg, message, mp1, mp2 )
        !           476: HWND    hwndDlg;
        !           477: USHORT  message;
        !           478: MPARAM  mp1;
        !           479: MPARAM  mp2;
        !           480: {
        !           481:   switch (message)
        !           482:   {
        !           483:     case WM_INITDLG:
        !           484:       CentreDlgBox( hwndDlg );
        !           485:       colorSave = colorClient;
        !           486:       if( (colorClient & CLR_RED) == CLR_RED )
        !           487:         WinPostMsg( WinWindowFromID( hwndDlg, CB_RED ),
        !           488:                     BM_SETCHECK,
        !           489:                     MPFROM2SHORT( TRUE,0 ),
        !           490:                     0L );
        !           491:       if( (colorClient & CLR_GREEN) == CLR_GREEN )
        !           492:         WinPostMsg( WinWindowFromID( hwndDlg, CB_GREEN ),
        !           493:                     BM_SETCHECK,
        !           494:                     MPFROM2SHORT( TRUE,0 ),
        !           495:                     0L );
        !           496:       if( (colorClient & CLR_BLUE) == CLR_BLUE )
        !           497:         WinPostMsg( WinWindowFromID( hwndDlg, CB_BLUE ),
        !           498:                     BM_SETCHECK,
        !           499:                     MPFROM2SHORT( TRUE,0 ),
        !           500:                     0L );
        !           501:       break;
        !           502:     case WM_CONTROL:                  /* User has clicked on a checkbox */
        !           503:       if( SHORT2FROMMP( mp1 ) == BN_CLICKED )
        !           504:         CheckColor( hwndDlg, SHORT1FROMMP( mp1 ), &colorClient );
        !           505:       WinInvalidateRect( hwndClient, NULL, FALSE );
        !           506:       break;
        !           507:     case WM_COMMAND:
        !           508:       switch( SHORT1FROMMP( mp1 ) )
        !           509:       {
        !           510:         case DID_OK:     /* Enter key or pushbutton pressed/ selected */
        !           511:           if( !bModality )
        !           512:             WinPostMsg( hwndClient, DLGSAMP_CBCOMPLETE, 0L, 0L );
        !           513:           break;
        !           514:         case DID_CANCEL: /* Escape key or CANCEL pushbutton pressed/selected */
        !           515:           colorClient = colorSave;
        !           516:           break;
        !           517:         default:
        !           518:           return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           519:       }
        !           520:       if( bModality )
        !           521:         WinDismissDlg( hwndDlg, TRUE );
        !           522:       else
        !           523:         WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );
        !           524:       return FALSE;
        !           525:  
        !           526:     default:  /* Pass all other messages to the default dialog proc */
        !           527:       return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           528:   }
        !           529:   return FALSE;
        !           530: }
        !           531:  
        !           532: /***********************************************************************
        !           533: *
        !           534: *  DlgProc:  fnwpListBoxDlg
        !           535: *
        !           536: *  Side effects
        !           537: *
        !           538: *  Modifies the global szSelection
        !           539: *
        !           540: ***********************************************************************/
        !           541:  
        !           542: MRESULT EXPENTRY fnwpListBoxDlg( hwndDlg, message, mp1, mp2 )
        !           543: HWND    hwndDlg;
        !           544: USHORT  message;
        !           545: MPARAM  mp1;
        !           546: MPARAM  mp2;
        !           547: {
        !           548:   CHAR szBuffer[LEN_LISTBOXENTRY];
        !           549:   SHORT  i;
        !           550:   SHORT  id;
        !           551:  
        !           552:   switch (message)
        !           553:   {
        !           554:     case WM_INITDLG:
        !           555:       CentreDlgBox( hwndDlg );
        !           556:  
        !           557: /*************************************************************************
        !           558: *
        !           559: *   Initialise the listbox with a set of strings loaded from a
        !           560: *   resource file.
        !           561: *
        !           562: *************************************************************************/
        !           563:  
        !           564:       for ( i = 0; i < NUM_LISTBOXENTRIES; i++ )
        !           565:       {
        !           566:         WinLoadString( hab,
        !           567:                        NULL,
        !           568:                        LBI_1 + i,               /****** WARNING *********/
        !           569:                        LEN_LISTBOXENTRY,        /*      Differs         */
        !           570:                        (PSZ)szBuffer            /*      from spec       */
        !           571:                      );
        !           572:         WinSendDlgItemMsg( hwndDlg,
        !           573:                            LB_1,
        !           574:                            LM_INSERTITEM,
        !           575:                            MPFROM2SHORT( LIT_END, 0 ),
        !           576:                            MPFROMP( szBuffer )
        !           577:                          );
        !           578:       }
        !           579:       break;
        !           580:     case WM_COMMAND:
        !           581:       switch( SHORT1FROMMP( mp1 ) )
        !           582:       {
        !           583:         case DID_OK:     /* Enter key or pushbutton pressed/ selected */
        !           584:           if( bModality )
        !           585:           {
        !           586:  
        !           587: /***********************************************************************
        !           588: *
        !           589: *   Find out which item if any was selected and return the selected
        !           590: *   item text.
        !           591: *
        !           592: ***********************************************************************/
        !           593:  
        !           594:             id = SHORT1FROMMR( WinSendDlgItemMsg( hwndDlg,
        !           595:                                                   LB_1,
        !           596:                                                   LM_QUERYSELECTION,
        !           597:                                                   0L,
        !           598:                                                   0L ) );
        !           599:             if( id == LIT_NONE )
        !           600:               strcpy( szSelection, "" );
        !           601:             else
        !           602:               WinSendDlgItemMsg( hwndDlg,
        !           603:                                  LB_1,
        !           604:                                  LM_QUERYITEMTEXT,
        !           605:                                  MPFROM2SHORT( id, LEN_LISTBOXENTRY ),
        !           606:                                  MPFROMP( szSelection ) );
        !           607:           }
        !           608:           else
        !           609:             WinPostMsg( hwndClient, DLGSAMP_LBCOMPLETE, 0L, 0L );
        !           610:         case DID_CANCEL: /* Escape key or CANCEL pushbutton pressed/selected */
        !           611:           if( bModality )
        !           612:             WinDismissDlg( hwndDlg, TRUE );
        !           613:           else
        !           614:             WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );
        !           615:           return FALSE;
        !           616:         default:
        !           617:           break;
        !           618:       }
        !           619:       break;
        !           620:  
        !           621:     default:  /* Pass all other messages to the default dialog proc */
        !           622:       return WinDefDlgProc( hwndDlg, message, mp1, mp2 );
        !           623:   }
        !           624:   return FALSE;
        !           625: }
        !           626:  
        !           627: /*************************************************************************
        !           628: *
        !           629: *   PRIVATE FUNCTION : CentreDlgBox
        !           630: *
        !           631: *   Positions the dialog box in the centre of the screen
        !           632: *
        !           633: *************************************************************************/
        !           634:  
        !           635: VOID cdecl CentreDlgBox( hwnd )
        !           636: HWND hwnd;
        !           637: {
        !           638:   SHORT ix, iy;
        !           639:   SHORT iwidth, idepth;
        !           640:   SWP   swp;
        !           641:  
        !           642:   iwidth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
        !           643:   idepth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
        !           644:   WinQueryWindowPos( hwnd, (PSWP)&swp );
        !           645:   ix = ( iwidth  - swp.cx ) / 2;
        !           646:   iy = ( idepth  - swp.cy ) / 2;
        !           647:   WinSetWindowPos( hwnd, HWND_TOP, ix, iy, 0, 0, SWP_MOVE );
        !           648: }
        !           649:  
        !           650: /***************************************************************************
        !           651: *
        !           652: *  PRIVATE FUNCTION: CheckColor
        !           653: *
        !           654: *  Toggle the Checked/UnChecked state of a checkbox and add/remove
        !           655: *  the corresponding CLR color component of the Client Area Color.
        !           656: *
        !           657: ***************************************************************************/
        !           658:  
        !           659: VOID cdecl CheckColor( hwndDlg, iDlgItem, colorClient )
        !           660: HWND   hwndDlg;
        !           661: SHORT  iDlgItem;
        !           662: COLOR *colorClient;
        !           663: {
        !           664:   BOOL  bChecked;
        !           665:   COLOR color;
        !           666:  
        !           667:   switch( iDlgItem )
        !           668:   {
        !           669:     case CB_RED:
        !           670:       color = CLR_RED;
        !           671:       break;
        !           672:     case CB_GREEN:
        !           673:       color = CLR_GREEN;
        !           674:       break;
        !           675:     case CB_BLUE:
        !           676:       color = CLR_BLUE;
        !           677:       break;
        !           678:     default:
        !           679:       return;
        !           680:   }
        !           681:  
        !           682:   bChecked = SHORT1FROMMR( WinSendMsg( WinWindowFromID( hwndDlg , iDlgItem ),
        !           683:                                        BM_QUERYCHECK,
        !           684:                                        0L,
        !           685:                                        0L ) );
        !           686:   WinPostMsg( WinWindowFromID( hwndDlg, iDlgItem ),
        !           687:               BM_SETCHECK,
        !           688:               MPFROM2SHORT( !bChecked, 0 ),
        !           689:               0L );
        !           690:   if( bChecked )                   /* If color previously checked */
        !           691:     *colorClient -= color;         /* subtract it ... else        */
        !           692:   else
        !           693:     *colorClient += color;         /* ... add it.                 */
        !           694: }
        !           695:  
        !           696: /**************************************************************************
        !           697: *
        !           698: *   PRIVATE FUNCTION: EnableModality
        !           699: *
        !           700: *   Enable or disable the Modality menuitems depending  on the value
        !           701: *   of modal. This is done to prevent the user from altering the
        !           702: *   modality setting while a modeless dialog is active.
        !           703: *
        !           704: **************************************************************************/
        !           705:  
        !           706: VOID cdecl EnableModality( hwnd, bModal )
        !           707: HWND hwnd;
        !           708: BOOL bModal;
        !           709: {
        !           710:   if( bModal )
        !           711:   {
        !           712:     WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           713:                 MM_SETITEMATTR,
        !           714:                 MPFROM2SHORT( MI_MODAL, TRUE ),
        !           715:                 MPFROM2SHORT( MIA_DISABLED, ~MIA_DISABLED ) );
        !           716:     WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           717:                 MM_SETITEMATTR,
        !           718:                 MPFROM2SHORT( MI_MODELESS, TRUE ),
        !           719:                 MPFROM2SHORT( MIA_DISABLED, ~MIA_DISABLED ) );
        !           720:   }
        !           721:   else
        !           722:   {
        !           723:     WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           724:                 MM_SETITEMATTR,
        !           725:                 MPFROM2SHORT( MI_MODAL, TRUE ),
        !           726:                 MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) );
        !           727:     WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           728:                 MM_SETITEMATTR,
        !           729:                 MPFROM2SHORT( MI_MODELESS, TRUE ),
        !           730:                 MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) );
        !           731:   }
        !           732: }
        !           733:  
        !           734: /***************************************************************************
        !           735: *
        !           736: *  PRIVATE FUNCTION: IsIntInRange.
        !           737: *
        !           738: *  Checks whether the value of a dialog item is in an integer in
        !           739: *  a given range.
        !           740: *
        !           741: ***************************************************************************/
        !           742:  
        !           743: BOOL cdecl IsIntInRange( hwndDlg,  idEntryField,
        !           744:                          iLoRange, iHiRange,
        !           745:                          idErrMsg, idMessageBox )
        !           746: HWND hwndDlg;
        !           747: SHORT  idEntryField;
        !           748: SHORT  iLoRange;
        !           749: SHORT  iHiRange;
        !           750: SHORT  idErrMsg;
        !           751: SHORT  idMessageBox;
        !           752: {
        !           753:   SHORT ivalue;
        !           754:   CHAR  szErrMsg[80];
        !           755:  
        !           756: /****************************************************************************
        !           757: *
        !           758: *   Validate an entry field.
        !           759: *
        !           760: *   If validation fails leave the dialog visible, issue an error message
        !           761: *   using a messagebox, and when the user dismisses the messagebox,
        !           762: *   set the input focus to the entry field containing the error. Leave
        !           763: *   the contents of the entry field unchanged, and return FALSE.
        !           764: *
        !           765: *   If validation is successful return the value in ivalue and return
        !           766: *   TRUE.
        !           767: *
        !           768: ****************************************************************************/
        !           769:  
        !           770:   if( !WinQueryDlgItemShort( hwndDlg, idEntryField, &ivalue, TRUE ) ||
        !           771:       ( ivalue < iLoRange ) ||
        !           772:       ( ivalue > iHiRange ) )
        !           773:   {
        !           774:     WinLoadString( hab, NULL, idErrMsg, sizeof( szErrMsg ), szErrMsg );
        !           775:     WinMessageBox( HWND_DESKTOP,
        !           776:                    hwndFrame,
        !           777:                    (PSZ)szErrMsg,
        !           778:                    NULL,
        !           779:                    idMessageBox,
        !           780:                    MB_OK );
        !           781:     WinSetFocus( HWND_DESKTOP, WinWindowFromID( hwndDlg, idEntryField ) );
        !           782:     return FALSE;
        !           783:   }
        !           784:   else
        !           785:     return TRUE;
        !           786: }
        !           787:  
        !           788: /***********************************************************************
        !           789: *
        !           790: *  PRIVATE FUNCTION: LoadDialog
        !           791: *
        !           792: *  Use the appropriate functions to put up a modal or modeless
        !           793: *  dialog box depending on the setting of the bModality parameter.
        !           794: *
        !           795: *  Side Effects
        !           796: *
        !           797: *  Stes the value of the global hwndModelessDlg
        !           798: *
        !           799: ***********************************************************************/
        !           800:  
        !           801: VOID cdecl LoadDialog( hwndParent, hwndOwner, idDlg, fnwpDlgProc, bModality )
        !           802: HWND  hwndParent;
        !           803: HWND  hwndOwner;
        !           804: SHORT idDlg;
        !           805: PFNWP fnwpDlgProc;
        !           806: BOOL  bModality;
        !           807: {
        !           808:   EnableModality( hwndOwner, FALSE ); /* Disable the Modality menu item */
        !           809:  
        !           810:   if( bModality )
        !           811:   {
        !           812:     WinDlgBox( hwndParent,        /* Parent                    */
        !           813:                hwndOwner,         /* Owner                     */
        !           814:                fnwpDlgProc,       /* Address of dialog proc    */
        !           815:                NULL,              /* Module handle             */
        !           816:                idDlg,             /* Id of dialog in resource  */
        !           817:                NULL );            /* Initialisation data       */
        !           818:     EnableModality( hwndOwner, TRUE ); /* Enable the Modality menu item */
        !           819:   }
        !           820:   else
        !           821:   {
        !           822:     /*******************************************************************
        !           823:     *
        !           824:     *   Check to see if a modeless dialog is already running: if
        !           825:     *   so destroy it before for loading the requested dialog. Save
        !           826:     *   the handle of the new dialog in a global variable so that in
        !           827:     *   can be accessed by the WinProc that issued LoadDialog.
        !           828:     *
        !           829:     *******************************************************************/
        !           830:  
        !           831:     if( WinIsWindow( hab, hwndModelessDlg ) )
        !           832:       WinDestroyWindow( hwndModelessDlg );
        !           833:     hwndModelessDlg = WinLoadDlg( hwndParent,
        !           834:                                   hwndOwner,
        !           835:                                   fnwpDlgProc,
        !           836:                                   NULL,
        !           837:                                   idDlg,
        !           838:                                   NULL );
        !           839:   }
        !           840: }
        !           841:  
        !           842: /*************************************************************************
        !           843: *
        !           844: *   PRIVATE FUNCTION: MainWndCommand
        !           845: *
        !           846: *   Take the appropriate action when a WM_COMMAND message is received by
        !           847: *   MainWndProc.  Issues calls which load dialogs in the prevailing state
        !           848: *   of modality.
        !           849: *
        !           850: *************************************************************************/
        !           851:  
        !           852: VOID cdecl MainWndCommand( hwnd, Command, bModality )
        !           853: HWND   hwnd;
        !           854: USHORT Command;
        !           855: BOOL   *bModality;
        !           856: {
        !           857:   USHORT idDlg;
        !           858:   PFNWP  pfnDlgProc;
        !           859:  
        !           860:   switch( Command )
        !           861:   {
        !           862:     case MI_MODAL:
        !           863:     case MI_MODELESS:
        !           864:       *bModality = ( Command == MI_MODAL ) ? TRUE
        !           865:                                            : FALSE;
        !           866:       SetModality( WinQueryWindow( hwnd, QW_PARENT, FALSE ), *bModality );
        !           867:       WinInvalidateRect( hwnd, NULL, FALSE );
        !           868:       return;
        !           869:     case MI_EXIT:
        !           870:       WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
        !           871:       return;
        !           872:     case MI_RESUME:
        !           873:       return;
        !           874:     case MI_ENTRYFIELDEXAMPLE:
        !           875:       idDlg      = DLG_ENTRYFIELDEXAMPLE;
        !           876:       pfnDlgProc = (PFNWP)fnwpEntryFieldDlg;
        !           877:       break;
        !           878:     case MI_AUTORADIOBUTTONEXAMPLE:
        !           879:       idDlg      = DLG_AUTORADIOBUTTONEXAMPLE;
        !           880:       pfnDlgProc = (PFNWP)fnwpAutoRadioButtonDlg;
        !           881:       break;
        !           882:     case MI_CHECKBOXEXAMPLE:
        !           883:       idDlg      = DLG_CHECKBOXEXAMPLE;
        !           884:       pfnDlgProc = (PFNWP)fnwpCheckBoxDlg;
        !           885:       break;
        !           886:     case MI_LISTBOXEXAMPLE:
        !           887:       idDlg      = DLG_LISTBOXEXAMPLE;
        !           888:       pfnDlgProc = (PFNWP)fnwpListBoxDlg;
        !           889:       break;
        !           890:     default:
        !           891:       return;
        !           892:   }
        !           893:   LoadDialog( HWND_DESKTOP,
        !           894:               hwndFrame,
        !           895:               idDlg,
        !           896:               pfnDlgProc,
        !           897:               *bModality );
        !           898:   if( *bModality )
        !           899:     WinInvalidateRect( hwnd, NULL, FALSE );  /* Request whole window repaint */
        !           900: }
        !           901:  
        !           902: /************************************************************************
        !           903: *
        !           904: *   PRIVATE FUNCTION: MainWndPaint
        !           905: *
        !           906: *   An unsophisticated window painting routine which simply repaints the
        !           907: *   entire window when a WM_PAINT message is received. In a real
        !           908: *   application more sophisticated techniques could be used to determine
        !           909: *   the minimum region needing repainting, and to paint only that
        !           910: *   region
        !           911: *
        !           912: ************************************************************************/
        !           913:  
        !           914: VOID cdecl MainWndPaint( hwnd )
        !           915: HWND hwnd;
        !           916: {
        !           917:   POINTL   pointl;
        !           918:   HPS      hps;                          /* Presentation space handle */
        !           919:   RECTL    rcl;                          /* Window rectangle          */
        !           920:   CHAR     string[50];
        !           921:  
        !           922:   hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&rcl );
        !           923:   WinFillRect( hps, (PRECTL)&rcl, colorClient );
        !           924:   GpiSetColor( hps, (colorClient == 0L) ? CLR_WHITE
        !           925:                                         : CLR_BLACK );
        !           926:   pointl.x = 10L; pointl.y = 70L;
        !           927:   strcpy( string, "Dialog modality    = " );
        !           928:   strcat( string, (bModality) ? "Modal"
        !           929:                               : "Modeless" );
        !           930:   GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );
        !           931:   pointl.y = 50L;
        !           932:   strcpy( string, "Entry Field 1      = " );
        !           933:   strcat( string, szEntryField1 );
        !           934:   GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );
        !           935:   pointl.y = 30L;
        !           936:   strcpy( string, "Entry Field 2      = " );
        !           937:   strcat( string, szEntryField2 );
        !           938:   GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );
        !           939:   pointl.y = 10L;
        !           940:   strcpy( string, "List Box Selection = " );
        !           941:   strcat( string, szSelection );
        !           942:   GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );
        !           943:   WinEndPaint( hps );
        !           944:  }
        !           945:  
        !           946: /**************************************************************************
        !           947: *
        !           948: *  PRIVATE FUNCTION: SetModality
        !           949: *
        !           950: *  Check or uncheck Modal and Modeless menu items as appropriate.
        !           951: *
        !           952: **************************************************************************/
        !           953:  
        !           954: VOID cdecl SetModality( hwnd, bModal )
        !           955: HWND hwnd;
        !           956: BOOL bModal;
        !           957: {
        !           958:   WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           959:               MM_SETITEMATTR,
        !           960:               MPFROM2SHORT( MI_MODAL, TRUE ),
        !           961:               MPFROM2SHORT( MIA_CHECKED, (bModal) ? ( MIA_CHECKED)
        !           962:                                                   : (~MIA_CHECKED) ) );
        !           963:  
        !           964:   WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),
        !           965:               MM_SETITEMATTR,
        !           966:               MPFROM2SHORT( MI_MODELESS, TRUE ),
        !           967:               MPFROM2SHORT( MIA_CHECKED, (bModal) ? (~MIA_CHECKED)
        !           968:                                                   : ( MIA_CHECKED) ) );
        !           969:  
        !           970: }

unix.superglobalmegacorp.com

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