Detecting a window within another window

Discussion in 'MFC' started by zapper222, Apr 30, 2007.

  1. zapper222

    zapper222 New Member

    Joined:
    Apr 30, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to write an app using MFC which allows me to drag small dialogs around and drop them in static windows within a main dialog. The idea is, the small dialogs represent workers and the static windows represent work positions. The problem I am having is when I drop the second dialog in the same static window, it simply overlaps the first dialog so you can't tell there are two dialogs ( or three or four etc.).
    I have been using this code to try and detect when the static has a dialog in it:
    Code:
    void CBoxes1Dlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    	CRect rect;
    	CWnd *pWnd1;
    	CPoint pt;
    	int y=0;
    
    	CWnd *pWnd = ChildWindowFromPoint(point);
    	if(pWnd!=NULL) {
    		pWnd->GetWindowRect(rect);
    		ScreenToClient (rect);
    		pt.x=rect.left+5;
    		pt.y=rect.top+5;
    		pWnd1=pWnd->ChildWindowFromPoint(pt,CWP_ALL);
    		
    		if(pWnd1 == pWnd){
    			// no dialog in this static box
    		}else{
    			// handles don't match so must be a dialog in the static already
    		}
    	}
    	m_person->SetWindowPos(&CWnd::wndTop,(pt.x),(pt.y),0,0,SWP_NOSIZE|SWP_NOZORDER);
    }
    
    This doesn't work properly.....
    Anyone see the problem or think of an easier way to do it.

    Thanks
    Zapper
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice