请教一段常见的关于CListCtrl的代码(客户区位置部分)

白虹李李 2010-12-19 03:18:25
一段标准的CListCtrl代码:

CRect rs;
m_TabCtrl.GetClientRect(&rs);
//调整子对话框在父窗口中的位置
rs.top+=40;
rs.bottom-=20;
rs.left+=5;
rs.right-=20;

//设置子对话框尺寸并移动到指定位置
m_CPart1.MoveWindow(&rs);

平时我也一直这样使用的,没有什么问题。但今天在调整TAB控件的位置的时候发现,在这段网上常见代码的前面有一句话:
调整TAB控件尺寸使其布满整个对话框!

我试验了如果把TAB控件放在对话框的中间,那么以上代码就工作不正常了,获得的rs是从对话框的左上角开始的,而不是我想象中的从TAB控件的左上角开始的!也就是说rs.top==0,rs.left==0。

请教一下高手,要获得TAB控件的客户区怎么办?或者获得TAB控件本身在对话框中的位置也可以啊。

...全文
118 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
白虹李李 2010-12-23
  • 打赏
  • 举报
回复
经过测试,的确要采用GetWindowRect而不是一般例子上的GetClientRect。
不过这个rs的位置还需要仔细的调整。
sxqinge 2010-12-20
  • 打赏
  • 举报
回复
假如子窗口类CPart;

CPart* Pointer;
Pointer = new CPart(&m_TabCtrl);
Pointer->Create(IDD_xxx, &m_TabCtrl);

CRect Rect, ItemRect;
m_tab.GetWindowRect(&Rect);
m_tab.GetItemRect(0, &ItemRect);

int nX, nY, nCX, nCY;
nX = ItemRect.left;
nY = ItemRect.bottom + 1;
nCX = Rect.right - Rect.left - 1;
nCY = Rect.bottom - ItemRect.bottom - 1;

Pointer->SetWindowPos(&m_TabCtrl.wndTop, nX, nY, nCX, nCY, SWP_SHOWWINDOW);
stjay 2010-12-19
  • 打赏
  • 举报
回复
GetClientRect获得的rect的top和left始终为0的
而不是LZ所想象的

将m_CPart1的父窗口设为Tab控件试试
疯狂石头_ 2010-12-19
  • 打赏
  • 举报
回复
CWnd::GetClientRect
This method copies the client coordinates of the CWnd client area into the structure pointed to by lpRect. The client coordinates specify the upper-left and lower-right corners of the client area. Since client coordinates are relative to the upper-left corners of the CWnd client area, the coordinates of the upper-left corner are (0,0).

GetClientRect返回的左上点的坐标一定是(0,0)
无边1 2010-12-19
  • 打赏
  • 举报
回复
TabCtrl的确是rs.top=0,rs.left=0呀
你下个断点不就知道了?
要想获得tab控件在对话框中的位置是m_TabCtrl.GetWindowRect

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧