VC对话框大小和位置设置

软件开发中,我们通常需要设置对话框到我们需要的大小,并且希望能在我们希望的位置显示,那么就需要设置对话框的大小和位置了。

步骤:

1.新建对话框

新建对话框应用程序,为了方便对比,我们还另外新建两个对话框。


2.设置对话框大小和位置

为了方便对比,一个对话框使用默认效果,另一个对话框重写OnInitDialog函数。
BOOL CDialog2::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//对话框背景图片宽和高
	const int nBkBmpWidth = 480;
	const int nBkBmpHeight = 300;
	int xPos = 0;
	int yPos = 0;

	//获得电脑显示器的像素宽度和像素高度
	int ax = GetDC()->GetDeviceCaps(HORZRES) - nBkBmpWidth;
	int ay = GetDC()->GetDeviceCaps(VERTRES) - nBkBmpHeight;

	int nWidth = 0;
	int nHeight = 0;
	if(ax <= 0)
	{	ax = 0;	}
	else
	{	ax = ax/2;	}
	if(ay <= 0)
	{	ay = 0;	}
	else
	{	ay = ay/2;	}

	RECT clientRect;
	RECT rt;
	clientRect.left = ax;
	clientRect.top = ay;
	clientRect.right = clientRect.left + nBkBmpWidth;
	clientRect.bottom = clientRect.top + nBkBmpHeight;
	MoveWindow(&clientRect);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

默认效果

设置后效果





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值