Creating an Empty Vector Handle and Attaching it to a Window

Take the following steps to start a project and to add some code that creates a new empty vector handle, and attaches it to a window.

Note:

This example is for a 32-bit (NT or Windows 9x) environment.

 

1.

Start Visual C++, version 4.2.

2.

Select the File->New menu option, and in the dialog box, select Project Workspace.

3.

In the New Project Workspace dialog box, enter the directory (c:\lead\examples\vector\tutorial), make sure to select Application (Win32 Application) as the project type,. Give the project the name "tutorial" and press Enter.

4.

Select the File->New menu option, and in the dialog box, select Text File and press Enter.

5.

Copy and paste the following code into the text file you have just created:

#include <windows.h>
#include "c:\lead14\dll\include\l_bitmap.h"
#include "c:\lead14\dll\include\lvkrn.h"

static L_VOID ResetView( HWND hWnd, pVECTORHANDLE pVector )
{
   // let the vector toolkit calculates the extent of the current drawing.
   L_VecSetParallelogram ( pVector, NULL, NULL );

   // let the vector toolkits calculates the origin of current drawing.
   L_VecSetOrigin ( pVector, NULL );

   // let the vector toolkits calculates the default camera position (top-view)
   L_VecSetCamera ( pVector, NULL );

   // cause a redraw of our main window
   InvalidateRect( hWnd, NULL, FALSE );
}

static LRESULT WINAPI WndProc( HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam )
{
   static VECTORHANDLE Vector;  // our vector handle
   RECT Rect;
   PAINTSTRUCT PaintStruct;
   HDC hDC;

   switch( uMessage )
   {
      case WM_CREATE:
         // initiates the vector handle
         L_VecInit ( &Vector );

         // set wireframe mode
         L_VecSetPolygonMode ( &Vector, VECTOR_POLYGON_LINE );

         // attach it to the main window
         L_VecAttachToWindow ( hWnd, &Vector, VECTOR_ENGINE_GDI, VECTOR_ENGINE_DOUBLEBUFFER );

         // set default view
         ResetView( hWnd, &Vector );
         return 0L;

      case WM_SIZE:
         // set the vector viewport to all client area
         GetClientRect( hWnd, &Rect );
         L_VecSetViewport ( &Vector, &Rect );
         return 0L;

      case WM_PAINT:
         // draw the vector
         hDC = BeginPaint( hWnd, &PaintStruct );
         L_VecPaint ( hDC, &Vector, TRUE );
         EndPaint( hWnd, &PaintStruct );
         return 0L;

      case WM_DESTROY:
         // free the vector handle
         L_VecFree ( &Vector );
         PostQuitMessage( 0 );
         return 0L;

      default:
         break;
   }

   return DefWindowProc( hWnd, uMessage, wParam, lParam );
}

L_INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE hInstPrev, LPTSTR pCmdLine, L_INT nCmdShow )
{
   const L_TCHAR szClassName[] = TEXT("lead_vector_tutorial");
   WNDCLASSEX WndClass;
   HWND hWnd;
   MSG Msg;

   UNREFERENCED_PARAMETER( hInstPrev );
   UNREFERENCED_PARAMETER( pCmdLine );

   // unlock vector support
   L_UnlockSupport ( L_SUPPORT_VECTOR, L_KEY_VECTOR );

   WndClass.cbSize = sizeof( WNDCLASSEX );
   WndClass.style = CS_HREDRAW | CS_VREDRAW;
   WndClass.lpfnWndProc = WndProc;
   WndClass.cbClsExtra = 0;
   WndClass.cbWndExtra = 0;
   WndClass.hInstance = hInst;
   WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
   WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
   WndClass.hbrBackground = NULL;
   WndClass.lpszMenuName = NULL;
   WndClass.lpszClassName = szClassName;
   WndClass.hIconSm = NULL;

   RegisterClassEx( &WndClass );

   hWnd = CreateWindowEx( 0L, szClassName, TEXT("Vector Tutorial"), WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
                          NULL, NULL, hInst, NULL );

   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );

   while( GetMessage( &Msg, NULL, 0, 0 ) != 0 )
   {
      TranslateMessage( &Msg );
      DispatchMessage( &Msg );
   }

   UnregisterClass( szClassName, hInst );

   return Msg.wParam;
}

6.

Select File->Save from the menu and give the text file the name "vectut.c"

7.

Select Insert->Files into Project from the menu . In the dialog box that appears, browse to the vectut.c file you have just created, select it and click Add.

8.

Select Insert->Files into Project from the menu In the dialog box that appears, browse to c:\lead\lib\ltkrn_n.lib, select it and click Add.

9.

Select Insert->Files into Project from the menu . In the dialog box that appears, browse to c:\lead\lib\lvkrn_n.lib, select it and click Add.

10.

Compile and run the project by selecting Build->Execute vectut.exe from the menu.

11.

The program should display a white background drawn by the vector handle.