• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Hosting ActiveX Controls using PBFORMS

Started by José Roca, August 30, 2011, 10:35:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
With the help of my OLE Container and Windows API Headers, you can use ActiveX controls with the PB IDE and PBForms.

First you have to download my translation of the Windows API headers, available at http://www.jose.it-berater.org/smfforum/index.php?board=344.0, and unzip them in a folder of your choice.

Then copy the file PBFORMS.INC from the WINAPI folder of the compiler to the folder where you have unzipped my Windows API headers.

Finally, replace the PB Include path in the PB IDE from "C:\PBWIN90\WINAPI" with the path of the folder where you have unzipped my Windows API headers. Both paths can't coexist because if the old headers are mixed with the new ones you will get errors at compile time.

To host an ActiveX control in your DDT dialog, add a Custom Control:



and use OC_WIN32 as the name of the class, and the ProgID of the ActiveX control as the caption (it can include the license key if the control is licensed).



In the example, using "MSComCtl2.MonthView.2;RTLKEY:651A8940-87C5-11d1-8BE3-0000F8754DA1" as the caption ("MSComCtl2.MonthView.2" is the ProgID of the MonthView control and "651A8940-87C5-11d1-8BE3-0000F8754DA1" the license key), PBFORMS will generate the following code:


#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly.  See the PB/Forms documentation for
' more information.
' Named blocks begin like this:    #PBFORMS BEGIN ...
' Named blocks end like this:      #PBFORMS END ...
' Other PB/Forms metastatements such as:
'     #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------

#COMPILE EXE
#DIM ALL

'------------------------------------------------------------------------------
'   ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1         =  101
%IDC_CUSTOMCONTROL_1 = 1001
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
    ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()

    SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
            ' Initialization handler

        CASE %WM_NCACTIVATE
            STATIC hWndSaveFocus AS DWORD
            IF ISFALSE CBWPARAM THEN
                ' Save control focus
                hWndSaveFocus = GetFocus()
            ELSEIF hWndSaveFocus THEN
                ' Restore control focus
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
            END IF

        CASE %WM_COMMAND
            ' Process control notifications
            SELECT CASE AS LONG CBCTL
                CASE %IDC_CUSTOMCONTROL_1

            END SELECT
    END SELECT
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "MonthView Control Demo", 70, 70, 350, 200, _
        %WS_OVERLAPPED OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
        %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR _
        %DS_MODALFRAME OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    CONTROL ADD "OC_WIN32", hDlg, %IDC_CUSTOMCONTROL_1, _
        "MSComCtl2.MonthView.2;RTLKEY:651A8940-87C5-11d1-8BE3-0000F8754DA1", _
        0, 0, 350, 200, %WS_CHILD OR %WS_VISIBLE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
#PBFORMS END DIALOG

    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------


Now you need to add the following include files:


#INCLUDE ONCE "OLECON.INC"     ' OLE Container
#INCLUDE ONCE "MSCOMCT2.INC"   ' Microsoft Windows Common Controls-2


And add the following statement at the beginning of PBMAIN:


OC_WinInit   ' Required: Initialize the OLE Container


Full code


#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly.  See the PB/Forms documentation for
' more information.
' Named blocks begin like this:    #PBFORMS BEGIN ...
' Named blocks end like this:      #PBFORMS END ...
' Other PB/Forms metastatements such as:
'     #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------

#COMPILE EXE
#DIM ALL

'------------------------------------------------------------------------------
'   ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
#INCLUDE ONCE "OLECON.INC"     ' OLE Container
#INCLUDE ONCE "MSCOMCT2.INC"   ' Microsoft Windows Common Controls-2
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1         =  101
%IDC_CUSTOMCONTROL_1 = 1001
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
    OC_WinInit   ' Required: Initialize the OLE Container
    ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()

    SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
            ' Initialization handler

        CASE %WM_NCACTIVATE
            STATIC hWndSaveFocus AS DWORD
            IF ISFALSE CBWPARAM THEN
                ' Save control focus
                hWndSaveFocus = GetFocus()
            ELSEIF hWndSaveFocus THEN
                ' Restore control focus
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
            END IF

        CASE %WM_COMMAND
            ' Process control notifications
            SELECT CASE AS LONG CBCTL
                CASE %IDC_CUSTOMCONTROL_1

            END SELECT
    END SELECT
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "MonthView Control Demo", 70, 70, 350, 200, _
        %WS_OVERLAPPED OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
        %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR _
        %DS_MODALFRAME OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    CONTROL ADD "OC_WIN32", hDlg, %IDC_CUSTOMCONTROL_1, _
        "MSComCtl2.MonthView.2;RTLKEY:651A8940-87C5-11d1-8BE3-0000F8754DA1", _
        0, 0, 350, 200, %WS_CHILD OR %WS_VISIBLE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
#PBFORMS END DIALOG

    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------


Run the example and this is the result:



José Roca

 
To give the control a chance to process keystrokes, we need to forward the window messages to the control, and for that we need a message pump. So we need to change:


DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt


to:


' We need to forward the messages to the control for keyboard handling
' and for that we need a message pump, so the dialog must be modeless.
DIALOG SHOW MODELESS hDlg, CALL ShowDIALOG1Proc TO lRslt

' Message handler loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
     IF IsDialogMessage(hDlg, uMsg) = 0 THEN
         TranslateMessage uMsg
         DispatchMessage uMsg
     END IF
END IF
WEND


and add the following code to the main dialog callback:


' --> Note: Both WM_SYSCOMMAND and WM_DESTROY are required with this control <--

CASE %WM_SYSCOMMAND
   ' Capture this message and send a %WM_CLOSE message,
   ' or the program may remain in memory
   IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
       DIALOG SEND CBHNDL, %WM_CLOSE, 0, 0
   END IF

CASE %WM_DESTROY
   PostQuitMessage 0


Full code:


#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly.  See the PB/Forms documentation for
' more information.
' Named blocks begin like this:    #PBFORMS BEGIN ...
' Named blocks end like this:      #PBFORMS END ...
' Other PB/Forms metastatements such as:
'     #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------

#COMPILE EXE
#DIM ALL

'------------------------------------------------------------------------------
'   ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
#INCLUDE ONCE "OLECON.INC"     ' OLE Container
#INCLUDE ONCE "MSCOMCT2.INC"   ' Microsoft Windows Common Controls-2
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1         =  101
%IDC_CUSTOMCONTROL_1 = 1001
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
    OC_WinInit   ' Required: Initialize the OLE Container
    ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()

    SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
            ' Initialization handler

        CASE %WM_NCACTIVATE
            STATIC hWndSaveFocus AS DWORD
            IF ISFALSE CBWPARAM THEN
                ' Save control focus
                hWndSaveFocus = GetFocus()
            ELSEIF hWndSaveFocus THEN
                ' Restore control focus
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
            END IF

        CASE %WM_COMMAND
            ' Process control notifications
            SELECT CASE AS LONG CBCTL
                CASE %IDC_CUSTOMCONTROL_1
                CASE %IDCANCEL
                   IF CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL, 0

            END SELECT

        ' --> Note: Both WM_SYSCOMMAND and WM_DESTROY are required with this control <--

        CASE %WM_SYSCOMMAND
            ' Capture this message and send a %WM_CLOSE message,
            ' or the program may remain in memory
            IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                DIALOG SEND CBHNDL, %WM_CLOSE, 0, 0
            END IF

        CASE %WM_DESTROY
            PostQuitMessage 0

    END SELECT
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "MonthView Control Demo", 70, 70, 350, 200, _
        %WS_OVERLAPPED OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
        %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR _
        %DS_MODALFRAME OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    CONTROL ADD "OC_WIN32", hDlg, %IDC_CUSTOMCONTROL_1, _
        "MSComCtl2.MonthView.2;RTLKEY:651A8940-87C5-11d1-8BE3-0000F8754DA1", _
        0, 0, 350, 200, %WS_CHILD OR %WS_VISIBLE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
#PBFORMS END DIALOG

    ' We need to forward the messages to the control for keyboard handling
    ' and for that we need a message pump, so the dialog must be modeless.
    DIALOG SHOW MODELESS hDlg, CALL ShowDIALOG1Proc TO lRslt

    ' Message handler loop
    LOCAL uMsg AS tagMsg
    WHILE GetMessage(uMsg, %NULL, 0, 0)
       IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
           IF IsDialogMessage(hDlg, uMsg) = 0 THEN
               TranslateMessage uMsg
               DispatchMessage uMsg
           END IF
       END IF
    WEND

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------


José Roca

 
The OC_GetDispatch function allows to retrieve a reference to the default interface of the control at any time giving the handle of window that hosts it. In the following example we are using it to sink to the events fired by the control. You can generate the events class with the help of my TypeLib Browser: http://www.jose.it-berater.org/smfforum/index.php?board=360.0


CASE %WM_INITDIALOG
   ' Initialization handler

   ' Get a pointer to the IMonthView interface
   CONTROL HANDLE CBHNDL, %IDC_CUSTOMCONTROL_1 TO hCtrl
   pMonthView = OC_GetDispatch(hCtrl)
   ' Connect events
   IF ISOBJECT(pMonthView) THEN
      pMonthViewEvents = CLASS "CDMonthViewEvents"
      IF ISOBJECT(pMonthViewEvents) THEN
         EVENTS FROM pMonthView CALL pMonthViewEvents
      END IF
      ' Release the interface
      pMonthView = NOTHING
   END IF


Full example:


#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly.  See the PB/Forms documentation for
' more information.
' Named blocks begin like this:    #PBFORMS BEGIN ...
' Named blocks end like this:      #PBFORMS END ...
' Other PB/Forms metastatements such as:
'     #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------

#COMPILE EXE
#DIM ALL

'------------------------------------------------------------------------------
'   ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
#INCLUDE ONCE "OLECON.INC"     ' OLE Container
#INCLUDE ONCE "MSCOMCT2.INC"   ' Microsoft Windows Common Controls-2
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1         =  101
%IDC_CUSTOMCONTROL_1 = 1001
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
    OC_WinInit   ' Required: Initialize the OLE Container
    ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()

    LOCAL  hCtrl            AS DWORD
    LOCAL  pMonthView       AS MSComCtl2_IMonthView
    STATIC pMonthViewEvents AS DMonthViewEventsImpl

    SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
            ' Initialization handler

            ' Get a pointer to the IMonthView interface
            CONTROL HANDLE CBHNDL, %IDC_CUSTOMCONTROL_1 TO hCtrl
            pMonthView = OC_GetDispatch(hCtrl)
            ' Connect events
            IF ISOBJECT(pMonthView) THEN
               pMonthViewEvents = CLASS "CDMonthViewEvents"
               IF ISOBJECT(pMonthViewEvents) THEN
                  EVENTS FROM pMonthView CALL pMonthViewEvents
               END IF
               ' Release the interface
               pMonthView = NOTHING
            END IF

        CASE %WM_NCACTIVATE
            STATIC hWndSaveFocus AS DWORD
            IF ISFALSE CBWPARAM THEN
                ' Save control focus
                hWndSaveFocus = GetFocus()
            ELSEIF hWndSaveFocus THEN
                ' Restore control focus
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
            END IF

        CASE %WM_COMMAND
            ' Process control notifications
            SELECT CASE AS LONG CBCTL
                CASE %IDC_CUSTOMCONTROL_1
                CASE %IDCANCEL
                   IF CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL, 0

            END SELECT

        ' --> Note: Both WM_SYSCOMMAND and WM_DESTROY are required with this control <--

        CASE %WM_SYSCOMMAND
            ' Capture this message and send a %WM_CLOSE message,
            ' or the program may remain in memory
            IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                DIALOG SEND CBHNDL, %WM_CLOSE, 0, 0
            END IF

        CASE %WM_DESTROY
            ' Disconnect events and quit
            IF ISOBJECT(pMonthViewEvents) THEN
                EVENTS END pMonthViewEvents
                pMonthViewEvents = NOTHING
            END IF
            PostQuitMessage 0

    END SELECT
END FUNCTION
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'   ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "MonthView Control Demo", 70, 70, 350, 200, _
        %WS_OVERLAPPED OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
        %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR _
        %DS_MODALFRAME OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    CONTROL ADD "OC_WIN32", hDlg, %IDC_CUSTOMCONTROL_1, _
        "MSComCtl2.MonthView.2;RTLKEY:651A8940-87C5-11d1-8BE3-0000F8754DA1", _
        0, 0, 350, 200, %WS_CHILD OR %WS_VISIBLE, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
#PBFORMS END DIALOG

    ' We need to forward the messages to the control for keyboard handling
    ' and for that we need a message pump, so the dialog must be modeless.
    DIALOG SHOW MODELESS hDlg, CALL ShowDIALOG1Proc TO lRslt

    ' Message handler loop
    LOCAL uMsg AS tagMsg
    WHILE GetMessage(uMsg, %NULL, 0, 0)
       IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
           IF IsDialogMessage(hDlg, uMsg) = 0 THEN
               TranslateMessage uMsg
               DispatchMessage uMsg
           END IF
       END IF
    WEND

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------


' ########################################################################################
' Class CDMonthViewEvents
' Interface name = DMonthViewEvents
' IID = {232E4569-87C3-11D1-8BE3-0000F8754DA1}
' Attributes = 4112 [&H1010] [Hidden] [Dispatchable]
' Code generated by the TypeLib Browser 4.0.10 (c) 2008 by José Roca
' Date: 10 sep 2008   Time: 18:58:10
' ########################################################################################

CLASS CDMonthViewEvents GUID$("{9F1994AC-39EB-4F7E-90B7-205B285F840F}") AS EVENT

INTERFACE DMonthViewEventsImpl GUID$("{232E4569-87C3-11D1-8BE3-0000F8754DA1}") AS EVENT

  INHERIT IDispatch

   ' =====================================================================================
   METHOD DateClick <1> ( _
     BYVAL DateClicked AS DOUBLE _                      ' __in Date DateClicked
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD DateDblClick <2> ( _
     BYVAL DateDblClicked AS DOUBLE _                   ' __in Date DateDblClicked
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD GetDayBold <3> ( _
     BYVAL StartDate AS DOUBLE _                        ' __in date StartDate
   , BYVAL iCount AS INTEGER _                          ' __in short Count
   , BYREF pState AS DWORD _                            ' __in_out SAFEARRAY *State
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD SelChange <4> ( _
     BYVAL StartDate AS DOUBLE _                        ' __in Date StartDate
   , BYVAL EndDate AS DOUBLE _                          ' __in Date EndDate
   , BYREF iCancel AS INTEGER _                         ' __out VARIANT_BOOL* Cancel
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD Click <-600>

     ' *** Insert your code here ***
     MSGBOX "Click"

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD DblClick <-601>

     ' *** Insert your code here ***
     ' Sample code
'     LOCAL hCtrl AS DWORD
'     hCtrl = GetFocus
'     MSGBOX "DblClick"
'     SetFocus hCtrl

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD KeyDown <-602> ( _
     BYREF KeyCode AS INTEGER _                         ' __in_out short* KeyCode
   , BYVAL iShift AS INTEGER _                          ' __in     short  Shift
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD KeyUp <-604> ( _
     BYREF KeyCode AS INTEGER _                         ' __in_out short* KeyCode
   , BYVAL iShift AS INTEGER _                          ' __in     short  Shift
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD KeyPress <-603> ( _
     BYREF KeyAscii AS INTEGER _                        ' __in_out short* KeyAscii
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD MouseDown <-605> ( _
     BYVAL iButton AS INTEGER _                         ' __in short Button
   , BYVAL iShift AS INTEGER _                          ' __in short Shift
   , BYVAL x AS LONG _                                  ' __in OLE_XPOS_PIXELS x
   , BYVAL y AS LONG _                                  ' __in OLE_YPOS_PIXELS y
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD MouseMove <-606> ( _
     BYVAL iButton AS INTEGER _                         ' __in short Button
   , BYVAL iShift AS INTEGER _                          ' __in short Shift
   , BYVAL x AS LONG _                                  ' __in OLE_XPOS_PIXELS x
   , BYVAL y AS LONG _                                  ' __in OLE_YPOS_PIXELS y
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD MouseUp <-607> ( _
     BYVAL iButton AS INTEGER _                         ' __in short Button
   , BYVAL iShift AS INTEGER _                          ' __in short Shift
   , BYVAL x AS LONG _                                  ' __in OLE_XPOS_PIXELS x
   , BYVAL y AS LONG _                                  ' __in OLE_YPOS_PIXELS y
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLEStartDrag <1550> ( _
     BYREF pData AS IDispatch _                         ' __in_out DataObject** Data
   , BYREF AllowedEffects AS LONG _                     ' __in_out long *AllowedEffects
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLEGiveFeedback <1551> ( _
     BYREF Effect AS LONG _                             ' __in_out long* Effect
   , BYREF DefaultCursors AS INTEGER _                  ' __in_out VARIANT_BOOL* DefaultCursors
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLESetData <1552> ( _
     BYREF pData AS IDispatch _                         ' __in_out DataObject** Data
   , BYREF DataFormat AS INTEGER _                      ' __in_out short *DataFormat
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLECompleteDrag <1553> ( _
     BYREF Effect AS LONG _                             ' __in_out long *Effect
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLEDragOver <1554> ( _
     BYREF pData AS IDispatch _                         ' __in_out DataObject** Data
   , BYREF Effect AS LONG _                             ' __in_out long* Effect
   , BYREF iButton AS INTEGER _                         ' __in_out short* Button
   , BYREF iShift AS INTEGER _                          ' __in_out short* Shift
   , BYREF x AS SINGLE _                                ' __in_out float* x
   , BYREF y AS SINGLE _                                ' __in_out float* y
   , BYREF iState AS INTEGER _                          ' __in_out short* State
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD OLEDragDrop <1555> ( _
     BYREF pData AS IDispatch _                         ' __in_out DataObject** Data
   , BYREF Effect AS LONG _                             ' __in_out long* Effect
   , BYREF iButton AS INTEGER _                         ' __in_out short* Button
   , BYREF iShift AS INTEGER _                          ' __in_out short* Shift
   , BYREF x AS SINGLE _                                ' __in_out float* x
   , BYREF y AS SINGLE _                                ' __in_out float* y
   )                                                    ' void

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

END INTERFACE

END CLASS
' ========================================================================================