转载,觉得非常有用。
如何修改MFC AppWizard向导生成的框架程序的外观和大小,修改图标、光标、背景的三种方法。如何增加和删除工具栏按钮,如何给应用程序增加工具栏,如何显示和隐藏工具栏。定制状态栏,在状态栏中添加时钟显示,CTime类及其用法。在状态栏中添加进度条(主窗口产生后立即产生进度条的巧妙思想,不能在OnCreate函数中直接处理,要用到自定义消息的方法)。鼠标坐标显示,在CView中获取状态栏对象的几种方式。如何为应用程序添加启动画面。(孙鑫老师VC课程第九课)
CMainFrame 样式修改
1、在窗口创建前修改:根据多态性原理,在CMainFrame的PreCreateWindow函数中修改。
In a single document interface (SDI) application, the default window style in the framework is a combination of the WS_OVERLAPPEDWINDOW and FWS_ADDTOTITLE styles. FWS_ADDTOTITLE is an MFC-specific style that instructs the framework to add the document title to the window’s caption. To change the window attributes in an SDI application, override the PreCreateWindow function in your class derived from CFrameWnd (which AppWizard names CMainFrame). For example:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// Create a window without min/max buttons or sizable border
cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;
// Size the window to 1/3 screen size and center it
cs.cy = ::GetSystemMetrics(SM_CYSCREEN) / 3;
cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 3;
cs.y = ((cs.cy * 3) - cs.cy) / 2;
cs.x = ((cs.cx * 3) - cs.cx) / 2;
// Call the base-class version
return CFrameWnd::PreCreateWindow(cs);
}
要改变窗口的名字,必须去掉默认的FWS_ADDTOTITLE 属性
This code creates a main frame window without
2、在窗口创建后修改:OnCreate函数中修改,里面加上函数SetWindowLong
The SetWindowLong function changes an attribute of the specified window. The function also sets a 32-bit (long) value at the specified offset into the extra window memory of a window.
index为GWL_STYLE;样式的意思 其他有
GWL_EXSTYLE Retrieves the extended window styles.
GWL_STYLE Retrieves the window styles.
GWL_WNDPR

本文介绍了如何修改MFC框架程序的外观,包括在CMainFrame的PreCreateWindow函数中修改窗口样式,使用SetWindowLong函数在窗口创建后改变属性,以及如何在PreCreateWindow中定制光标和图标。此外,还讨论了如何添加和删除工具栏按钮,创建自定义工具栏,以及在状态栏中添加时钟和进度条。详细步骤涵盖从窗口大小、风格到自定义消息的处理。
最低0.47元/天 解锁文章
2131

被折叠的 条评论
为什么被折叠?



