我有一个组合框,我在其中放置了CListCtrl一个自定义高度
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); });
Run Code Online (Sandbox Code Playgroud)
现在我想在下方放置一个图片控件CListCtrl,但所有功能都让CRect我感到困惑.所有他们把控制放在某处但不是我想要的地方.
//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);
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个疯狂的mfc问题吗?
GetClientRect返回的左侧和顶层成员始终为零.因此,调用m_FeatureList.GetClientRect不会告诉您控件的位置.您必须调用m_FeatureList.GetWindowRect,然后转换结果以获取其相对于父对话框的位置.
CRect listRect;
m_FeatureList.GetWindowRect(&listRect);
ScreenToClient(&listRect);
listRect.top = listRect.bottom +3;
listRect.bottom = listRect.top + 20;
m_image.MoveWindow(&listRect);
Run Code Online (Sandbox Code Playgroud)