Sending Keystrokes to Activex

Sending Keystrokes to Activex

Postby alvaro533 » Sun Nov 08, 2009 4: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
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Sending Keystrokes to Activex

Postby fafi » Mon Nov 09, 2009 3:56 am

Mr. Alvaro

Send me your activex file for test over here.

I'm creating class with this code :

Code: Select all  Expand view


*------------------------------------------------------------------------------*
* 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 _ project
   http://www.sourceforge.net/projects/_

*/


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
User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Sending Keystrokes to Activex

Postby Antonio Linares » Mon Nov 09, 2009 7:27 am

Alvaro,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending Keystrokes to Activex

Postby alvaro533 » 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
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Sending Keystrokes to Activex

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests