MFC-单文档-控件随客户区大小改变而改变

思考者Jack 2018-05-02 07:12:32
前提说明:问题如标题所描述,已百度和在CSDN上找了段时间,暂时未发现符合我要求的答案。
问题描述:创建了单文档的程序,在对话框下FORM上添加了一个CTabCtr控件,现在要求将控件大小设置为随当前客户区变化而变化。有自适应的功能。
...全文
974 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
跟随我 2018-05-07
  • 打赏
  • 举报
回复
OnSize处理控件的大小
思考者Jack 2018-05-07
  • 打赏
  • 举报
回复
我现在的做法是直接使用以下代码处理的:
CFormView::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
	if (m_Tab)
	{
		CRect rect;
		GetClientRect(rect);
		m_Tab.MoveWindow(rect);
	}
但是这样出来有一个问题,就是有的时候有效果,有的时候又没有效果。
赵4老师 2018-05-03
  • 打赏
  • 举报
回复
建议直接转WPF
worldy 2018-05-03
  • 打赏
  • 举报
回复
在OnSize事件处理中改变CTabCtr的大小(MoveWindow)
hhhh63 2018-05-03
  • 打赏
  • 举报
回复
在OnSize事件改变控件大小
思考者Jack 2018-05-03
  • 打赏
  • 举报
回复
5楼的方法我用过了,可以将CTabCtrl进行自适应缩放。但是该控件中添加了三个对话框页。造成对话框上的控件也变化了。
scsjhkxx 2018-05-03
  • 打赏
  • 举报
回复
void CMFCApplication2Dlg::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); if (m_listRect.GetCount() > 0) { CRect dlgNow; GetWindowRect(&dlgNow); POSITION pos = m_listRect.GetHeadPosition();//第一个保存的是对话框的Rect CRect dlgSaved; dlgSaved = m_listRect.GetNext(pos); ScreenToClient(dlgNow); float x = dlgNow.Width() * 1.0 / dlgSaved.Width();//根据当前和之前保存的对话框的宽高求比例 float y = dlgNow.Height() * 1.0 / dlgSaved.Height(); ClientToScreen(dlgNow); CRect childSaved; CWnd* pWnd = GetWindow(GW_CHILD); while (pWnd) { childSaved = m_listRect.GetNext(pos);//依次获取子窗体的Rect childSaved.left = dlgNow.left + (childSaved.left - dlgSaved.left)*x;//根据比例调整控件上下左右距离对话框的距离 childSaved.right = dlgNow.right + (childSaved.right - dlgSaved.right)*x; childSaved.top = dlgNow.top + (childSaved.top - dlgSaved.top)*y; childSaved.bottom = dlgNow.bottom + (childSaved.bottom - dlgSaved.bottom)*y; ScreenToClient(childSaved); pWnd->MoveWindow(childSaved); pWnd = pWnd->GetNextWindow(); } } //Invalidate(); } 应该可以实现你说的功能
schlafenhamster 2018-05-03
  • 打赏
  • 举报
回复
如: void CPage3::OnSize(UINT nType, int cx, int cy) { CPropertyPage::OnSize(nType, cx, cy); // TODO: Add your message handler code here if(IsWindow(m_Bt3.m_hWnd)) { if(cx>1100) {// max m_Bt3.MoveWindow(200,200,200,100); } else {// restore m_Bt3.MoveWindow(200,50,120,60); } } }

15,979

社区成员

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

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