Maintaining a Device ContextAll writing to a window's client area is performed through a Windows device context, or DC for short. The Windows API function GetDC() obtains a device context (in Visual Basic, we just use the hDC property), and the function fg_setdc() tells Fastgraph about it. These functions typically appear in the WM_CREATE section of the window procedure, as shown here. If a Fastgraph program does not call fg_setdc(), calls to fg_vbpaste() and fg_vbscale() will not work.
C/C++:
C++Builder:
Delphi:
Visual Basic:
The WM_DESTROY handler should then use the Windows API function ReleaseDC() to release the device context:
C/C++:
C++Builder:
Delphi:
In C/C++ programs, the device context returned by GetDC() cannot be stored in a local variable (unless declared static), as it must retain its value across window procedure calls. Visual Basic programs don't need to release the device context, since that's handled automatically. The C/C++, MFC, and PowerBASIC versions of the Fastgraph example programs all specify the CS_OWNDC style flag when setting up the window class. This flag tells Windows to assign a unique device context to each window, and further guarantees that Windows will not reclaim any of our device contexts while the program executes. The C++Builder and Delphi versions do not do this, but we can specify CS_OWNDC in C++Builder and Delphi programs by overriding a form's CreateParams() method. To do this, we must add the following declaration to the form's class definition:
C++Builder:
Delphi:
Then add our CreateParams() function to the source code module where you define the form's event handlers:
C++Builder:
Delphi:
|
 
copyright 2001 Ted Gruber Software, Inc.