Annotation of pmsdk/samples/petzold/chap06/bitcat2.c, revision 1.1.1.1

1.1       root        1: /*------------------------------------------
                      2:    BITCAT2.C -- Bitmap Creation and Display
                      3:   ------------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #define INCL_GPI
                      7: #include <os2.h>
                      8: #include <stdlib.h>
                      9: #include "bitcat.h"
                     10: 
                     11: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     12: 
                     13: HAB  hab ;
                     14: 
                     15: int main (void)
                     16:      {
                     17:      static CHAR  szClientClass [] = "BitCat2" ;
                     18:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
                     19:                                  FCF_SIZEBORDER    | FCF_MINMAX   |
                     20:                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
                     21:      HMQ          hmq ;
                     22:      HWND         hwndFrame, hwndClient ;
                     23:      QMSG         qmsg ;
                     24: 
                     25:      hab = WinInitialize (0) ;
                     26:      hmq = WinCreateMsgQueue (hab, 0) ;
                     27: 
                     28:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
                     29: 
                     30:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
                     31:                                      &flFrameFlags, szClientClass, NULL,
                     32:                                      0L, NULL, 0, &hwndClient) ;
                     33: 
                     34:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     35:           WinDispatchMsg (hab, &qmsg) ;
                     36: 
                     37:      WinDestroyWindow (hwndFrame) ;
                     38:      WinDestroyMsgQueue (hmq) ;
                     39:      WinTerminate (hab) ;
                     40:      return 0 ;
                     41:      }
                     42: 
                     43: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     44:      {
                     45:      static HBITMAP   hbm ;
                     46:      static HDC       hdcMemory ;
                     47:      static HPS       hpsMemory ;
                     48:      static SHORT     cxClient, cyClient ;
                     49:      BITMAPINFO       *pbmi ;
                     50:      BITMAPINFOHEADER bmp ;
                     51:      HPS              hps ;
                     52:      POINTL           aptl [4] ;
                     53:      SIZEL            sizl ;
                     54: 
                     55:      switch (msg)
                     56:           {
                     57:           case WM_CREATE:
                     58: 
                     59:                          /*-------------------------------------------------
                     60:                             Open memory DC and create PS associated with it
                     61:                            -------------------------------------------------*/
                     62: 
                     63:                hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;
                     64: 
                     65:                sizl.cx = 0 ;
                     66:                sizl.cy = 0 ;
                     67: 
                     68:                hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl,
                     69:                                        PU_PELS    | GPIF_DEFAULT |
                     70:                                         GPIT_MICRO | GPIA_ASSOC) ;
                     71: 
                     72:                          /*------------------------
                     73:                             Create 32 by 32 bitmap
                     74:                            ------------------------*/
                     75: 
                     76:                bmp.cbFix     = sizeof bmp ;
                     77:                bmp.cx        = 32 ;
                     78:                bmp.cy        = 32 ;
                     79:                bmp.cPlanes   = 1 ;
                     80:                bmp.cBitCount = 1 ;
                     81: 
                     82:                hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, NULL, NULL) ;
                     83: 
                     84:                          /*------------------------------
                     85:                             Select bitmap into memory PS
                     86:                            ------------------------------*/
                     87: 
                     88:                GpiSetBitmap (hpsMemory, hbm) ;
                     89: 
                     90:                          /*-------------------------------------
                     91:                             Set bitmap bits from abBitCat array
                     92:                            -------------------------------------*/
                     93: 
                     94:                pbmi = malloc (sizeof (BITMAPINFO) + sizeof (RGB)) ;
                     95: 
                     96:                pbmi->cbFix     = sizeof bmp ;
                     97:                pbmi->cx        = 32 ;
                     98:                pbmi->cy        = 32 ;
                     99:                pbmi->cPlanes   = 1 ;
                    100:                pbmi->cBitCount = 1 ;
                    101: 
                    102:                pbmi->argbColor[0].bBlue  = 0 ;
                    103:                pbmi->argbColor[0].bGreen = 0 ;
                    104:                pbmi->argbColor[0].bRed   = 0 ;
                    105:                pbmi->argbColor[1].bBlue  = 0xFF ;
                    106:                pbmi->argbColor[1].bGreen = 0xFF ;
                    107:                pbmi->argbColor[1].bRed   = 0xFF ;
                    108: 
                    109:                GpiSetBitmapBits (hpsMemory, 0L, 32L, abBitCat, pbmi) ;
                    110: 
                    111:                free (pbmi) ;
                    112:                return 0 ;
                    113: 
                    114:           case WM_SIZE:
                    115:                cxClient = SHORT1FROMMP (mp2) ;
                    116:                cyClient = SHORT2FROMMP (mp2) ;
                    117:                return 0 ;
                    118: 
                    119:           case WM_PAINT:
                    120:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                    121: 
                    122:                aptl[0].x = 0 ;                    // target lower left
                    123:                aptl[0].y = 0 ;
                    124: 
                    125:                aptl[1].x = cxClient ;             // target upper right
                    126:                aptl[1].y = cyClient ;
                    127: 
                    128:                aptl[2].x = 0 ;                    // source lower left
                    129:                aptl[2].y = 0 ;
                    130: 
                    131:                aptl[3].x = 32 ;                   // source upper right
                    132:                aptl[3].y = 32 ;
                    133: 
                    134:                GpiBitBlt (hps, hpsMemory, 4L, aptl, ROP_SRCCOPY, BBO_AND) ;
                    135: 
                    136:                aptl[1] = aptl[3] ;                // target upper right
                    137: 
                    138:                GpiBitBlt (hps, hpsMemory, 3L, aptl, ROP_SRCCOPY, BBO_AND) ;
                    139: 
                    140:                WinEndPaint (hps) ;
                    141:                return 0 ;
                    142: 
                    143:           case WM_DESTROY:
                    144:                GpiDestroyPS (hpsMemory) ;
                    145:                DevCloseDC (hdcMemory) ;
                    146:                GpiDeleteBitmap (hbm) ;
                    147:                return 0 ;
                    148:           }
                    149:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    150:      }

unix.superglobalmegacorp.com

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