功能就是点击本窗口 获取到本窗口下面那个窗口的句柄
不考虑窗口先后问题 只获取本窗口下面的窗口句柄 下面贴张图给大家看一下就明白我的意思了我尝试用::WindowFromPoint获取当前Point的句柄,接着在用该句柄进行::GetNextWindow但是取到的句柄不对,为了让自己看的清楚些,我特地存储了每次获取来的句柄的窗口类名并输出,奇怪,我本窗口下面的窗口是VC6.0的IDE,输出的窗口类名却是(MSCTFIME UI),下面是代码:void CZWindowDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ClientToScreen(&point);
HWND hWndTemp = NULL;
hWndTemp = ::WindowFromPoint(point);
//--------------
HWND hWnd = NULL;
/*
GW_HWNDNEXT = 2; {同级别 Z 序之下}
GW_HWNDPREV = 3; {同级别 Z 序之上}
*/
hWnd = ::GetNextWindow(hWndTemp,GW_HWNDNEXT);
//hWnd = GetNextWindow(GW_HWNDNEXT);
if(!hWnd)
AfxMessageBox(_T("GetNextWindow Fail!!"));
//--------------
CString str;
char wszClassname[MAX_PATH] = _T("\0");
::GetClassName(hWnd,wszClassname,MAX_PATH);
str.Format(_T("Classname:%s"),wszClassname);
CDC *pDC = GetDC();
pDC->Rectangle(0,0,300,200);
pDC->TextOut(30,40,str);
ReleaseDC(pDC);
CDialog::OnLButtonUp(nFlags, point);
}
我也看了MSDN的相关说明:(The GetNextWindow function retrieves a handle to the next or previous window in the Z-Order. The next window is below the specified window; the previous window is above. If the specified window is a topmost window, the function retrieves a handle to the next (or previous) topmost window. If the specified window is a top-level window, the function retrieves a handle to the next (or previous) top-level window. If the specified window is a child window, the function searches for a handle to the next (or previous) child window)
----------------------------------------------------------------------------------------------------现在问题是,对于这个Z字序我没彻底弄懂,所以出现了这个我不明白的问题,不知道Z字序是否真的能解决我提出来的这个问题,主要的功能就是要完成一个点击本窗口然后直接可以获取到本窗口下面的那个窗口的句柄。求解!!!
不考虑窗口先后问题 只获取本窗口下面的窗口句柄 下面贴张图给大家看一下就明白我的意思了我尝试用::WindowFromPoint获取当前Point的句柄,接着在用该句柄进行::GetNextWindow但是取到的句柄不对,为了让自己看的清楚些,我特地存储了每次获取来的句柄的窗口类名并输出,奇怪,我本窗口下面的窗口是VC6.0的IDE,输出的窗口类名却是(MSCTFIME UI),下面是代码:void CZWindowDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ClientToScreen(&point);
HWND hWndTemp = NULL;
hWndTemp = ::WindowFromPoint(point);
//--------------
HWND hWnd = NULL;
/*
GW_HWNDNEXT = 2; {同级别 Z 序之下}
GW_HWNDPREV = 3; {同级别 Z 序之上}
*/
hWnd = ::GetNextWindow(hWndTemp,GW_HWNDNEXT);
//hWnd = GetNextWindow(GW_HWNDNEXT);
if(!hWnd)
AfxMessageBox(_T("GetNextWindow Fail!!"));
//--------------
CString str;
char wszClassname[MAX_PATH] = _T("\0");
::GetClassName(hWnd,wszClassname,MAX_PATH);
str.Format(_T("Classname:%s"),wszClassname);
CDC *pDC = GetDC();
pDC->Rectangle(0,0,300,200);
pDC->TextOut(30,40,str);
ReleaseDC(pDC);
CDialog::OnLButtonUp(nFlags, point);
}
我也看了MSDN的相关说明:(The GetNextWindow function retrieves a handle to the next or previous window in the Z-Order. The next window is below the specified window; the previous window is above. If the specified window is a topmost window, the function retrieves a handle to the next (or previous) topmost window. If the specified window is a top-level window, the function retrieves a handle to the next (or previous) top-level window. If the specified window is a child window, the function searches for a handle to the next (or previous) child window)
----------------------------------------------------------------------------------------------------现在问题是,对于这个Z字序我没彻底弄懂,所以出现了这个我不明白的问题,不知道Z字序是否真的能解决我提出来的这个问题,主要的功能就是要完成一个点击本窗口然后直接可以获取到本窗口下面的那个窗口的句柄。求解!!!
注意看MSDN解释:
The GetNextWindow function retrieves a handle to the next or previous window in the Z-Order. The next window is below the specified window; the previous window is above.
我还取到一个叫做“tooltips_class32”类名的句柄,于是我打开Spy++找了一圈都没看到这个窗口莫非这个GetNextWindow啥都取?
会找到全部的包括子窗在内的一大堆窗,好几百个.还要自己筛选,哪些窗不要,最后得出要的窗.
多亏了 finder 的帮助
{
HWND hNextWnd = hWnd; while (hNextWnd = ::GetWindow(hNextWnd,GW_HWNDNEXT))
{
if (::IsWindowVisible(hNextWnd) == 0)
continue; char szCaption[MAX_PATH]={0};
::GetWindowText(hNextWnd,szCaption,sizeof(szCaption));
if ( ::strstr(szCaption,"Program Manager") || (0 == strcmp(szCaption,"")))
continue; RECT rc;
::GetWindowRect(hNextWnd,&rc);
if ( ::IsRectEmpty(&rc) )
continue; break;
};
return hNextWnd;
}这样勉强可以找到下一个窗.
那些说什么GetNextWindow 的,都是没有试过代码的,MSDN的说法跟函数的实际表现不一样.
不过也可能是我们不会用GetNextWindow,有没有人用GetNextWindow搞过行的?给个代码来看看.
很简单的测试代码:SetWindowPos(hWnd1, hWnd2, 0,0,0,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOSIZE);
HANDLE hWndTest = GetNextWindow(hWnd2, GW_HWNDNEXT);hWndTest和hWnd1根本就不一样,谁能解释?
还是用GetNextWindow(),取出来的Window用IsWindowVisible判断下,
FALSE就用取出来的Window再继续GetNextWindow(),
直到是TRUE,应该就是LZ要的窗口。
我的问题按这种方法已解决。