First: Visual BasicVisual Basic programs consist of a project (vbp) file and one or more source code form (frm) files. The project file defines the forms and modules used in the program. All Fastgraph Visual Basic projects must include either Fastgraph's native module (FGWin.bas) or DirectX module (FGWinD.bas). Form files include the program's functions, sub procedures, and event handlers. Visual Basic automatically takes care of many of the traditional Windows programming details such as setting up the window class, the window procedure, and the message loop. Here is the Visual Basic form file for our first example program:
The form for our first example simply consists of event-handling procedures that provide our first look at some Fastgraph functions. Note that our program does not explicitly call these procedures. Instead, they are called by Visual Basic in response to Windows events such as creating or resizing the window (the event-handling procedures are analogous to the traditional WindowProc() message handlers). Our program includes event handlers for the form's activate, load, paint, resize, and destroy events. A load event occurs when the form is first created during program execution. This event occurs once per program instance and is analogous to the WM_CREATE Windows message. Hence, it is a good place for any application-specific initialization code. Our load event procedure is in the Form_Load() Sub procedure:
Form_Load() first sets the ScaleMode property to 3 (units=pixels), which Fastgraph needs to update the form's client area properly. It then calls fg_setdc() to make the form's device context (obtained with the hDC property) available to other Fastgraph functions. Next, Form_Load() creates the default logical palette with fg_defpal() and realizes the palette with fg_realize(). It then initializes Fastgraph's virtual buffer environment, creates a 640x480 virtual buffer and makes it the active virtual buffer, and assigns the logical palette colors to the virtual buffer. Finally, Form_Load() fills the virtual buffer with blue pixels (color 19 is blue when using Fastgraph's default 256-color virtual buffers with the default logical palette). An activate event occurs when the form gains the input focus. This happens when control shifts from another Windows application to our program, so it is analogous to the WM_SETFOCUS Windows message. Our activate event procedure is in the Form_Activate() Sub procedure:
Form_Activate() first calls fg_realize() to activate the program's logical palette (in case another program has changed the logical palette colors). It then uses the Refresh method to force a paint event to redraw the form's client area. This sequence is typical of activate event procedures in Fastgraph programs. A paint event occurs when the form's client area must be repainted; it is analogous to the WM_PAINT Windows message. Our paint event procedure is in the Form_Paint() Sub procedure:
Form_Paint() just calls fg_vbscale() to display the 640x480 virtual buffer scaled to the size of the form's client area. This sequence is typical of paint event procedures in Fastgraph programs. A resize event occurs whenever the size of the form changes, and also upon creation of a form. It is analogous to the WM_SIZE Windows message. Our resize event procedure is in the Form_Resize() Sub procedure:
Form_Resize() first saves the new width and height of the client area (in pixels) in the variables cxClient and cyClient. These quantities are passed to fg_vbscale() in Form_Paint(). It then uses the Refresh method to generate a paint event that updates the resized form. An unload event occurs after removing a form and often signals a program exit; it is analogous to the WM_DESTROY Windows message. Our unload event procedure is in the Form_Unload() Sub procedure:
Form_Unload() calls fg_vbclose() to close the virtual buffer, fg_vbfree() to release its memory, and fg_vbfin() to terminate virtual buffer processing.
|
 
copyright 2001 Ted Gruber Software, Inc.