如何知道焦点控制是我要捕捉的控制(我正在使用钩子)? [英] How to know focus control is control i want to catch (i'm using hook)?
问题描述
亲爱的所有人,
我正在为公司的软件编写虚拟键盘,并且当文本框控件处于焦点位置时,我必须进行处理以显示键盘.(完成)
但是有一个问题,我公司的软附件OpenFileDialog.dll打开了打开文件Dialog(Ofd).单击分配给显示打开文件对话框的按钮时,将显示我的键盘.
因此,我必须检查Ofd上的文件名控制"是否集中.如果它被聚焦,我的vkeyboard将会显示.
现在,我正在使用钩子技术来解决问题,用鼠标左键钩住我成功的文件名控件,但是用键盘上的Tab键钩子,我不知道要集中控制哪个控件.
那么,在Tab键的情况下,如何解决呢?否则我必须使用其他方式来解决它.
这是我在方法挂钩键盘中的代码:
Dear all,
I''m coding virtual keyboard for my company''s soft, and i must handle to show keyboard when textbox control is focused.(this is finished)
But have a problem, my company''s soft attached OpenFileDialog.dll to open open file Dialog(Ofd). When click on a button assigned to show open file dialog, my keyboard will display.
so, i must check whether "file name control" on Ofd is focused. if it''s being focused , my vkeyboard will display.
Now, i''m using hook technique to solve, with hook of mouse left button click on filename control i sucessed.but with hook of Tab key on keyboard, i can''t know what control is being focused.
So, in Tab key case, how to solve it? or i must use other way to solve it.
This is my code in method hook keyboard:
if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
{
Keys keyData = (Keys)MyKeyboardHookStruct.VirtualKeyCode;
KeyEventArgs e = new KeyEventArgs(keyData);
if (e.KeyData == Keys.Tab)
{
IntPtr hWndFileDialog = GetForegroundWindow();
IntPtr hWndFileName = GetDlgItem(hWndFileDialog, 0x047C);
IntPtr focusedCtrlKeyboard = GetFocus();
if (focusedCtrlKeyboard == hWndFileName)
{
KeyBoard.Instance.TopMost = true;
KeyBoard.Instance.Show();
}
}
}
我不明白,为什么我通过Win 32的GetFocus()方法得到的文件名控件的hWnd与控件不相等.
请帮我!!!
P/S:我使用C#语言.
最好的问候,
I don''t understand , why hWnd of Filename control which i got is not equal with control is being focused i got by GetFocus() method of Win 32.
Plz help me!!!
P/S: I use C# language.
Best regards,
推荐答案
亲爱的大家,
我解决了我的问题.我用过:
Dear everyone,
I sovled my problem.I used:
<br />
[DllImport("user32.dll")]<br />
private static extern int GetDlgCtrlID(IntPtr hWnd);<br />
这篇关于如何知道焦点控制是我要捕捉的控制(我正在使用钩子)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!