home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BMAP01.ZIP / BMAP01.C < prev    next >
C/C++ Source or Header  |  1993-01-21  |  8KB  |  247 lines

  1. //█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  2. //█ Module.....: bmap01.c                                                    █
  3. //█ Date.......: Thu Jan 21 14:36:32 1993                                    █
  4. //█ Version....: 1.0                                                         █
  5. //█ Author.....: Wade A. Deuter / Progressive Software Technologies, Inc.    █
  6. //█                                                                          █
  7. //█ Description: Bitmap Sample - Display Bitmap In A Window                  █
  8. //█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  9.  
  10. //
  11. // Window Coordinates
  12. //
  13.  
  14. #define EXTERN
  15.  
  16. #define TOP    550
  17. #define LEFT     0
  18. #define BOTTOM   0
  19. #define RIGHT  750
  20.  
  21. #include "BMAP01.h"
  22.  
  23. HDC     hdc,      
  24.         hdcMemory;
  25. HPS     hps,      
  26.         hpsMemory;
  27. LONG    alBmpFormats[2];
  28. HBITMAP hbmSrc;
  29. LONG    lcxMinMax, 
  30.         lcyMinMax;
  31. SHORT   sGridy, 
  32.         sGridx,
  33.         sMoveVar, 
  34.         sxPels, 
  35.         syPels;
  36. BOOL    FirstTime = 1;
  37.  
  38. SIZEL   sizl;
  39. SIZEL   NewSizl;
  40.  
  41. BITMAPINFOHEADER bmp;
  42. POINTL           aptl[4];
  43. HPS              hpsd;
  44. RECTL            rclInvalid, 
  45.                  WinSize;
  46.  
  47. int              Width  = RIGHT - LEFT,
  48.                  Height = TOP - BOTTOM;
  49.  
  50. int main( void )
  51. {
  52.   QMSG        qmsg; 
  53.   INT         rc;
  54.   ULONG       ctldata;
  55.   
  56.   if((hAB = WinInitialize(0)) == 0)
  57.      return(FALSE);
  58.    
  59.   if((hMQ = WinCreateMsgQueue(hAB, 0)) == 0)
  60.      return(FALSE);
  61.            
  62.   rc = WinRegisterClass(hAB,                                              // Anchor block handle            
  63.                        (PCH)"BMAP01",                                     // Name of class being registered 
  64.                        (PFNWP)WndProc,                                    // Window procedure for class     
  65.                        CS_SIZEREDRAW ,                
  66.                        0);                                                // Extra bytes to reserve         
  67.   if (rc == FALSE)
  68.     return(FALSE);
  69.  
  70.   ctldata = FCF_TITLEBAR     |
  71.             FCF_SYSMENU      |
  72.             FCF_MINBUTTON    |
  73.             FCF_MAXBUTTON    |
  74.             FCF_SIZEBORDER   |
  75.             FCF_MENU         |
  76.             FCF_SHELLPOSITION;
  77.  
  78.   hWndFrame = WinCreateStdWindow(HWND_DESKTOP,                            // parent of window    
  79.                                  0L,                                      // frame window style  
  80.                                  &ctldata,                                // frame flags         
  81.                                  "BMAP01",                                // class name          
  82.                                  "BMAP01",                                // window title        
  83.                                  0L,                                      // client window style 
  84.                                  0,                                       // module for resources
  85.                                  ID_BMAP01,                               // resource id         
  86.                                  (HWND FAR *)&hWndClient);                // client handle
  87.  
  88.   if(hWndFrame == 0)
  89.      return(FALSE);
  90.  
  91.   // 
  92.   // Window was not displayed because frame window style was specified as 0L,
  93.   // so here we size it and make it visible
  94.   //
  95.   WinSetWindowPos( hWndFrame, HWND_TOP, LEFT, BOTTOM, RIGHT, TOP, SWP_SIZE | SWP_MOVE | SWP_SHOW);
  96.  
  97.   while(WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  98.         WinDispatchMsg(hAB,(PQMSG)&qmsg);
  99.  
  100.   WinDestroyWindow(hWndFrame);
  101.   WinDestroyMsgQueue(hMQ);    
  102.   WinTerminate(hAB);          
  103. }
  104.  
  105. //┌──────────────────────────────────────────────────────────────────────────┐
  106. //│ Function...: WndProc                                                     │
  107. //│ Date.......: Wed Jan 20 10:34:17 1993                                    │
  108. //│ Author.....: Wade A. Deuter                                              │
  109. //│                                                                          │
  110. //│ Description:                                                             │
  111. //└──────────────────────────────────────────────────────────────────────────┘
  112. MRESULT EXPENTRY WndProc(HWND hWnd, USHORT message, MPARAM mp1, MPARAM mp2)
  113. {                      
  114.    HPS    hps;            
  115.  
  116.    static HBITMAP   Bitmap;
  117.  
  118.    RECTL  Rect, 
  119.       rcl,
  120.       WinSize;      
  121.  
  122.    USHORT rc;
  123.  
  124.    switch(message)
  125.      {
  126.       case WM_COMMAND:
  127.            switch(SHORT1FROMMP(mp1))
  128.             {
  129.              case IDM_H_ABOUT:
  130.  
  131.                   rc = WinDlgBox(HWND_DESKTOP, 
  132.                          hWnd, 
  133.                  (PFNWP)BMAPABTMsgProc,
  134.                                  0, 
  135.                  IDLG_BMAPABT, 
  136.                  NULL);
  137.                   break;
  138.  
  139.              default:
  140.                   break;
  141.             }
  142.            break;
  143.  
  144.       case WM_SIZE:
  145.        //
  146.        // Load Bitmap and get ready to use it 
  147.        //
  148.            WinSetPointer (HWND_DESKTOP,
  149.                           WinQuerySysPointer (HWND_DESKTOP, SPTR_WAIT, FALSE));
  150.  
  151.            WinQueryWindowRect (hWnd, &WinSize);
  152.        Width  = WinSize.xRight - WinSize.xLeft;
  153.        Height = WinSize.yTop - WinSize.yBottom;
  154.  
  155.            hps    = WinGetPS( hWnd );
  156.            Bitmap = GpiLoadBitmap( hps, (USHORT)NULL, ID_LOGO, Width, Height );
  157.            WinReleasePS( hps );
  158.  
  159.            WinSetPointer (HWND_DESKTOP,
  160.                           WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE));
  161.            break;
  162.  
  163.       case WM_CREATE:
  164.        //
  165.        // Load Bitmap and get ready to use it 
  166.        //
  167.  
  168.            hps    = WinGetPS( hWnd );
  169.            Bitmap = GpiLoadBitmap( hps, (USHORT)NULL, ID_LOGO, Width, Height );
  170.            WinReleasePS( hps );
  171.         
  172.            break;
  173.  
  174.       case WM_PAINT:
  175.        // 
  176.        // Draw Bitmap In Window
  177.        //
  178.            hps = WinBeginPaint (hWnd, (HPS) NULL, &Rect);
  179.            WinQueryWindowRect (hWnd, &rcl);
  180.            
  181.            WinSetPointer (HWND_DESKTOP,
  182.                           WinQuerySysPointer (HWND_DESKTOP, SPTR_WAIT, FALSE));
  183.            
  184.            WinDrawBitmap (hps,
  185.                           Bitmap,
  186.                           NULL,
  187.                           (PPOINTL) &rcl,
  188.                           CLR_BLACK,
  189.                           CLR_BLACK,
  190.                           DBM_NORMAL);
  191.            
  192.            WinSetPointer (HWND_DESKTOP,
  193.                           WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE));
  194.            
  195.            WinEndPaint (hps);
  196.            return(MRESULT)FALSE;
  197.  
  198.       case WM_DESTROY:
  199.            GpiDeleteBitmap( Bitmap );
  200.            return(MRESULT)NULL;
  201.  
  202.       default:
  203.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  204.            break; 
  205.      } 
  206.    return(0L);
  207. }
  208.  
  209. //┌──────────────────────────────────────────────────────────────────────────┐
  210. //│ Function...: BMAPABTMsgProc                                              │
  211. //│ Date.......: Wed Jan 20 10:34:41 1993                                    │
  212. //│ Author.....: Wade A. Deuter                                              │
  213. //│                                                                          │
  214. //│ Description:                                                             │
  215. //└──────────────────────────────────────────────────────────────────────────┘
  216. MRESULT EXPENTRY BMAPABTMsgProc(HWND hWndDlg, USHORT message, MPARAM mp1, MPARAM mp2)
  217.  switch(message)
  218.    {
  219.     case WM_COMMAND:
  220.          switch(SHORT1FROMMP(mp1))
  221.            {
  222.             case DID_OK:
  223.                  WinDismissDlg(hWndDlg, TRUE);
  224.                  break;
  225.            }
  226.          break;
  227.  
  228.     case WM_CLOSE:
  229.          WinDismissDlg(hWndDlg, FALSE);
  230.          break;
  231.   
  232.     case WM_FAILEDVALIDATE:
  233.          return((MRESULT)TRUE);
  234.          break;
  235.  
  236.     default:
  237.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  238.          break;
  239.    }
  240.  return FALSE;
  241. }
  242.  
  243.  
  244.  
  245.  
  246.