home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / WINPROPM.ZIP / EXAMMAIN.C < prev    next >
Text File  |  1989-06-19  |  7KB  |  255 lines

  1. /* file : Exammain.c
  2.  
  3.  
  4.         Created: 21:55:40 Mon Jun 19 1989
  5.  
  6.         Description:  Main routines for "ExamplPM"
  7.                       Presentation Manager application
  8.  
  9.         Skeleton by:  WINPRO/PM, a product from Louis J. Cutrona, Jr.
  10.                       Skeleton.pm (Revision 2.5)  
  11.  
  12. */
  13.  
  14. /* Activate standard window management definitions and typedefs */
  15. #define  INCL_WIN
  16. #define  INCL_GPI
  17. /* Activate definitions for ExitList processing */
  18. #define  INCL_DOSPROCESS
  19.  
  20. #include <os2.h>
  21.  
  22. #include "Examrc.h"
  23. #include "Examgbl.h"
  24.  
  25.  
  26. /*   E X A M P L  P  M   C L E A N  U P  */  /* Exit list process */
  27. VOID PASCAL FAR   ExamplPMCleanUp( USHORT usTermCode )
  28. {
  29.    /* This routine gets control after all other threads have been */
  30.    /* terminated.  Do any final clean-up here.  Don't dawdle!     */
  31.  
  32.    /* ExamplPMCleanUp is invoked by a JMP not a CALL, so it must   */
  33.    /* not issue a RETURN.  This is the only correct way to end it */
  34.    DosExitList( EXLST_EXIT, 0L ) ;     /* Termination complete */
  35. }
  36.  
  37.  
  38.  
  39. /* M A I N */  /* Main procedure for ExamplPM */
  40. VOID cdecl main( argc, argv )
  41. SHORT     argc;
  42. char    **argv;
  43. {
  44.    QMSG     qmsg;
  45.  
  46.    /* Initialize anchor block */
  47.    gbl_hab = WinInitialize( (USHORT) 0 );
  48.  
  49.    /* Create message queue of default size */
  50.    gbl_hmqExamplPM = WinCreateMsgQueue( gbl_hab, 0 );
  51.  
  52.    if( ! ExamplPMInit() )
  53.       DosExit( EXIT_PROCESS, 1 ) ;
  54.  
  55.    /* Specify the routine to call at application termination time */
  56.    DosExitList( EXLST_ADD, ExamplPMCleanUp ) ;
  57.  
  58.    while( WinGetMsg( gbl_hab, (PQMSG) &qmsg, (HWND) 0, (USHORT) 0, (USHORT) 0) )
  59.       WinDispatchMsg( gbl_hab, (PQMSG) &qmsg );
  60.  
  61.    WinDestroyWindow( gbl_hwndAppFrame ) ;
  62.    WinDestroyMsgQueue( gbl_hmqExamplPM );
  63.    WinTerminate( gbl_hab );
  64.    DosExit( EXIT_PROCESS, 0 ) ;
  65. }
  66.  
  67.  
  68. /*  F  O K  T O  T E R M I N A T E   E X A M P L  P  M   */
  69. BOOL  fOkToTerminateExamplPM()
  70. {
  71.    /* This routine responds to a request to terminate the application. */
  72.    /* If termination is ok or we can make it ok by the time this       */
  73.    /* function completes, we will return TRUE.  If, at the end of this */
  74.    /* routine we have decided (probably after querying the user) that  */
  75.    /* we don't want to terminate yet, then we will return FALSE.       */
  76.  
  77.    MRESULT  RetCode;
  78.  
  79.    RetCode = WinMessageBox( HWND_DESKTOP,
  80.                gbl_hwndApp,
  81.                (PSZ) "Terminate (from fOkToTerminateExamplPM)",
  82.                (PSZ) gbl_psz( IDS_NAME ),     /* Caption */
  83.                (USHORT) 0,                    /* ID for Help */
  84.                MB_OKCANCEL | MB_ICONQUESTION
  85.                );
  86.  
  87.    if( RetCode == DID_OK )
  88.    {
  89.       return TRUE;
  90.    }
  91.    else
  92.       return FALSE;
  93. }
  94.  
  95.  
  96. /*  F   E X A M P L  P  M   C L O S E  */
  97. BOOL  fExamplPMClose()
  98. {
  99.    /* A WM_CLOSE message was sent to the main window.  If it is  */
  100.    /* ok to terminate the application, post a WM_QUIT message    */
  101.    /* and return TRUE.  If we decide not to terminate, return    */
  102.    /* FALSE.                                                     */
  103.       
  104.    /* In processing this message, we get a chance to prompt the  */
  105.    /* user for confirmation if appropriate and then, if needed,  */
  106.    /* do whatever needs to be done to terminate the application  */
  107.    /* in an orderly fashion or simply continue processing.       */
  108.  
  109.    BOOL  RetCode;
  110.  
  111.    RetCode = fOkToTerminateExamplPM();
  112.  
  113.    if( RetCode )
  114.       WinPostQueueMsg( gbl_hmqExamplPM, WM_QUIT, (MPARAM) 0, (MPARAM) 0 );
  115.    
  116.    return( RetCode );
  117. }
  118.  
  119.  
  120. /*   E X A M P L  P  M   P A I N T  */
  121. void ExamplPMPaint( hWnd, hps )
  122. HWND     hWnd;
  123. HPS      hps;
  124. {
  125.    RECTL    rcl;
  126.  
  127.    GpiSavePS( hps );
  128.  
  129.    GpiCreateLogColorTable( hps, 0L, LCOLF_RGB, 0L, 0L, NULL );
  130.  
  131.    WinQueryWindowRect( hWnd, &rcl) ;
  132.  
  133.    WinFillRect( hps, &rcl,
  134.       (COLOR) 0x808080L       /* Dark Grey */ 
  135.       );
  136.  
  137.    GpiRestorePS( hps, -1L );
  138. }
  139.  
  140.  
  141. /*   E X A M P L  P  M   W N D  P R O C  */  /* Procedures which make up the window class */
  142. MRESULT EXPENTRY ExamplPMWndProc( HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  143. {
  144.    HPS      hps;     /* Handle to a presentation space */
  145.    ULONG    RetCode;
  146.  
  147.    switch( msg )
  148.    {
  149.    case WM_CREATE:
  150.       /* Put a call here to a routine to handle initialization */
  151.       break;
  152.  
  153.    case WM_CLOSE:
  154.       /* Message sent when user selects "Close" on the system menu. */
  155.       /* Also sent within this application when user selects item   */
  156.       /* midEXIT (by convention "Exit" on the leftmost pull-down    */
  157.       /* menu.                                                      */
  158.  
  159.       /* If WinDefWindowProc gets this message, it will call the    */
  160.       /* WinDestroyWindow function and we'll get a WM_DESTROY.      */
  161.  
  162.       /* For reasons known only to Microsoft, return FALSE if we    */
  163.       /* are terminating; return TRUE if we are not!                */
  164.  
  165.       return( (MRESULT) ! fExamplPMClose() );
  166.       break;
  167.  
  168.    case WM_PAINT:
  169.       hps = WinBeginPaint( hWnd, (HPS) NULL, (PRECTL) NULL );
  170.       ExamplPMPaint( hWnd, hps );
  171.       WinEndPaint( hps );
  172.       break;
  173.  
  174.    case WM_ERASEBACKGROUND:
  175.       /* Tell frame window to erase with current system window color */
  176.       return( TRUE );
  177.       break;
  178.  
  179.    case WM_COMMAND:
  180.       switch( COMMANDMSG( &msg )->cmd )
  181.       {
  182.       case midFILENEW:
  183.          RetCode = midFILENEWFunction( (PUSHORT) &msg ) ;
  184.          break ;
  185.       case midFILEOPEN:
  186.          RetCode = midFILEOPENFunction( (PUSHORT) &msg ) ;
  187.          break ;
  188.       case midFILESAVE:
  189.          RetCode = midFILESAVEFunction( (PUSHORT) &msg ) ;
  190.          break ;
  191.       case ABOUT:
  192.          RetCode = ABOUTFunction( (PUSHORT) &msg ) ;
  193.          break ;
  194.       case midEDITRESTORE:
  195.          RetCode = midEDITRESTOREFunction( (PUSHORT) &msg ) ;
  196.          break ;
  197.       case midEDITCUT:
  198.          RetCode = midEDITCUTFunction( (PUSHORT) &msg ) ;
  199.          break ;
  200.       case midEDITCOPY:
  201.          RetCode = midEDITCOPYFunction( (PUSHORT) &msg ) ;
  202.          break ;
  203.       case midEDITPASTE:
  204.          RetCode = midEDITPASTEFunction( (PUSHORT) &msg ) ;
  205.          break ;
  206.       case midEDITCLEAR:
  207.          RetCode = midEDITCLEARFunction( (PUSHORT) &msg ) ;
  208.          break ;
  209.       case midCREATESCAN:
  210.          RetCode = midCREATESCANFunction( (PUSHORT) &msg ) ;
  211.          break ;
  212.       case midCREATEPROCESS:
  213.          RetCode = midCREATEPROCESSFunction( (PUSHORT) &msg ) ;
  214.          break ;
  215.       case MID_EXIT:
  216.          RetCode = MID_EXITFunction( (PUSHORT) &msg ) ;
  217.          break ;
  218.       case accelF10:
  219.          RetCode = accelF10Function( (PUSHORT) &msg ) ;
  220.          break ;
  221.       default:
  222.          break;
  223.       }
  224.       break;
  225.  
  226.    case WM_HELP:
  227.       switch( COMMANDMSG( &msg )->cmd )
  228.       {
  229.       case midHELP:
  230.          RetCode = midHELPFunction( (PUSHORT) &msg ) ;
  231.          break ;
  232.       default:
  233.          break;
  234.       }
  235.       break;
  236.  
  237.    case WM_SYSCOMMAND:
  238.       switch( COMMANDMSG( &msg )->cmd )
  239.       {
  240.       default:
  241.          break;
  242.       }
  243.       break;
  244.  
  245.    default:
  246.       return WinDefWindowProc( hWnd, msg, mp1, mp2 );
  247.       break;
  248.    }
  249.    return( (MRESULT) 0 );
  250. }
  251.  
  252.  
  253.  
  254. /*   E N D   O F   E X A M M A I N . C   */
  255.