c++visual-c++mfcsdi

CTreeCtrl - changing its position without moving the whole area


Helloes and thank you for reading :)

I am writing an application in MFC/SDI. I split the window in two views. The one on the left is derived from CTreeView, the one on the right from CView. I also created an invisible splitter to part them. Here's the picture showing it: https://i.sstatic.net/WFZsz.png (the area on the left is CTreeView derived, my bad). I wanted to move the CTreeCtrl so it doesn't cover the picture. I googled for the possible solution but the only one I found doesn't work quite as I expected. Using GetWindowRect moves the whole area and doesn't allow me to draw on the area that was previously a part of the rectangle but no longer is. So when I move the CTreeCtrl I can't put a picture in the area above it. I am doing all these things in OnInitialUpdate().

Here's a sample code of what I've found on the internet and tried doing:

CTreeCtrl &list_recipes = this -> GetTreeCtrl();
list_recipes.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.top += 100;
rect.bottom += 100;
list_recipes.MoveWindow(&rect);

// inserting items into the CTreeCtrl
// (...)

CImage image;
CDC dc;
image.LoadFromResource(AfxGetInstanceHandle(), IDB_CUPCAKE);
dc.CreateCompatibleDC(pDC);
CRect rect3(0,0,202,126);
image.Draw(pDC -> m_hDC,rect3);

Any help will be appreciated, thanks in advance :) And I have to use MFC, it wasn't my decision.


Solution

  • I would avoid drawing your image on the treeview. Try using a separate view which contains the treeview and a static control with the treeview moved below.