2009-08-21 19:19 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* contrib/gtwvg/wvgax.prg
* contrib/gtwvg/wvgsink.c
! Code parts used fron axcore.c, deleted from these files.
* contrib/hbwin/axcore.c
+ __AXDOVERB(), a very important function for in-process active-x controls
This commit is contained in:
@@ -17,6 +17,14 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2009-08-21 19:19 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
|
||||
* contrib/gtwvg/wvgax.prg
|
||||
* contrib/gtwvg/wvgsink.c
|
||||
! Code parts used fron axcore.c, deleted from these files.
|
||||
|
||||
* contrib/hbwin/axcore.c
|
||||
+ __AXDOVERB(), a very important function for in-process active-x controls
|
||||
|
||||
2009-08-22 03:10 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* config/common/watcom.mk
|
||||
* config/win/bcc.mk
|
||||
|
||||
@@ -122,7 +122,6 @@ CLASS WvgActiveXControl FROM win_OleAuto, WvgWindow
|
||||
METHOD mapEvent( nEvent, bBlock )
|
||||
|
||||
METHOD handleEvent()
|
||||
METHOD HandleOleEvents()
|
||||
|
||||
PROTECTED:
|
||||
METHOD adviseEvents()
|
||||
@@ -163,63 +162,42 @@ METHOD Create( oParent, oOwner, aPos, aSize, aPresParams, lVisible, cCLSID, cLic
|
||||
::hWnd := NIL
|
||||
::nID := ::oParent:GetControlId()
|
||||
|
||||
Wvg_AxInit()
|
||||
Win_AxInit()
|
||||
|
||||
hWnd := Wvg_AxCreateWindow( Win_N2P( ::hContainer ), ::CLSID, ::nID, ;
|
||||
::aPos[ 1 ], ::aPos[ 2 ], ::aSize[ 1 ], ::aSize[ 2 ], ;
|
||||
::style, ::exStyle )
|
||||
::aPos[ 1 ], ::aPos[ 2 ], ::aSize[ 1 ], ::aSize[ 2 ], ;
|
||||
::style, ::exStyle )
|
||||
IF empty( hWnd )
|
||||
RETURN nil
|
||||
ENDIF
|
||||
//
|
||||
::hWnd := Win_p2n( hWnd )
|
||||
|
||||
hObj := Wvg_AxGetControl( hWnd )
|
||||
hObj := __AxGetControl( hWnd )
|
||||
if empty( hObj )
|
||||
RETURN NIL
|
||||
ENDIF
|
||||
|
||||
Wvg_AxDoVerb( hWnd, -4 )
|
||||
|
||||
//
|
||||
::__hObj := hObj
|
||||
::hWnd := Win_P2N( hWnd )
|
||||
|
||||
::oParent:addChild( SELF )
|
||||
__AxDoVerb( hWnd, -4 )
|
||||
|
||||
IF !Empty( ::__hObj ) .AND. !Empty( ::hEvents )
|
||||
IF !Empty( ::hEvents )
|
||||
#if 1
|
||||
/* hb_ToOutDebug( "AdviseEvents() ----hWnd = %i", hWnd ) */
|
||||
::nEventHandler := "AdviseEvents"
|
||||
::AdviseEvents()
|
||||
#else
|
||||
/* hb_ToOutDebug( "__AxRegisterHandler() ----hWnd = %i", ::hWnd ) */
|
||||
::nEventHandler := "AxRegisterHandler"
|
||||
::__hSink := __AxRegisterHandler( ::__hObj, {|n,...| ::handleOleEvents( n, ... ) } )
|
||||
::__hSink := __AxRegisterHandler( ::__hObj, ::hEvents )
|
||||
#endif
|
||||
ENDIF
|
||||
|
||||
::oParent:addChild( SELF )
|
||||
|
||||
RETURN Self
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD handleOleEvents( nEvent, ... ) CLASS WvgActiveXControl
|
||||
LOCAL aBlocks, i, bBlock, xResult
|
||||
|
||||
hb_idleSleep()
|
||||
IF !empty( ::hEvents )
|
||||
IF hb_hHasKey( ::hEvents, nEvent )
|
||||
aBlocks := ::hEvents[ nEvent ]
|
||||
FOR i := 1 TO len( aBlocks )
|
||||
bBlock := aBlocks[ i ]
|
||||
IF hb_isBlock( bBlock )
|
||||
xResult := eval( bBlock, ... )
|
||||
ENDIF
|
||||
NEXT
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
RETURN xResult
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
METHOD handleEvent( nEvent, aInfo ) CLASS WvgActiveXControl
|
||||
LOCAL nHandled := 0
|
||||
|
||||
@@ -266,7 +244,8 @@ METHOD adviseEvents() CLASS WvgActiveXControl
|
||||
METHOD mapEvent( nEvent, bBlock )
|
||||
|
||||
if hb_isNumeric( nEvent ) .and. hb_isBlock( bBlock )
|
||||
::hEvents[ nEvent ] := { bBlock }
|
||||
//::hEvents[ nEvent ] := { bBlock }
|
||||
::hEvents[ nEvent ] := bBlock
|
||||
endif
|
||||
|
||||
RETURN Self
|
||||
|
||||
@@ -84,76 +84,6 @@ void extern hb_ToOutDebug( const char * sTraceMsg, ... );
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
static HMODULE s_hLib = NULL;
|
||||
|
||||
typedef BOOL ( CALLBACK * PHB_AX_WININIT )( void );
|
||||
typedef BOOL ( CALLBACK * PHB_AX_WINTERM )( void );
|
||||
typedef HRESULT ( CALLBACK * PHB_AX_GETCTRL )( HWND, IUnknown** );
|
||||
|
||||
static PHB_AX_WINTERM s_pAtlAxWinTerm = NULL;
|
||||
static PHB_AX_GETCTRL s_pAtlAxGetControl = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
static void hb_ax_exit( void* cargo )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( cargo );
|
||||
|
||||
if( s_hLib )
|
||||
{
|
||||
#if 0
|
||||
hb_ToOutDebug( "Terminating 1" );
|
||||
#endif
|
||||
if( s_pAtlAxWinTerm )
|
||||
{
|
||||
#if 0
|
||||
hb_ToOutDebug( "Terminating 2" );
|
||||
#endif
|
||||
if( ( *s_pAtlAxWinTerm ) () )
|
||||
{
|
||||
#if 0
|
||||
hb_ToOutDebug( "Terminating 3" );
|
||||
#endif
|
||||
s_pAtlAxWinTerm = NULL;
|
||||
s_pAtlAxGetControl = NULL;
|
||||
}
|
||||
}
|
||||
FreeLibrary( s_hLib );
|
||||
s_hLib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int hb_ax_init( void )
|
||||
{
|
||||
if( s_hLib == NULL )
|
||||
{
|
||||
PHB_AX_WININIT pAtlAxWinInit;
|
||||
|
||||
s_hLib = LoadLibrary( TEXT( "atl.dll" ) );
|
||||
if( ( unsigned long ) s_hLib <= 32 )
|
||||
{
|
||||
s_hLib = NULL;
|
||||
return 0;
|
||||
}
|
||||
pAtlAxWinInit = ( PHB_AX_WININIT ) GetProcAddress( s_hLib, HBTEXT( "AtlAxWinInit" ) );
|
||||
s_pAtlAxWinTerm = ( PHB_AX_WINTERM ) GetProcAddress( s_hLib, HBTEXT( "AtlAxWinTerm" ) );
|
||||
s_pAtlAxGetControl = ( PHB_AX_GETCTRL ) GetProcAddress( s_hLib, HBTEXT( "AtlAxGetControl" ) );
|
||||
if( pAtlAxWinInit )
|
||||
( *pAtlAxWinInit )();
|
||||
|
||||
hb_vmAtQuit( hb_ax_exit, NULL );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( WVG_AXINIT )
|
||||
{
|
||||
hb_retl( hb_ax_init() );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
static void hb_itemPushList( ULONG ulRefMask, ULONG ulPCount, PHB_ITEM** pItems )
|
||||
{
|
||||
HB_ITEM itmRef;
|
||||
@@ -274,21 +204,20 @@ static ULONG STDMETHODCALLTYPE AddRef( IEventHandler *self )
|
||||
static ULONG STDMETHODCALLTYPE Release( IEventHandler *self )
|
||||
{
|
||||
#ifdef __HBTOOUT__
|
||||
hb_ToOutDebug( "Release %i", ( ( MyRealIEventHandler * ) self )->count );
|
||||
hb_ToOutDebug( "WinSink.c:Release %i", ( ( MyRealIEventHandler * ) self )->count );
|
||||
#endif
|
||||
|
||||
if( --( ( MyRealIEventHandler * ) self )->count == 0 )
|
||||
{
|
||||
if( ( ( MyRealIEventHandler * ) self)->pSelf )
|
||||
if( ( ( MyRealIEventHandler * ) self )->pSelf )
|
||||
hb_itemRelease( ( ( MyRealIEventHandler * ) self )->pSelf );
|
||||
|
||||
#if 0
|
||||
if( ( MyRealIEventHandler * ) self )
|
||||
GlobalFree( ( MyRealIEventHandler * ) self );
|
||||
|
||||
#endif
|
||||
return ( ULONG ) 0;
|
||||
}
|
||||
else
|
||||
return ( ULONG ) ( ( MyRealIEventHandler * ) self )->count;
|
||||
return ( ULONG ) ( ( MyRealIEventHandler * ) self )->count;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE GetTypeInfoCount( IEventHandler *self, UINT *pCount )
|
||||
@@ -336,7 +265,7 @@ static HRESULT STDMETHODCALLTYPE Invoke( IEventHandler *self, DISPID dispid, REF
|
||||
PHB_ITEM Key;
|
||||
|
||||
#if 0
|
||||
hb_ToOutDebug( "event = %i",(int)dispid );
|
||||
hb_ToOutDebug( "winsink.c:Invoke dispid = %i",(int)dispid );
|
||||
#endif
|
||||
|
||||
/* We implement only a "default" interface */
|
||||
@@ -355,8 +284,12 @@ hb_ToOutDebug( "event = %i",(int)dispid );
|
||||
Key = hb_itemNew( NULL );
|
||||
if( hb_hashScan( ( ( MyRealIEventHandler * ) self )->pEvents, hb_itemPutNL( Key, dispid ), &ulPos ) )
|
||||
{
|
||||
#if 0
|
||||
PHB_ITEM pArray = hb_hashGetValueAt( ( ( MyRealIEventHandler * ) self )->pEvents, ulPos );
|
||||
PHB_ITEM pExec = hb_arrayGetItemPtr( pArray, 1 );
|
||||
#endif
|
||||
|
||||
PHB_ITEM pExec = hb_hashGetItemPtr( ( ( MyRealIEventHandler * ) self )->pEvents, Key, 0 );
|
||||
|
||||
if( pExec )
|
||||
{
|
||||
@@ -368,7 +301,7 @@ hb_ToOutDebug( "event = %i",(int)dispid );
|
||||
hb_vmPushSymbol( &hb_symEval );
|
||||
hb_vmPush( pExec );
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case HB_IT_STRING:
|
||||
{
|
||||
PHB_ITEM pObject = hb_arrayGetItemPtr( pArray, 3 );
|
||||
@@ -380,7 +313,7 @@ hb_ToOutDebug( "event = %i",(int)dispid );
|
||||
hb_vmPushNil();
|
||||
}
|
||||
break;
|
||||
|
||||
#endif
|
||||
case HB_IT_POINTER:
|
||||
hb_vmPushSymbol( hb_dynsymSymbol( ( ( PHB_SYMB ) pExec )->pDynSym ) );
|
||||
hb_vmPushNil();
|
||||
@@ -572,75 +505,3 @@ HB_FUNC( WVG_AXCREATEWINDOW ) /* ( hWndContainer, CLSID, menuID=0, x, y, w, h, s
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
HB_FUNC( WVG_AXGETCONTROL ) /* HWND hWnd = handle of control container window */
|
||||
{
|
||||
IDispatch *obj;
|
||||
IUnknown *pUnk = NULL;
|
||||
HWND hWnd = ( HWND ) hb_parptr( 1 );
|
||||
|
||||
if( ! s_pAtlAxGetControl )
|
||||
{
|
||||
hb_oleSetError( S_OK );
|
||||
hb_errRT_BASE_SubstR( EG_UNSUPPORTED, 3012, "ActiveX not initialized", HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
return;
|
||||
}
|
||||
|
||||
if( hWnd )
|
||||
{
|
||||
( *s_pAtlAxGetControl )( hWnd, &pUnk );
|
||||
|
||||
if( pUnk )
|
||||
{
|
||||
HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IDispatch ), ( void** ) (void*) &obj );
|
||||
HB_VTBL( pUnk )->Release( HB_THIS( pUnk ) );
|
||||
|
||||
hb_itemReturnRelease( hb_oleItemPut( NULL, obj ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
HB_FUNC( WVG_AXDOVERB ) /* ( hWndAx, iVerb ) --> hResult */
|
||||
{
|
||||
HWND hWnd = ( HWND ) hb_parptr( 1 );
|
||||
IUnknown* pUnk = NULL;
|
||||
HRESULT lOleError;
|
||||
|
||||
if( ! s_pAtlAxGetControl )
|
||||
{
|
||||
hb_oleSetError( S_OK );
|
||||
hb_errRT_BASE_SubstR( EG_UNSUPPORTED, 3012, "ActiveX not initialized", HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
return;
|
||||
}
|
||||
|
||||
lOleError = ( *s_pAtlAxGetControl )( hWnd, &pUnk );
|
||||
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
IOleObject *lpOleObject = NULL;
|
||||
|
||||
lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IOleObject ), ( void** ) ( void* ) &lpOleObject );
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
IOleClientSite* lpOleClientSite;
|
||||
|
||||
lOleError = HB_VTBL( lpOleObject )->GetClientSite( HB_THIS_( lpOleObject ) &lpOleClientSite );
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
MSG Msg;
|
||||
RECT rct;
|
||||
|
||||
memset( &Msg, 0, sizeof( MSG ) );
|
||||
GetClientRect( hWnd, &rct );
|
||||
HB_VTBL( lpOleObject )->DoVerb( HB_THIS_( lpOleObject ) hb_parni( 2 ), &Msg, lpOleClientSite, 0, hWnd, &rct );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hb_oleSetError( lOleError );
|
||||
|
||||
hb_retnl( lOleError );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
@@ -157,6 +157,48 @@ HB_FUNC( __AXGETCONTROL ) /* ( hWnd ) --> pDisp */
|
||||
hb_oleAxControlNew( hb_stackReturnItem(), hWnd );
|
||||
}
|
||||
|
||||
HB_FUNC( __AXDOVERB ) /* ( hWndAx, iVerb ) --> hResult */
|
||||
{
|
||||
HWND hWnd = ( HWND ) hb_parptr( 1 );
|
||||
IUnknown* pUnk = NULL;
|
||||
HRESULT lOleError;
|
||||
|
||||
if( ! s_pAtlAxGetControl )
|
||||
{
|
||||
hb_oleSetError( S_OK );
|
||||
hb_errRT_BASE_SubstR( EG_UNSUPPORTED, 3012, "ActiveX not initialized", HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
return;
|
||||
}
|
||||
|
||||
lOleError = ( *s_pAtlAxGetControl )( hWnd, &pUnk );
|
||||
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
IOleObject *lpOleObject = NULL;
|
||||
|
||||
lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IOleObject ), ( void** ) ( void* ) &lpOleObject );
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
IOleClientSite* lpOleClientSite;
|
||||
|
||||
lOleError = HB_VTBL( lpOleObject )->GetClientSite( HB_THIS_( lpOleObject ) &lpOleClientSite );
|
||||
if( lOleError == S_OK )
|
||||
{
|
||||
MSG Msg;
|
||||
RECT rct;
|
||||
|
||||
memset( &Msg, 0, sizeof( MSG ) );
|
||||
GetClientRect( hWnd, &rct );
|
||||
HB_VTBL( lpOleObject )->DoVerb( HB_THIS_( lpOleObject ) hb_parni( 2 ), &Msg, lpOleClientSite, 0, hWnd, &rct );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hb_oleSetError( lOleError );
|
||||
|
||||
hb_retnl( lOleError );
|
||||
}
|
||||
|
||||
|
||||
/* ======================== Event handler support ======================== */
|
||||
|
||||
@@ -279,7 +321,7 @@ static HRESULT STDMETHODCALLTYPE Invoke( IDispatch* lpThis, DISPID dispid, REFII
|
||||
if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
|
||||
return DISP_E_UNKNOWNINTERFACE;
|
||||
|
||||
if( ! ( ( ISink* ) lpThis )->pItemHandler )
|
||||
if( ! ( ( ISink* ) lpThis)->pItemHandler )
|
||||
return S_OK;
|
||||
|
||||
pAction = ( ( ISink* ) lpThis )->pItemHandler;
|
||||
|
||||
Reference in New Issue
Block a user