功能就是点击本窗口  获取到本窗口下面那个窗口的句柄
不考虑窗口先后问题  只获取本窗口下面的窗口句柄  下面贴张图给大家看一下就明白我的意思了我尝试用::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字序是否真的能解决我提出来的这个问题,主要的功能就是要完成一个点击本窗口然后直接可以获取到本窗口下面的那个窗口的句柄。求解!!!

解决方案 »

  1.   

    用GetNextWindow,句柄传入当前window的句柄
      

  2.   

    我刚才和朋友讨论了一下,这个GetNextWindow解决不了我这个问题。不知道还有什么办法可以取到本窗口下面窗口的句柄,求解!!
      

  3.   


    注意看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.
      

  4.   

    GetNextWindow(HWND, GW_HWNDNEXT);就可以得到你指定窗口的下一个窗口
      

  5.   

    但是我取来的句柄类名都非常奇怪  MSDN的说明和我实际操作出来的结果搞的我很迷糊啊
    我还取到一个叫做“tooltips_class32”类名的句柄,于是我打开Spy++找了一圈都没看到这个窗口莫非这个GetNextWindow啥都取?
      

  6.   

    测试过了,GetNextWindow GetWindow EnumWindows 都是一个样,不行的.
    会找到全部的包括子窗在内的一大堆窗,好几百个.还要自己筛选,哪些窗不要,最后得出要的窗.
      

  7.   

    GetNextWindow连同系统的窗口一起获取了  难怪返回的句柄莫名其妙的   现在没有疑惑了
    多亏了 finder 的帮助
      

  8.   

    HWND CZWindowDlg::GetNextZWnd(HWND hWnd)
    {
    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搞过行的?给个代码来看看.
      

  9.   

    赞成你的说法,曾经我问过局部刷新的问题,回复的个个都说InvalidateRect。。
      

  10.   

    不过也许是我自己没弄懂这个 GetNextWindow 怎么使用吧
      

  11.   

    就是GetWindow GetNextWindow InvalidateRect等等楼上的这些API就足够了,你想找别的办法也没有。有问题的话只可能是你用法有问题。
      

  12.   

    CSDN就是装专家的比较多,
    很简单的测试代码:SetWindowPos(hWnd1, hWnd2, 0,0,0,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOSIZE);
    HANDLE hWndTest = GetNextWindow(hWnd2, GW_HWNDNEXT);hWndTest和hWnd1根本就不一样,谁能解释?
      

  13.   

    有办法了,应该能解决绝大多数问题,
    还是用GetNextWindow(),取出来的Window用IsWindowVisible判断下,
    FALSE就用取出来的Window再继续GetNextWindow(),
    直到是TRUE,应该就是LZ要的窗口。
    我的问题按这种方法已解决。