FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Sending Keystrokes to Activex
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM

Sending Keystrokes to Activex

Posted: Sun Nov 08, 2009 04:26 PM

Good evening,

I have an Activex control in a Window or in a dialog and I want to get the same effect as if the user had pressed the keys "Control+2" with the focus set on the control.

What lines do I have to write to send those keys to the control?

I have tried oControl:KeyChar(ckey) and ( oControl:Setfocus() , __Keyboard(nkey) ) but it does not work.

Any ideas?

Thank you very much
Alvaro

Posts: 169
Joined: Mon Feb 25, 2008 02:42 AM

Re: Sending Keystrokes to Activex

Posted: Mon Nov 09, 2009 03:56 AM
Mr. Alvaro

Send me your activex file for test over here.

I'm creating class with this code :

Code (fw): Select all Collapse
*------------------------------------------------------------------------------*
* Low Level C Routines
*------------------------------------------------------------------------------*

#pragma BEGINDUMP

#include <windows.h>
#include <commctrl.h>
#include <hbapi.h>
#include <hbvm.h>
#include <hbstack.h>

typedef HRESULT(WINAPI *LPAtlAxGetControl)(HWND hwnd,IUnknown** unk);
typedef HRESULT(WINAPI *LPAtlAxWinInit)(void);

/*

   InitActivex() function.
   2008.07.15 - Roberto López <harbourminigui@gmail.com>
   http://harbourminigui.googlepages.com

   Inspired by the works of Oscar Joel Lira Lira <oskar78@users.sourceforge.net>
        for Freewin project
   http://www.sourceforge.net/projects/freewin

*/

HB_FUNC( INITACTIVEX ) 
{

   HMODULE hlibrary;
   HWND hchild;
   IUnknown *pUnk;
   IDispatch *pDisp;
   LPAtlAxWinInit    AtlAxWinInit;
   LPAtlAxGetControl AtlAxGetControl;

   hlibrary = LoadLibrary( "Atl.Dll" );
   AtlAxWinInit    = ( LPAtlAxWinInit )    GetProcAddress( hlibrary, "AtlAxWinInit" );
   AtlAxGetControl = ( LPAtlAxGetControl ) GetProcAddress( hlibrary, "AtlAxGetControl" );
   AtlAxWinInit();

   hchild = CreateWindowEx( 0, "AtlAxWin",hb_parc(2), WS_CHILD | WS_VISIBLE , hb_parni(3), hb_parni(4), hb_parni(5), hb_parni(6), (HWND)hb_parnl( 1 ) , 0 , 0 , 0 );

   AtlAxGetControl( (HWND) hchild , &pUnk );
   pUnk->lpVtbl->QueryInterface(pUnk,&IID_IDispatch,(void**)&pDisp);

   hb_reta( 3 );
   hb_stornl( (LONG) hchild   , -1, 1 ); 
   hb_stornl( (LONG) pDisp      , -1, 2 ); 
   hb_stornl( (LONG) hlibrary   , -1, 3 ); 

}

HB_FUNC( EXITACTIVEX ) 
{

   DestroyWindow ( (HWND)hb_parnl( 1 ) );
   FreeLibrary ( (HMODULE)hb_parnl( 2 ) );

}


#pragma ENDDUMP


Regards
Fafi
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Sending Keystrokes to Activex

Posted: Mon Nov 09, 2009 07:27 AM

Alvaro,

Try to use SendMessage( oControl:hWnd, WM_KEYDOWN, nKeyValue, 0 ) // 0 --> nKeyFlags

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM

Re: Sending Keystrokes to Activex

Posted: Mon Nov 09, 2009 11:44 AM

Fafi,

Here you can find an example,

http://www.box.net/shared/b334b8nth9

Try sending the nkey 34 (pagedown). Thank you

Antonio,

I have tried this:

SendMessage( oControl:hWnd, WM_KEYDOWN, nKeyValue, 0 )

But it does not work.

If I put this line:

oControl:bKeyDown:= { |nkey | msginfo(nkey) }

I can see that the key is sent, but the activex control does not move accordingly. However if manually I press the key in the keyboard it does move.

Any ideas?
Thank you. Alvaro

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Sending Keystrokes to Activex

Posted: Mon Nov 09, 2009 12:16 PM

Alvaro,

Please try to send the two events, down and up:

PostMessage( oControl:hWnd, WM_KEYDOWN, nKeyValue, 0 )
PostMessage( oControl:hWnd, WM_KEYUP, nKeyValue, 0 )

also, you may first have to give it the focus:
oControl:SetFocus()

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion