Dcb: C/C++ Version

/****************************************************************************\
*                                                                            *
*  Dcb.c                                                                     *
*                                                                            *
*  This program demonstrates the Fastgraph for Windows direct color bitmap   *
*  display functions.                                                        *
*                                                                            *
\****************************************************************************/
#include 
#include "Dcb.h"
#define vbWidth  320
#define vbHeight 240
// 40x20 high color bitmapped image of a bird
WORD Bird[] = {
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0821,0x0821,0x0000,0x0821,0x0000,0x0821,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0821,0xFFFF,0x0821,0xAD55,0x0821,0xAD55,0x0821,0x0821,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0821,0xFFFF,0xFFFF,0x0821,0xAD55,0x0821,0xAD55,0x0821,0xFFFF,
   0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0x0821,0xFFFF,0xFFFF,
   0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0x0821,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0x0821,0xFFFF,0x0821,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0xFFFF,0xFFFF,0xFFFF,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,
   0x0000,0x0000,0x0821,0x0821,0x0821,0x0821,0x0821,0xAD55,0x0821,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0xFFFF,0xFFFF,0x0821,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,
   0x0000,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0821,0xFFFF,0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0x0821,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0821,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0821,0xFFFF,0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0821,0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,
   0x0821,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0821,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0821,0x0821,0x0821,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0821,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,
   0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0821,0xAD55,0xAD55,0xAD55,0xAD55,0x0821,0x0821,0x0821,0x0821,0x0000,
   0x0821,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0x0821,
   0x0821,0x0821,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0821,0xAD55,0xAD55,0xAD55,0xAD55,0xAD55,0xAD55,0xAD55,0x0821,
   0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xFFFF,0xFFFF,0xFFFF,0x0821,0xAD55,
   0xAD55,0xAD55,0xAD55,0x0821,0x0821,0x0821,0x0821,0x0821,0x0821,0x0000,
   0x0000,0x0000,0x0821,0x0821,0x0821,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0xA800,0xA800,0x0821,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0x0821,0x0821,
   0x0821,0x0821,0x0821,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xA800,0xFFFF,0xFFFF,0x0821,0x0821,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
   0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0821,0x0821,
   0x0821,0xFFFF,0xFFFF,0xFFFF,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0821,0x0821,0x0821,0x0821,
   0x0821,0x0821,0x0821,0x0821,0x0821,0x0821,0x0821,0x0000,0x0000,0x0000,
   0x0000,0x0821,0x0821,0x0821,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdParam, int iCmdShow)
{
   static char szAppName[] = "FGdcb";
   HWND        hWnd;
   MSG         msg;
   WNDCLASSEX  wndclass;
   wndclass.cbSize        = sizeof(wndclass);
   wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
   wndclass.lpfnWndProc   = WindowProc;
   wndclass.cbClsExtra    = 0;
   wndclass.cbWndExtra    = 0;
   wndclass.hInstance     = hInstance;
   wndclass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
   wndclass.hCursor       = LoadCursor(NULL,IDC_ARROW);
   wndclass.hbrBackground = NULL;
   wndclass.lpszMenuName  = szAppName;
   wndclass.lpszClassName = szAppName;
   wndclass.hIconSm       = LoadIcon(NULL,IDI_APPLICATION);
   RegisterClassEx(&wndclass);
   hWnd = CreateWindow(szAppName, // window class name
      "Direct Color Bitmap Demo", // window caption
      WS_OVERLAPPEDWINDOW,     // window style
      CW_USEDEFAULT,           // initial x position
      CW_USEDEFAULT,           // initial y position
      CW_USEDEFAULT,           // initial x size
      CW_USEDEFAULT,           // initial y size
      NULL,                    // parent window handle
      NULL,                    // window menu handle
      hInstance,               // program instance handle
      NULL);                   // creation parameters
   ShowWindow(hWnd,iCmdShow);
   UpdateWindow(hWnd);
   while (GetMessage(&msg,NULL,0,0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
   return msg.wParam;
}
/****************************************************************************\
*                                                                            *
*  WindowProc()                                                              *
*                                                                            *
\****************************************************************************/
HDC      hDC;
HPALETTE hPal;
int      hVB;
UINT     cxClient, cyClient;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
   PAINTSTRUCT ps;
   switch (iMsg)
   {
      case WM_CREATE:
         hDC = GetDC(hWnd);
         fg_setdc(hDC);
         hPal = fg_defpal();
         fg_realize(hPal);
         fg_vbinit();
         fg_vbdepth(16);
         hVB = fg_vballoc(vbWidth,vbHeight);
         fg_vbopen(hVB);
         fg_vbcolors();
         fg_setcolorrgb(85,255,85);
         fg_fillpage();
         return 0;
      case WM_COMMAND:
         switch (wParam)
         {
            case IDM_DrawDCB:
               fg_fillpage();
               fg_move(vbWidth/2-20,vbHeight/2+10);
               fg_drawdcb(Bird,40,20);
               fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
               return 0;
            case IDM_ClipDCB:
               fg_fillpage();
               fg_move(-20,vbHeight/2+10);
               fg_clipdcb(Bird,40,20);
               fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
               return 0;
            case IDM_RevDCB:
               fg_fillpage();
               fg_move(vbWidth/2-20,vbHeight/2+10);
               fg_revdcb(Bird,40,20);
               fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
               return 0;
            case IDM_FlipDCB:
               fg_fillpage();
               fg_move(vbWidth-20,vbHeight/2+10);
               fg_flipdcb(Bird,40,20);
               fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
               return 0;
            case IDM_PutDCB:
               fg_fillpage();
               fg_move(vbWidth/2-20,vbHeight/2+10);
               fg_putdcb(Bird,40,20);
               fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
               return 0;
            case IDM_Exit:
               DestroyWindow(hWnd);
               return 0;
         }
         break;
      case WM_PAINT:
         BeginPaint(hWnd,&ps);
         fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
         EndPaint(hWnd,&ps);
         return 0;
      case WM_SETFOCUS:
         fg_realize(hPal);
         InvalidateRect(hWnd,NULL,TRUE);
         return 0;
      case WM_SIZE:
         cxClient = LOWORD(lParam);
         cyClient = HIWORD(lParam);
         return 0;
      case WM_DESTROY:
         fg_vbclose();
         fg_vbfree(hVB);
         fg_vbfin();
         DeleteObject(hPal);
         ReleaseDC(hWnd,hDC);
         PostQuitMessage(0);
         return 0;
   }
   return DefWindowProc(hWnd,iMsg,wParam,lParam);
}

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.