home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------
- // GENERIC.C
- //-------------------------------------------------------
- // Contains code for Generic VBX control.
- //
- // Use the following files as templates for building your
- // own VBX control:
- //
- // - GENERIC.C (this file)
- // - GENERIC.H
- // - GENERIC.DEF
- // - GENERIC.RC
- //-------------------------------------------------------
-
- #include <windows.h>
- #include "vbapi.h"
- #include "GENERIC.H"
-
- //------------------------------------------------------
- // Global Variables
- //------------------------------------------------------
- HANDLE hmodDLL;
-
-
- //------------------------------------------------------
- // Local Prototypes
- //------------------------------------------------------
- VOID NEAR DrawTheControl(HCTL hctl, HWND hwnd, HDC hdc);
-
-
- //------------------------------------------------------
- // Generic Control Procedure
- //------------------------------------------------------
- LONG FAR PASCAL _export GenericCtlProc
- (
- HCTL hctl,
- HWND hwnd,
- USHORT msg,
- USHORT wp,
- LONG lp
- )
- {
-
- // Process messages of the VBX control.
- switch (msg)
- {
- case WM_NCCREATE:
-
- // TODO: Add initialization code here
-
-
- break;
-
- case WM_PAINT:
-
- // Note: Write the control drawing code
- // inside the function DrawTheControl().
-
- if (wp)
- DrawTheControl(hctl, hwnd, (HDC)wp);
- else
- {
- PAINTSTRUCT ps;
- BeginPaint(hwnd, &ps);
- DrawTheControl(hctl, hwnd, ps.hdc);
- EndPaint(hwnd, &ps);
- }
-
- break;
-
-
- case VBM_SETPROPERTY:
-
- // NOTE: wp = Property that was just changed.
- // lp = New value of the property.
-
- switch (wp)
- {
- // TODO: Add a case for each custom property
-
- }
-
- break;
-
- case WM_TIMER:
- {
- // TODO: Add timer code here
-
-
-
- break;
- }
-
-
- // TODO: Add cases for other events here
-
-
- }
-
-
- return VBDefControlProc(hctl, hwnd, msg, wp, lp);
- }
-
-
- //------------------------------------------------------
- // Initialize library. This routine is called when the
- // first client loads the DLL.
- //------------------------------------------------------
- int FAR PASCAL LibMain
- (
- HANDLE hModule,
- WORD wDataSeg,
- WORD cbHeapSize,
- LPSTR lpszCmdLine
- )
- {
- // Avoid warnings on unused formal parameters
- wDataSeg = wDataSeg;
- cbHeapSize = cbHeapSize;
- lpszCmdLine = lpszCmdLine;
-
- hmodDLL = hModule;
-
- return 1;
- }
-
-
- //------------------------------------------------------
- // Register custom control. This routine is called by VB
- // when the custom control DLL is loaded for use.
- //------------------------------------------------------
- BOOL FAR PASCAL _export VBINITCC
- (
- USHORT usVersion,
- BOOL fRuntime
- )
- {
- // Avoid warnings on unused formal parameters
- fRuntime = fRuntime;
- usVersion = usVersion;
-
- // Register control(s)
- return VBRegisterModel(hmodDLL, &modelGeneric);
- }
-
-
- //------------------------------------------------------
- // WEP
- //------------------------------------------------------
- // C7 and QCWIN provide default WEP:
- //------------------------------------------------------
- #if (_MSC_VER < 610)
-
- int FAR PASCAL WEP(int fSystemExit);
-
- //------------------------------------------------------
- // For Windows 3.0 it is recommended that the WEP
- // function reside in a FIXED code segment and be
- // exported as RESIDENTNAME. This is accomplished
- // using the alloc_text pragma below and the related
- // EXPORTS and SEGMENTS directives in the .DEF file.
- //
- // Read the comments section documenting the WEP
- // function in the Windows 3.1 SDK "Programmers
- // Reference, Volume 2: Functions" before placing
- // any additional code in the WEP routine for a
- // Windows 3.0 DLL.
- //------------------------------------------------------
- #pragma alloc_text(WEP_TEXT,WEP)
-
- //------------------------------------------------------
- // Performs cleanup tasks when the DLL is unloaded.
- // WEP() is called automatically by Windows when the DLL
- // is unloaded (no remaining tasks still have the DLL
- // loaded). It is strongly recommended that a DLL have a
- // WEP() function, even if it does nothing but returns
- // success (1), as in this example.
- //------------------------------------------------------
- int FAR PASCAL WEP
- (
- int fSystemExit
- )
- {
- // Avoid warnings on unused formal parameters
- fSystemExit = fSystemExit;
-
- return 1;
- }
- #endif // C6
-
- //------------------------------------------------------
-
- //------------------------------------------------------
- // Draw inside the control.
- //------------------------------------------------------
- VOID NEAR DrawTheControl
- (
- HCTL hctl,
- HWND hwnd,
- HDC hdc
- )
- {
- // Variables for the brush.
- HBRUSH hbr;
- HBRUSH hbrOld = NULL;
-
- // TODO: Define your own local variables here (if any)
-
-
-
-
- // Select new brush, and save old brush.
- hbr = (HBRUSH)SendMessage(GetParent(hwnd),
- WM_CTLCOLOR, hdc, MAKELONG(hwnd,0));
- if (hbr)
- hbrOld = SelectObject(hdc, hbr);
-
-
- // TODO: Add your drawing code here
-
-
-
-
-
-
-
- // Restore the old brush
- if (hbrOld)
- SelectObject(hdc, hbrOld);
-
- }
-
-