我需要得到鼠标光标下的窗口,一般的用WindowFromPoint函数可以,
但有一个问题是:对话框上的控件(如BUTTON,EDIT,STATIC等),如果控件的
Enable状态是TRUE用上面的函数可以得到窗口句柄,
但如果控件的Enable状态是FALSE,得到的就是对话框的窗口句柄,
我试过很多软件都是这样,但Microsoft Visual Studio 6.0 Tools中的
Spy++却可以得到Enable状态是FALSE的控件的窗口句柄.求救高手,怎么得到.

解决方案 »

  1.   

    我的msdn中没有spy++的源码,只有spy,ddespy的原码.
      

  2.   

    在sdk那一块的,不过好像就是spy吧
      

  3.   

    The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search.
      

  4.   

       好像有个 ChildWindowFromPoint什么的。   MSDN上查下看吧。
      

  5.   

    谢谢大家,这些函数我原本都仔细看过了,只是没仔细看,在ChildWindowFromPoint中
    需要的是客户坐标,我原来的没有转化成客户坐标,所以原来不行.这是我做的代码的一部分,主要实现类似Spy++中的FindWindow功能,当拖鼠标到目标窗口时
    得到窗口,同时显示所在窗口的边框.很多类似的软件中没有显示边框.void CControlHwndDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    if (m_bIsCapturing)
    {
    ClientToScreen(&point);
    HWND h  = ::WindowFromPoint(point);
    if (IsWindow(h))
    {
    POINT ptChild = point;
    ::ScreenToClient(h, &ptChild);//我原来的没有转化成客户坐标,所以原来不行.
    HWND hChild  = ::ChildWindowFromPoint(h, ptChild);
    if (NULL != hChild)
    {
    h = hChild;
    }
    if (::GetWindowThreadProcessId(GetSafeHwnd(), NULL) != ::GetWindowThreadProcessId(h, NULL))
    {
    UpdateWndInformation(h); if (NULL == m_hOldWnd)
    {
    m_hOldWnd = h;
    DrawBorder(h);
    }
    else
    {
    if (h != m_hOldWnd)
    {
    DrawBorder(m_hOldWnd);
    m_hOldWnd = h;
    DrawBorder(h);
    }
    }
    }
    }
    }
    }
    谢谢大家支持.