mfc更改窗口大小

可使用函数1:

//可用于更改窗口的大小,位置等
BOOL SetWindowPos(
   const CWnd* pWndInsertAfter,
   int x,
   int y,
   int cx,
   int cy,
   UINT nFlags 
);

可使用函数2:

//可用于更改窗口的位置,大小
void MoveWindow(
   int x,
   int y,
   int nWidth,
   int nHeight,
   BOOL bRepaint = TRUE 
);
void MoveWindow(
   LPCRECT lpRect,
   BOOL bRepaint = TRUE 
);

项目类型:基于对话框的mfc应用程序


可在函数

//当收到WM_INITDIALOG消息时此函数被调用 
virtual BOOL OnInitDialog( );
中加上以上两个函数中的一个并给予适当的参数,就可改变对话框窗口的大小

例如下面的代码,

//将对话框置顶,不改变对话框位置,将对话框大小设置为485x299
BOOL CdialogDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	SetWindowPos(&wndTop,0,0,485,299,SWP_NOMOVE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}
就可以将对话框大小设置为485x299,也可使用函数MoveWindow达到同样的效果,代码如下

//将对话框置于屏幕中心,设置对话框的大小为485x299
BOOL CdialogDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	SetWindowPos(&wndTop,0,0,485,299,SWP_NOMOVE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

略注:项目类型不同,函数的使用位置或者设置方法可能不同.函数的具体使用方法和各参数的含义可以参见msdn.



以上内容属于个人理解,仅供参考,不保证正确. 如果发现错误或有建议请与我联系,谢谢.
email: linjieligc@qq.com
qq:914196158
程序设计交流群:250967270
Citius, Altius, Fortius





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值