tags:

views:

20

answers:

2

Hi,

How would one retrieve the handle of the control that currently has focus ? I am using WH_KEYBOARD_LL to capture all keypresses in, and I should be able to determine in which textbox the user is typing in. The code capturing the events has no direct access to the controls in the other application.

I know the win32 function GetFocus() exists for getting the current window handle, but I need something similar for the current control.

Any ideas would be appreciated.

Pika

A: 

You can pass the GUI thread ID to GetGUIThreadInfo() which will provide you with a GUITHREADINFO.hwndFocus.

Alex K.
Thanks for the suggestion, but the problem remains the same as with GetFocus(). It seems I cannot get the handles of the controls inside Visual Foxpro. All I can get are the windows and child windows inside the application.
pika81
Have you spy++'d it? perhaps the controls are not windows but are drawn instead (like MS Forms)
Alex K.
I just did, but the depth is also limited to windows, toolbars, treeviews, imagelists, not deeper like you would see in a .NET Forms app. I found the following post (http://www.mofeel.net/110-microsoft-public-fox-programmer-exchange/10593.aspx): FoxPro does not use GDI to draw its controls, but it paints them like bitmaps. Seems like it's impossible what I'd like to do.
pika81
I'm gonna try to find another solution to my problem. Thanks for the help.
pika81
A: 

You can use more general WH_MSGFILTER (it's called within context of the monitored thread so you must create a DLL). The callback gets MSG structure containing all informations about message (handle too).

adf88
I took a look at the API, the callback also returns a Hwnd, but in the case of Foxpro, there is none. I will have the same problem. Thanks anyway (I didn't know about that hook)
pika81