FGFW1: C/C++ Version


/****************************************************************************\
*                                                                            *
*  FGFW1.c                                                                   *
*                                                                            *
*  Demonstrate the basic Fastgraph/Fonts for Windows operations of font      *
*  loading, character display and justification, and font unloading.         *
*                                                                            *
\****************************************************************************/
#include 
#include 
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdParam, int iCmdShow)
{
   static char szAppName[] = "FGFW1";
   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  = NULL;
   wndclass.lpszClassName = szAppName;
   wndclass.hIconSm       = LoadIcon(NULL,IDI_APPLICATION);
   RegisterClassEx(&wndclass);
   hWnd = CreateWindow(
      szAppName,             // window class name
      "Example FGFW1",       // 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;
   int xMax, yMax, xMid, yMid;
   switch (iMsg)
   {
      case WM_CREATE:
         hDC = GetDC(hWnd);
         fg_setdc(hDC);
         hPal = fg_defpal();
         fg_realize(hPal);
         fg_vbinit();
         hVB = fg_vballoc(640,480);
         fg_vbopen(hVB);
         fg_vbcolors();
         if (fgf_load("AUSTIN36.FGF") == 0)
         {
            MessageBox(hWnd,"Unable to load font file.","Error",
                       MB_ICONSTOP|MB_OK);
            DestroyWindow(hWnd);
            return 0;
         }
         xMax = fg_getmaxx();
         yMax = fg_getmaxy();
         xMid = xMax / 2;
         yMid = yMax / 2;
         fg_setcolor(255);
         fg_fillpage();
         fg_setcolor(19);
         fg_move(0,0);
         fgf_justify(-1,1);
         fgf_print("FG/Fonts",8);
         fg_move(xMid,0);
         fgf_justify(0,1);
         fgf_print("FG/Fonts",8);
         fg_move(xMax,0);
         fgf_justify(1,1);
         fgf_print("FG/Fonts",8);
         fg_move(0,yMid);
         fgf_justify(-1,0);
         fgf_print("FG/Fonts",8);
         fg_move(xMid,yMid);
         fgf_justify(0,0);
         fgf_print("FG/Fonts",8);
         fg_move(xMax,yMid);
         fgf_justify(1,0);
         fgf_print("FG/Fonts",8);
         fg_move(0,yMax);
         fgf_justify(-1,-1);
         fgf_print("FG/Fonts",8);
         fg_move(xMid,yMax);
         fgf_justify(0,-1);
         fgf_print("FG/Fonts",8);
         fg_move(xMax,yMax);
         fgf_justify(1,-1);
         fgf_print("FG/Fonts",8);
         return 0;
      case WM_PAINT:
         BeginPaint(hWnd,&ps);
         fg_vbscale(0,fg_getmaxx(),0,fg_getmaxy(),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:
         fgf_unload(-1);
         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.