home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bitmap1.zip / APP1.CPP next >
Text File  |  1993-12-02  |  4KB  |  143 lines

  1. // bitmap test program
  2.  
  3. // Copyright (C) Joel Barnum, Descriptor Systems, 1993
  4.  
  5. #define INCL_WIN
  6. #define INCL_GPI
  7. #include <os2.h>
  8. #include "app1.h"
  9. #include "bitmap.hpp"
  10. #include "bitfile.hpp"
  11.  
  12. /* Internal function prototypes  */
  13.  
  14. MRESULT EXPENTRY App1WindowProc( HWND hwnd,ULONG msg
  15.                                , MPARAM mp1,MPARAM mp2 );
  16. int main ( int argc, char *argv[] );
  17.  
  18. int main ( int argc, char *argv[] )
  19. {
  20.     HAB  hab;               // anchor block handle
  21.     HWND hwndFrame;         // frame window handle
  22.     HWND hwndClient;        // client window handle
  23.     HMQ  hmq;               // message queue handle
  24.     QMSG qmsg;              // message from message queue
  25.     ULONG flCreate;         // window creation control flags
  26.  
  27.     hab = WinInitialize ( 0 );
  28.  
  29.     hmq = WinCreateMsgQueue ( hab, 0 );
  30.  
  31.     WinRegisterClass( hab, "App1Window", App1WindowProc
  32.                 , CS_SIZEREDRAW, 0 );
  33.  
  34.     flCreate = FCF_SYSMENU          |
  35.                FCF_SIZEBORDER       |
  36.                FCF_TITLEBAR         |
  37.                FCF_MINMAX           |
  38.                FCF_SHELLPOSITION    |
  39.                FCF_ICON                |
  40.                FCF_TASKLIST;
  41.  
  42.     hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE
  43.                     , &flCreate ,"App1Window"
  44.                     , "Descriptor Systems Bitmap Example", 0, 0
  45.                     , ID_APP1, &hwndClient );
  46.  
  47.     while( WinGetMsg( hab, &qmsg, (HWND)0, 0, 0 )  != FALSE )
  48.         WinDispatchMsg( hab, &qmsg );
  49.  
  50.     WinDestroyWindow( hwndFrame );
  51.     WinDestroyMsgQueue( hmq );
  52.     WinTerminate( hab );
  53.     return 0;
  54. }
  55. //******************************************************
  56. MRESULT EXPENTRY App1WindowProc ( HWND hwnd, ULONG msg
  57.                                 , MPARAM mp1, MPARAM mp2 )
  58. {
  59.     static     bitmap    *pb1;                // bitmap object
  60.     static     bitmap    *pb2;                // bitmap object
  61.  
  62.     switch( msg )
  63.     {
  64.         case WM_CREATE:
  65.             {
  66.                   HPS     hps = WinGetPS ( hwnd );
  67.                 HDC     hdc = GpiQueryDevice ( hps );
  68.  
  69.               // create a bitmap from a resource
  70.                 pb1 = new bitmap ( hdc, NULLHANDLE, ID_BITMAP );
  71.  
  72.               // create a bitmap file object
  73.                   bitmapfile *pbmfile = new bitmapfile ( "TEST1.BMP" );
  74.  
  75.               // create a bitmap from the file data
  76.                 switch ( pbmfile->gettype() )
  77.                 {
  78.                     case BITMAP:
  79.                         pb2 = new bitmap ( hdc
  80.                             , pbmfile->getbitmapinfo()
  81.                             , pbmfile->getbitmapbits() );
  82.  
  83.                         break;
  84.  
  85.                     case UNKNOWN:
  86.                         WinMessageBox ( HWND_DESKTOP, hwnd
  87.                             , "Not a bitmap file", "Error", 0
  88.                             , MB_OK | MB_MOVEABLE | MB_ERROR );
  89.                             break;
  90.  
  91.                     case ERROR:
  92.                         WinMessageBox ( HWND_DESKTOP, hwnd
  93.                             , "Error opening file", "Error", 0
  94.                             , MB_OK | MB_MOVEABLE | MB_ERROR );
  95.                             break;
  96.                 }
  97.  
  98.                 delete pbmfile;
  99.  
  100.                 WinReleasePS ( hps );
  101.             }
  102.             return FALSE;
  103.  
  104.         case WM_PAINT:
  105.             {
  106.                 HPS        hps;
  107.  
  108.                 hps = WinBeginPaint ( hwnd , (HPS)0, NULL );
  109.                 GpiErase ( hps );
  110.  
  111.               // draw the bitmaps
  112.                   POINTL    ptl;
  113.  
  114.                 if ( pb1 )
  115.                 {
  116.                     ptl.x = ptl.y = 50;
  117.                     pb1->draw ( hps, ptl );
  118.                 }
  119.  
  120.                 if ( pb2 )
  121.                 {
  122.                     ptl.x = ptl.y = 250;
  123.                     pb2->draw ( hps, ptl );
  124.                 }
  125.  
  126.                 WinEndPaint ( hps );
  127.             }
  128.             return (MRESULT) NULL;
  129.  
  130.         case WM_CLOSE:
  131.             WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
  132.             return (MRESULT) NULL;
  133.  
  134.         case WM_DESTROY:
  135.             delete pb1;
  136.             delete pb2;
  137.             return 0;
  138.  
  139.         default:
  140.             return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
  141.     }
  142. }
  143.