VC对话框大小和位置设置
2015-03-30 20:03
211 查看
软件开发中,我们通常需要设置对话框到我们需要的大小,并且希望能在我们希望的位置显示,那么就需要设置对话框的大小和位置了。
步骤:
默认效果
设置后效果
源码下载
步骤:
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 }
默认效果
设置后效果
源码下载
相关文章推荐
- VC++设置对话框显示的起始位置
- VC之按钮控件位置大小界面设置
- 设置对话框大小和位置
- VC MFC对话框中按钮背景色以及大小设置
- mfc基于对话框的应用程序,如何设置初始对话框大小,移动控件位置
- MFC 设置弹出对话框的位置、大小和风格 SetWindowPos
- (四十)android在代码中,如何设置自定义对话框在屏幕中的位置和大小
- 关于对话框和popupwindow的设置指定大小和位置的小结
- 对话框消除黑色背景、边框,设置对话框大小和位置
- Android 自定义对话框,可设置大小和显示位置,并设置点击其他位置不消失
- 1.2 对话框设置(样式、大小位置、无边框可拖动)
- 设置对话框大小和位置
- VC:对话框中设置工具栏的位置(LoadToolBar()、RepositionBars()、SetBarStyle())
- VC改变控件或对话框的大小和位置方法
- 操作Word对象----在指定位置插入图片并设置大小(原)
- VC对话框全屏显示及相应控件位置改变
- VC中自动改变控件位置和大小的对话框类
- VC++之随父窗口变化调整控件大小 (没有位置)
- 设置VC对话框背景图
- VC动态内存大小信息的存放位置