如何检测焦点窗口是否为编辑“类型”控件?我知道的一种方法是使用Microsoft Active Accessibility,看起来它会涉及使用这种方法的很多努力。如何检测焦点窗口是否为编辑“类型”控件?
有没有另一种方法,我可以使用更简单?
我的用例是:当编辑控件有焦点时,存储hwnd
。
// Callback set by SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, NULL, (WINEVENTPROC)&winEventProc, 0, 0, WINEVENT_SKIPOWNPROCESS);
void CALLBACK KeyboardComponent::winEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject,
LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
// if hwnd == "Edit Control" store hwnd to send key input events
// One technique but not comprehensive
TCHAR wndClassName[255];
GetClassName(hwnd, wndClassName, 255);
if (_tcsicmp(wndClassName, _T("edit")) == 0)
targetEdit = hwnd;
// Class names I am receiving are subclassed or new window classes that look and operate like Edit controls.
// Ie when clicking the Firefox address bar I get: MozillaWindowClass
// Ie when clicking the Chrome address bar I get: Chrome_WidgetWin_1
}
有什么不好的代码?使用Windows API可以查看窗口类的名称,这正是您正在做的。 –
我必须投票这个问题,因为,如果我想编辑类,并获得编辑类,这是我想要的。 OP有问题的理解并非所有看起来都是编辑控件的控件都是“编辑”类。 – user2120666
我不认为你真的明白你在这里做什么。谁说控制甚至是开窗。你已经找到了正确的解决方案,UI自动化。停止从它跑。 –