2

I have a group box where I placed a CListCtrl with a custom height

m_FeatureList.GetClientRect(&rect); nColInterval = rect.Width()/2; m_FeatureList.InsertColumn(0, _T("ID"), LVCFMT_LEFT, nColInterval); m_FeatureList.InsertColumn(1, _T("Class"), LVCFMT_RIGHT, nColInterval); m_FeatureList.ModifyStyle( LVS_OWNERDRAWFIXED, 0, 0 ); m_FeatureList.SetExtendedStyle(m_CoilList.GetExtendedStyle() | LVS_EX_GRIDLINES); ... int a, b; m_FeatureList.GetItemSpacing(true, &a, &b); // data is a vector containing item text m_FeatureList.MoveWindow(listRect.left, listRect.top, listRect.Width(), b*data.size()+4); int i = 0; std::for_each(data.begin(), data.end(), [&](CString& p) { AddDefectListItem(i++,p); }); 

Now I want to place a picture control below the CListCtrl, but all the functions with CRect confuse me. All them place the control somewhere but not where I want.

//m_FeatureList.GetClientRect(&listRect); //m_FeatureList.ClientToScreen(&listRect); m_FeatureList.ScreenToClient(&listRect); // Oh my god, which coordinates do I need??? m_image.MoveWindow(listRect.left, listRect.bottom+3,listRect.Width(), 20); 

Can somebody help me with this crazy mfc stuff?

2
  • Are the List control and the image control both children of the same parent (e.g., controls in the same dialog)? If so, you shouldn't need to transform coordinates at all--just get the coordinates of the list control, add the vertical offset for the image control, and use MoveWindow to move it there. Commented Nov 12, 2013 at 14:19
  • This is not an MFC question, there is no crazy MFC stuff going on. This is pretty much straight Windows API programming; MFC merely saves you of typing hWnd in the parameter lists. If you find MFC confusing, read the Windows API documentation for the respective methods. Read About Windows to get the basics straight. Commented Nov 12, 2013 at 14:43

1 Answer 1

6

The left and top members returned by GetClientRect are always zero. So calling m_FeatureList.GetClientRect tells you nothing about where the control is located. You have to call m_FeatureList.GetWindowRect and then convert the result to get its position relative to the parent dialog.

CRect listRect; m_FeatureList.GetWindowRect(&listRect); ScreenToClient(&listRect); listRect.top = listRect.bottom +3; listRect.bottom = listRect.top + 20; m_image.MoveWindow(&listRect); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.