Hello Mindaugus

Mindaugas Kavaliauskas wrote:
> 
> I've extended my previous sample by:
> 

> nAddr := MakeWndProc( {|X,Y,Z,T| WndProc( X,Y,Z,T ) } ) 

Can you make this function public. Probably this may pave the 
way to clean a non-portable part of GTWVG, whio knows.


Just to put everything together, to have a whole picture:

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

#include "windows.ch"

FUNC main() 
   LOCAL nAddr, hWnd, cMsg, hWndAx, oAx, pDisp, nStyle

   AtlAxInit() /* !!! */ 

   nAddr := MakeWndProc( {|X,Y,Z,T| WndProc( X,Y,Z,T ) } ) 

   RegisterClass("MainWndCls",, COLOR_WINDOW + 1, LoadCursor( EMPTYPTR(),
IDC_ARROW ), 
                                    LoadIcon(EMPTYPTR(),
IDI_APPLICATION),,,, nAddr ) 

   hWnd := CreateWindow("MainWndCls", "CAWI32 Sample Hello",
WS_OVERLAPPEDWINDOW, 100, 100, 600, 500) 

   /* ActiveX Window and object */
   nStyle := WS_CHILD + WS_VISIBLE + WS_BORDER + WS_HSCROLL + WS_VSCROLL
   hWndAx := CreateWindow( "ATLAXWin", "http://www.harbour-project.org";,
nStyle, 10, 10, 500, 400, hWnd ) /* !!! */ 
   HB_AtlAxGetControl( hWndAx, @pDisp ) 
   IF ! EMPTY( pDisp ) 
      oAx := HB_OleAuto() 
      oAx:__hObj := pDisp 
   ENDIF 

   ShowWindow(hWnd, SW_SHOWNORMAL) 
   UpdateWindow(hWnd) 

   DO WHILE GetMessage(@cMsg) 
     TranslateMessage(cMsg) 
     DispatchMessage(cMsg) 
   ENDDO 

   RETURN 0 

FUNC WndProc(hWnd, nMsg, wParam, lParam) 
   LOCAL hDC, sPS, hMenu, hSubMenu, nStyle 
   LOCAL nStyle := WS_CHILD + WS_VISIBLE + WS_BORDER + WS_HSCROLL +
WS_VSCROLL

   IF nMsg == WM_CREATE 

   ELSEIF nMsg == WM_PAINT 
     hDC := BeginPaint(hWnd, @sPS) 
     EndPaint(hWnd, @sPS) 

   ELSEIF nMsg == WM_DESTROY 
     PostQuitMessage() 
     RETURN 0 

   ENDIF 

   RETURN DefWindowProc( hWnd, nMsg, wParam, lParam ) 

PROC RDDSYS();  RETURN 

PROC HB_GTSYS();  RETURN 


#pragma begindump 

#include "hbapi.h" 
#include <windows.h> 

static HMODULE hLib = NULL; 

HB_FUNC( ATLAXINIT ) 
{ 
    BOOL ( CALLBACK *pAtlAxWinInit )( void ); 

    if( hLib == NULL )
       hLib = LoadLibrary( "atl.dll" ); 
    if( ( unsigned long ) hLib > 32 ) 
    { 
       pAtlAxWinInit = GetProcAddress( hLib, "AtlAxWinInit" ); 
       if( pAtlAxWinInit ) 
          ( *pAtlAxWinInit )(); 
    } 
    // I leave hLib not freed to avoid unloading of library 
} 

HB_FUNC( HB_ATLAXGETCONTROL ) 
{ 
    IUnknown*   pUnk = NULL; 
    IDispatch*  pDisp = NULL; 
    PHB_ITEM    pItem; 
    HRESULT     lOleError; 

    lOleError = ( *s_pAtlAxGetControl )( ( HWND ) hb_parptr( 1 ), &pUnk ); 

    if( lOleError == S_OK ) 
    { 
       /* AtlAxGetControl returns IUnknown, but we are goint to use OLE
Automation 
          on ActiveX control, so let's deal with IDispatch only [Mindaugas]
*/ 
#if HB_OLE_C_API 
       lOleError = pUnk->lpVtbl->QueryInterface( pUnk, &IID_IDispatch, (
void** ) ( void * ) &pDisp ); 
       pUnk->lpVtbl->Release( pUnk ); 
#else 
       lOleError = pUnk->QueryInterface( IID_IDispatch, ( void** ) ( void *
) &pDisp ); 
       pUnk->Release(); 
#endif 
    } 

    if( lOleError == S_OK ) 
    { 
       pItem = hb_oleItemPut( NULL, pDisp ); 
       hb_itemParamStoreForward( 2, pItem ); 
       hb_itemRelease( pItem ); 
       hb_retnl( S_OK ); 
    } 
    else 
    { 
       /* TODO: RTE */ 
    } 
    hb_retnl( lOleError ); 
} 

#pragma enddump 

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

Regards
Pritpal Bedi


-- 
View this message in context: 
http://www.nabble.com/Errors-with-11032-tp23521549p23607332.html
Sent from the Harbour - Dev mailing list archive at Nabble.com.

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to