用VC++ MFC 修改外观和大小,图标、光标、背景
(2009-04-29 14:15:18)
标签:
杂谈 |
分类: 计算机 |
如何修改MFC AppWizard向导生成的框架程序的外观和大小,修改图标、光标、背景的三种方法。如何增加和删除工具栏按钮,如何给应用程序增加工具栏,如何显示和隐藏工具栏。定制状态栏,在状态栏中添加时钟显示,CTime类及其用法。在状态栏中添加进度条(主窗口产生后立即产生进度条的巧妙思想,不能在OnCreate函数中直接处理,要用到自定义消息的方法)。鼠标坐标显示,在CView中获取状态栏对象的几种方式。如何为应用程序添加启动画面。
CMainFrame 样式修改
1、在窗口创建前修改:根据多态性原理,在CMainFrame的PreCreateWindow函数中修改。
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT&
cs)
{
}
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
GWL_STYLE
GWL_WNDPROC
GWL_HINSTANCE
GWL_HWNDPARENT Retrieves the handle of the parent window, if
any.
GWL_ID
GWL_USERDATA
LONG SetWindowLong(
);
另外一个对应的函数
The GetWindowLong function retrieves information about the
specified window. The function also retrieves the 32-bit (long)
value at the specified offset into the extra window memory of a
window.
LONG GetWindowLong(
);
2、如何修改光标、图标等
MFC默认的光标、图标是由MFC底层代码完成的。当然,我们是不能修改MFC的底层代码的。
创建之前
而应该:
方法1:
在PreCreateWindow函数,定义一个自己的窗口类
然后注册这个窗口类
改变cs的属性类名为刚刚定义的这个类。
在框架窗口中只能修改图标等没被View覆盖的。
光标修改:应该在View类中的PreCreateWindow修改,将cs属性类名为刚刚定义的这个类。
这个方法麻烦!
方法2:
使用下面这个函数:
LPCTSTR AFXAPI AfxRegisterWndClass( UINT nClassStyle, HCURSOR
hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0 );
nClassStyle 为样式 参看 WndClass的style成员。msdn
在框架类的PreCreateWindow函数中 用它修改图标。
在视图类的PreCreateWindow函数中,用它修改背景、光标、画刷。
创建之后
方法1:
SetClassLong函数
The SetClassLong function replaces the specified 32-bit (long)
value at the specified offset into the extra class memory or the
WNDCLASSEX structure for the class to which the specified window
belongs.
DWORD SetClassLong(
);
用法查看msdn 注意类型转换。
3、获取当前应用程序与实例句柄
AfxGetApp() 它也有个成员是实例句柄
AfxGetInstanceHandle()
4、WM_TIMER消息使用
时间间隔设置 SetTimer()在构造函数里使用。
5、创建自定义工具栏的步骤
Visual C++ provides you with two methods to create a toolbar. To
create a toolbar resource using the Resource Editor, follow these
steps:
(1)Create a toolbar resource.
(2)Construct the CToolBar object.
(3)Call the Create (or CreateEx) function to create the Windows
toolbar and attach it to the CToolBar object.
(4)Call LoadToolBar to load the toolbar resource.
参看默认生成步骤.
6、状态栏
添加新的状态
如何访问状态拦
7、进度栏
8、自定义消息
The WM_USER constant is used by applications to help define private
messages, usually of the form WM_USER+X, where X is an integer
value.
#define
WM_USER
使用:#define UM_PROGRESS WM_USER+1

加载中…