Page 1 of 1

Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 12:47 am
by Antonio Linares
We have greatly enhanced FWH Class TActiveX so now there is no need to use Do(), SetProp() and GetProp(), though it offers full backwards compatibility :-)

Now you can directly send Messages to the ActiveX object! i.e.:

oRb = oActiveX:AddRibbonBar( "first" )
or
oSettings = oActiveX:GlobalSettings
or
oActiveX:AnyProp = ...

Its source code is so nice now, that we have decided to publish it here, so you can start using it :-)
Code: Select all  Expand view

// FiveWin ActiveX support (32/64 bits only)
// (c) FiveTech Software, all rights reserved

#include "FiveWin.ch"

#define  HKEY_CLASSES_ROOT       2147483648

//----------------------------------------------------------------------------//

CLASS TActiveX FROM TControl

   CLASSDATA lRegistered AS LOGICAL

   DATA   hActiveX
   DATA   cProgID
   DATA   cString
   DATA   aProperties, aMethods, aEvents
   DATA   bOnEvent
   DATA   oOleAuto

   METHOD New( oWnd, cProgID, nRow, nCol, nWidth, nHeight ) CONSTRUCTOR

   METHOD ReDefine( nId, oWnd, cProgID ) CONSTRUCTOR

   METHOD Do( cMethodName, uParam1, uParam2, uParam3, uParam4, uParam5 )

   METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0

   METHOD EraseBkGnd( hDC ) INLINE 1

   METHOD GetProp( cPropName ) INLINE __ObjSendMsg( ::oOleAuto, cPropName )

   METHOD Initiate( hDlg )
   
   METHOD OnEvent( nEvent, aParams )

   METHOD ReadTypes()

   METHOD ReSize( nFlags, nWidth, nHeight ) INLINE ;
             ActXSetLocation( ::hActiveX, 0, 0, nWidth, nHeight )

   METHOD SetProp( cPropName, uParam1 ) INLINE __ObjSendMsg( ::oOleAuto, cPropName, uParam1 )
             
   METHOD Destroy() INLINE ActXEnd( ::hActiveX ), Super:Destroy()  
   
   ERROR HANDLER OnError( uParam1 )      
             
ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( oWnd, cProgID, nRow, nCol, nWidth, nHeight ) CLASS TActiveX

   DEFAULT oWnd := GetWndDefault(), nRow := 0, nCol := 0, nWidth := 200,;
           nHeight := 200

   ::nTop    = nRow
   ::nLeft   = nCol
   ::nBottom = nRow + nHeight
   ::nRight  = nCol + nWidth
   ::oWnd    = oWnd
   ::nId     = ::GetNewId()
   ::nStyle  = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )
   ::cProgID = cProgID
   ::cString = ActXString( cProgID )

   ::Register()

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
      ::hActiveX = CreateActiveX( ::hWnd, cProgID, Self )
      ::oOleAuto = TOleAuto():New( ActXPdisp( ::hActiveX ) )
      ::nTop = nRow
      ::nLeft = nCol
      ::nWidth = nWidth
      ::nHeight = nHeight
      ::ReadTypes()
   else
      oWnd:DefControl( Self )
   endif

return Self

//----------------------------------------------------------------------------//

METHOD Do( ... ) CLASS TActiveX

#ifndef __XHARBOUR__
   return __ObjSendMsg( ::oOleAuto, ... )
#else
   local aParams := hb_aParams()

   AIns( aParams, 1, ::oOleAuto, .T. )

   return hb_execFromArray( @__ObjSendMsg(), aParams )  
#endif  

//----------------------------------------------------------------------------//

METHOD ReDefine( nId, oWnd, cProgID ) CLASS TActiveX

   DEFAULT oWnd := GetWndDefault()
   
   ::nId     = nId
   ::oWnd    = oWnd
   ::cProgID = cProgID
   ::cString = ActXString( cProgID )

   ::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
   
   oWnd:DefControl( Self )

return Self

//----------------------------------------------------------------------------//

METHOD Initiate( hDlg ) CLASS TActiveX

   Super:Initiate( hDlg )

   ::hActiveX = CreateActiveX( ::hWnd, ::cProgID, Self )
   ::oOleAuto = TOleAuto():New( ActXPdisp( ::hActiveX ) )
   ::ReadTypes()

return nil

//----------------------------------------------------------------------------//

METHOD OnEvent( nEvent, aParams ) CLASS TActiveX

   local nAt := AScan( ::aEvents, { | aEvent | aEvent[ 2 ] == nEvent } )
   local cEvent := If( nAt != 0, ::aEvents[ nAt ][ 1 ], "" )
   
   if ! Empty( ::bOnEvent )
      Eval( ::bOnEvent, If( ! Empty( cEvent ), cEvent, nEvent ), aParams )
   endif  

return nil

//----------------------------------------------------------------------------//

METHOD ReadTypes() CLASS TActiveX

   local oReg := TReg32():New( HKEY_CLASSES_ROOT, "CLSID\" + ::cString + ;
                               "
\InprocServer32" )
   local cTypeLib := oReg:Get( "
" )

   oReg:Close()
   
   if ! Empty( cTypeLib ) .and. File( cTypeLib )
      ::aEvents = ActXEvents( cTypeLib, ::hActiveX )
   endif  

return nil

//----------------------------------------------------------------------------//

METHOD OnError( ... ) CLASS TActiveX

#ifndef __XHARBOUR__
   return __ObjSendMsg( ::oOleAuto, __GetMessage(), ... )
#else
   local aParams := hb_aParams()

   AIns( aParams, 1, ::oOleAuto, .T. )
   AIns( aParams, 2, __GetMessage(), .T. )  

   return hb_execFromArray( @__ObjSendMsg(), aParams )  
#endif  

//----------------------------------------------------------------------------//

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 1:44 am
by fafi
Antonio,

I got error :
error: Unresolved external symbol '_HB_FUN_ACTXEND referenced from (activex.obj)'.

Fafi

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 8:43 am
by Antonio Linares

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 9:24 am
by anserkk
Dear Mr.Antonio,

Would be nice if you can publish an updated FWH 9.4 with these changes. Is it possible ?

Regards

Anser

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 3:14 pm
by Antonio Linares
Anser,

We are uploading a new FWH 9.04 build with those enhancements :-)

It should be ready to be downloaded in a few minutes.

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 3:28 pm
by Enrico Maria Giordano
You are great and amazing as usual, Antonio! :)

EMG

Re: Greatly enhanced Class TActiveX !!!

PostPosted: Sat Apr 18, 2009 10:11 pm
by Antonio Linares
Dear Enrico,

We are a great team all together in these forums :-)

And Harbour is a great project :-)