我的程序在后台运行,怎样才能获得当前活动窗口(另一个应用程序的)的Edit控件的句柄,并给它传递一个字符串呢?用户已经在Edit里设置了插入符号
我试了很多方法,由于不知道窗口名,FindWindow都不能用啊,即使找到该窗体,又怎样得知用户设置插入符号的Edit句柄呢?
请各位大侠伸出援助之手,帮帮小弟.
我试了很多方法,由于不知道窗口名,FindWindow都不能用啊,即使找到该窗体,又怎样得知用户设置插入符号的Edit句柄呢?
请各位大侠伸出援助之手,帮帮小弟.
GetNextWindow()或许能帮助你
有没有函数获得当前活动窗体(另一个应用程序)的句柄啊,又怎么能判断出是哪个edit设置了插入符号呢
现在能够得到最上层用户活动的窗口了,但仍然不知道用户已经设置插入符号的Edit控件的句柄或ID啊
再去查找你想要的Edit.
HWND hWnd = GetForegroundWindow()->GetSafeHwnd();
if( hWnd != NULL )
{
RECT rcClient;
::GetClientRect(hWnd,&rcClient);
EnumChildWindows(hWnd,EnumChildProc, (LPARAM) rcClient); //这里为什么编译不过去呢,提示说第二个参数类型不对
}
//下面是回调函数
BOOL CALLBACK CTest2Dlg::EnumChildProc(HWND hwndChild, LPARAM lParam)
{
int ChildID = GetWindowLong(hwndChild,GWL_ID);
CString s;
s.Format("%d ",ChildID);
AfxMessageBox(s);
return true;
}
Res
Even if GetFocus returns NULL, another thread's queue may be associated with a window that has the keyboard focus. Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function.
不过遗憾的是,对于浏览器打开的网页,地址栏可以接收到消息,而网页里面的EDIT控件却接不到消息,难道这个Edit不是属于该窗口的?