The following example demonstrates how to embed an instance of the Microsoft Calendar Control using my Ole Container (OLECON.INC).
' ########################################################################################
' Demonstrates how to create an instance of the Microsoft Calendar Control.
' ########################################################################################
' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "MSCAL.INC"
#INCLUDE "OLECON.INC"
%IDC_MSCAL = 1001
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL hWndMain AS DWORD
LOCAL hFont AS DWORD
LOCAL wcex AS WNDCLASSEX
LOCAL szClassName AS ASCIIZ * 80
LOCAL rc AS RECT
LOCAL szCaption AS ASCIIZ * 255
LOCAL nLeft AS LONG
LOCAL nTop AS LONG
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
' Required: Initialize the Ole Container
OC_WinInit
hFont = GetStockObject(%ANSI_VAR_FONT)
' Register the window class
szClassName = "MSCAL"
wcex.cbSize = SIZEOF(wcex)
wcex.style = %CS_HREDRAW OR %CS_VREDRAW
wcex.lpfnWndProc = CODEPTR(WndProc)
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
wcex.hCursor = LoadCursor (%NULL, BYVAL %IDC_ARROW)
wcex.hbrBackground = %COLOR_3DFACE + 1
wcex.lpszMenuName = %NULL
wcex.lpszClassName = VARPTR(szClassName)
wcex.hIcon = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
wcex.hIconSm = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
RegisterClassEx wcex
' Window caption
szCaption = "Microsoft Calendar Control"
' Retrieve the size of the working area
SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0
' Calculate the position and size of the window
nWidth = (((rc.nRight - rc.nLeft)) + 2) * 0.75 ' 75% of the client screen width
nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.70 ' 70% of the client screen height
nLeft = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
nTop = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)
' Create a window using the registered class
hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _ ' extended style
szClassName, _ ' window class name
szCaption, _ ' window caption
%WS_OVERLAPPEDWINDOW OR _
%WS_CLIPCHILDREN, _ ' window style
nLeft, _ ' initial x position
nTop, _ ' initial y position
nWidth, _ ' initial x size
nHeight, _ ' initial y size
%NULL, _ ' parent window handle
0, _ ' window menu handle
hInstance, _ ' program instance handle
BYVAL %NULL) ' creation parameters
' Show the window
ShowWindow hWndMain, nCmdShow
UpdateWindow hWndMain
' Message handler loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
IF IsDialogMessage(hWndMain, uMsg) = 0 THEN
TranslateMessage uMsg
DispatchMessage uMsg
END IF
END IF
WEND
FUNCTION = uMsg.wParam
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL rc AS RECT
LOCAL hCtl AS DWORD
LOCAL hr AS DWORD
LOCAL pCal AS MSCAL_ICalendar
STATIC pCalEvents AS DCalendarEventsImpl
SELECT CASE wMsg
CASE %WM_SYSCOMMAND
' Capture this message and send a %WM_CLOSE message
IF (wParam AND &HFFF0) = %SC_CLOSE THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE %WM_CREATE
' Create the ShockWaveFlash window container
hCtl = CreateWindowEx(0, $OC_CLASSNAME, "MSCAL.Calendar", %WS_CHILD OR %WS_VISIBLE, _
0, 0, 0, 0, hWnd, %IDC_MSCAL, GetModuleHandle(""), BYVAL %NULL)
SetFocus hCtl
' Get the IDispatch of the control
pCal = OC_GetDispatch(hCtl)
IF ISOBJECT(pCal) THEN
' Connect events
pCalEvents = CLASS "CDCalendarEvents"
IF ISOBJECT(pCalEvents) THEN EVENTS FROM pCal CALL pCalEvents
' Release the interface
pCal = NOTHING
END IF
CASE %WM_SIZE
IF wParam <> %SIZE_MINIMIZED THEN
GetClientRect hWnd, rc
MoveWindow GetDlgItem(hWnd, %IDC_MSCAL), 10, 10, (rc.nRight - rc.nLeft) - 20, (rc.nBottom - rc.nTop) - 20, %TRUE
END IF
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_DESTROY
IF ISOBJECT(pCalEvents) THEN EVENTS END pCalEvents
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
' ########################################################################################
' Class CDCalendarEvents
' Interface name = DCalendarEvents
' IID = {8E27C92D-1264-101C-8A2F-040224009C02}
' Event interface for Calendar control
' Attributes = 4112 [&H1010] [Hidden] [Dispatchable]
' ########################################################################################
CLASS CDCalendarEvents GUID$("{D4A44440-33A2-4A55-B0AB-30D70B127E3C}") AS EVENT
INTERFACE DCalendarEventsImpl GUID$("{8E27C92D-1264-101C-8A2F-040224009C02}") AS EVENT
INHERIT IDispatch
' =====================================================================================
METHOD Click <-600>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD DblClick <-601>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD KeyDown <-602> ( _
BYREF KeyCode AS INTEGER _ ' *KeyCode VT_I2 <Integer>
, BYVAL iShift AS INTEGER _ ' Shift VT_I2 <Integer>
) ' VOID
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD KeyPress <-603> ( _
BYREF KeyAscii AS INTEGER _ ' *KeyAscii VT_I2 <Integer>
) ' VOID
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD KeyUp <-604> ( _
BYREF KeyCode AS INTEGER _ ' *KeyCode VT_I2 <Integer>
, BYVAL iShift AS INTEGER _ ' Shift VT_I2 <Integer>
) ' VOID
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD BeforeUpdate <2> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' VOID
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD AfterUpdate <1>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NewMonth <3>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NewYear <4>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
END INTERFACE
END CLASS