Question : Overlap CTreeCtrl and multiline CEdit in dialog

I want to have an MFC dialog-based application have two of the controls overlapping.  There is a multiline CEdit, and a CTreeCtrl.  When I compile/run, there are numerous problems with the frames and contents showing up incorrectly.  I've tried a lot of combinations of static and modal frames, and SDK calls to ::SetWindowPos, ::BringWindowToTop, SetForegroundWindow, etc.

Generally, once the focus changes, the frame border disappears.  The tab order seems to override the focus.  Mouse clicking in the tree control is sometimes ignored in the overlap area, and the app behaves like the mouseclick is directed to the CEdit control.

Below is a crude drawing that may convey the effect I'm looking for (if it shows up with fixed font).  I'm baffled, and hope someone can provide a solution.

Regards,
Lynn Allan


CTreeCtrl has focus (z-top)

222222222222222
222222222222222
222222222222222
222222222222222
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888

CEdit has focus (z-top)

222222222222222
222222222222222
222222222222222
222222222222222
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888




IDD_OVERLAP_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "OverLap"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,260,7,50,14
    EDITTEXT        IDC_EDIT1,7,69,306,124,ES_MULTILINE | ES_AUTOHSCROLL
    CONTROL         "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
                    181,26,132,167,WS_EX_STATICEDGE
    LISTBOX         IDC_LIST1,25,25,136,134,LBS_SORT | LBS_NOINTEGRALHEIGHT |
                    WS_VSCROLL | WS_TABSTOP,WS_EX_STATICEDGE
END

Answer : Overlap CTreeCtrl and multiline CEdit in dialog

I_d_allan!  Why do you make me work so hard!

This was a tough problem.  I, too had to try a million different things.  But this combination very nearly works.  I used ClassWizard to create a control for each object and to add a handler for the NM_SETFOCUS messahe:

void CD03Dlg::OnSetfocusEdit1()
{
     m_ctlEdit.SetWindowPos( &wndTopMost,    0,0, 0,0, SWP_NOSIZE |SWP_NOMOVE | SWP_SHOWWINDOW | SWP_DRAWFRAME );
     m_ctlTree.SetWindowPos( &wndNoTopMost,  0,0, 0,0, SWP_NOSIZE |SWP_NOMOVE | SWP_SHOWWINDOW | SWP_DRAWFRAME );

     CRect rc;
     m_ctlEdit.GetWindowRect( &rc );
     ScreenToClient( &rc );
     InvalidateRect( &rc, TRUE );

     m_ctlTree.UpdateWindow();
     m_ctlEdit.UpdateWindow();
}

void CD03Dlg::OnSetfocusTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
     m_ctlTree.SetWindowPos( &wndTopMost,    0,0, 0,0, SWP_NOSIZE |SWP_NOMOVE | SWP_SHOWWINDOW | SWP_DRAWFRAME );
     m_ctlEdit.SetWindowPos( &wndNoTopMost,  0,0, 0,0, SWP_NOSIZE |SWP_NOMOVE | SWP_SHOWWINDOW | SWP_DRAWFRAME );

     CRect rc;
     m_ctlTree.GetWindowRect( &rc );
     ScreenToClient( &rc );
     InvalidateRect( &rc, TRUE );

     m_ctlEdit.UpdateWindow();
     m_ctlTree.UpdateWindow();
}

---=-=-==--=-=-==--=
Notice how the order of the UpdateWindow is critical.  The InvalidateRect gets sent to the dialog, not the control!

There is still a tiny painting problem (see if you can see it).  I don't have time to keep digging right now, but I think it will be easy to fix.

For the Tree, I set all these property checkboxes: Border, Scroll, Client Edge, Static edge, Modal frame.... the result looks pretty good.  And without some of those, the corner of the tree looks kinda wonky.

>>I'm not clear what you are suggesting.  

I'm not sure that roshmon understood the question completely.

-- Dan
Random Solutions  
 
programming4us programming4us