简体   繁体   English

如何在MFC中移动窗口?

[英]How to move window in MFC?

I have a group box where I placed a CListCtrl with a custom height 我有一个分组框,在其中放置了具有自定义高度的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); });      

Now I want to place a picture control below the CListCtrl , but all the functions with CRect confuse me. 现在,我想在CListCtrl下放置一个图片控件,但是所有带有CRect的功能使我感到困惑。 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? 有人可以帮我解决这个疯狂的mfc问题吗?

The left and top members returned by GetClientRect are always zero. GetClientRect返回的左侧和顶部成员始终为零。 So calling m_FeatureList.GetClientRect tells you nothing about where the control is located. 因此,调用m_FeatureList.GetClientRect不会告诉您控件的位置。 You have to call m_FeatureList.GetWindowRect and then convert the result to get its position relative to the parent dialog. 您必须调用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM