home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------
- // MYCLOCK.C
- //-------------------------------------------------------
- // Contains code for Myclock VBX control.
- //
- // Use the following files as templates for building your
- // own VBX control:
- //
- // - MYCLOCK.C (this file)
- // - MYCLOCK.H
- // - MYCLOCK.DEF
- // - MYCLOCK.RC
- //-------------------------------------------------------
-
- #include <windows.h>
- #include "vbapi.h"
- #include "MYCLOCK.H"
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- #include <time.h>
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- //------------------------------------------------------
- // Global Variables
- //------------------------------------------------------
- HANDLE hmodDLL;
-
-
- //------------------------------------------------------
- // Local Prototypes
- //------------------------------------------------------
- VOID NEAR DrawTheControl(HCTL hctl, HWND hwnd, HDC hdc);
-
-
- //------------------------------------------------------
- // Myclock Control Procedure
- //------------------------------------------------------
- LONG FAR PASCAL _export MyclockCtlProc
- (
- 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
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Install a timer.
- SetTimer(hwnd,1,1000,NULL);
-
- // Set the BackColor property to 65280 (Green).
- VBSetControlProperty(hctl,
- IPROP_MYCLOCK_BACKCOLOR,
- 65280L);
-
- // Set the UpdateInterval property to 1000
- pMYCLOCK(hctl)->UpdateInterval = 1000;
-
- ////////////////////
- // MY CODE ENDS 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
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- case IPROP_MYCLOCK_UPDATEINTERVAL:
-
- // Set the UpdateInterval property with
- // the new value.
- pMYCLOCK(hctl)->UpdateInterval = (SHORT)lp;
-
- // Set the timer with the new value.
- SetTimer(hwnd,
- 1,
- pMYCLOCK(hctl)->UpdateInterval,
- NULL);
-
- return 0;
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- break;
-
- case WM_TIMER:
- {
- // TODO: Add timer code here
-
- ///////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Draw the control.
- HDC hdc = GetDC(hwnd);
- DrawTheControl(hctl, hwnd, hdc);
- ReleaseDC(hwnd,hdc);
-
- ///////////////////////
- // MY CODE STARTS 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, &modelMyclock);
- }
-
-
- //------------------------------------------------------
- // 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)
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- char CurrentTime[30];
- struct tm *newtime;
- long lTime;
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- // 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
-
- ///////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Get the current time
- time(&lTime);
- newtime=localtime(&lTime);
-
- // Convert the time into a string.
- strcpy(CurrentTime, asctime(newtime));
-
- // Pad the string with 5 blanks
- CurrentTime[24]=' ';
- CurrentTime[25]=' ';
- CurrentTime[26]=' ';
- CurrentTime[27]=' ';
- CurrentTime[28]=' ';
-
- // Display the current time
- TextOut(hdc, 0, 0, CurrentTime, 29);
-
- // If a new minute has just begun, fire the NEWMINUTE event.
- if (newtime->tm_sec==0)
- VBFireEvent(hctl, IEVENT_MYCLOCK_NEWMINUTE, NULL);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- // Restore the old brush
- if (hbrOld)
- SelectObject(hdc, hbrOld);
-
- }
-
-