不是这个意思啦
我的意思是想得到一个比较通用的方法,能得到Mouse所指向的窗口句柄
我用windowfrompoint却不能正确处理那个winrar,
想求解一下还有什么其它的办法

解决方案 »

  1.   

    HWND GetMouseWindow(CPoint& point)
    {
    // Find the smallest "window" still containing the point
    // Doing this prevents us from stopping at the first window containing the point
    RECT rect, rectSearch;
    HWND hParentWnd, hWnd, hSearchWnd; hWnd = ::WindowFromPoint(point);
    if(hWnd != NULL)
    {
    // Get the size and parent for compare later
    ::GetWindowRect(hWnd, &rect);
    hParentWnd = ::GetParent(hWnd); // We only search further if the window has a parent
    if(hParentWnd != NULL)
    {
    // Search from the window down in the Z-Order
    hSearchWnd = hWnd;
    do{
    hSearchWnd = ::GetWindow(hSearchWnd, GW_HWNDNEXT); // Does the search window also contain the point, have the same parent, and is visible?
    ::GetWindowRect(hSearchWnd, &rectSearch);
    if(::PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == hParentWnd && ::IsWindowVisible(hSearchWnd))
    {
    // It does, but is it smaller?
    if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top)))
    {
    // Found new smaller window, update compare window
    hWnd = hSearchWnd;
    ::GetWindowRect(hWnd, &rect);
    }
    }
    }while(hSearchWnd != NULL);
    }
    } return hWnd;
    }