建立一个单文档的MFC应用程序,修改一个应用程序的外观和大小,要在应用程序的窗口创建之前去修改,
1.在CMainFrame类的PrecreateWindow()函数中去创建。
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx=300;//宽度
cs.cy=200;//高度
//cs.style&=~FWS_ADDTOTITLE;
//cs.style=cs.style & ~FWS_ADDTOTITLE;//这两个表达式一样
cs.style=WS_OVERLAPPEDWINDOW;//也可以直接给这个类型赋值
cs.lpszName="维唯为为";//窗口标题
return TRUE;
}
2.用SetWindowLong
在窗口创建之后改变外观,在CMainFrame类中的OnCreate()函数中去编写代码。
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar/n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar/n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
//修改窗口的外观
//SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW);
//修改现有窗口的类型
SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)& ~WS_MAXIMIZEBOX);//使最大化图标变灰
return 0;
}
3.编写自己的窗口类
在CMainFrame::PreCreateWindow(CREATESTRUCT& cs)函数中添加:
WNDCLASS wndcls;//定义一个窗口类
wndcls.cbClsExtra=0;//类的额外内存,0,不需要
wndcls.cbWndExtra=0;//窗口的额外内存,0,不需要
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//背景
wndcls.hCursor=LoadCursor(NULL,IDC_HELP);//NULL,指定标准光标
//注:要改变窗口的背景和光标要在View类中去改变,因View窗口覆盖在Frame窗口之上
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);//图标
wndcls.hInstance=AfxGetInstanceHandle();//获取当前应用程序的句柄
wndcls.lpfnWndProc=::DefWindowProc;//窗口过程用缺省的,函数名指函数的地址
wndcls.lpszClassName="luowei.org";//类的名字
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;//水平重画,垂直重画
RegisterClass(&wndcls);//注册窗口类
cs.lpszClass="luowei.org";
在CStyleView::PreCreateWindow(CREATESTRUCT& cs)函数中添加:
BOOL CStyleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//修改窗口类
cs.lpszClass="luowei.org";//修改成自己定义的类
return CView::PreCreateWindow(cs);
}
4.利用AfxRegisterWnd函数修改
在CMainFrame::PreCreateWindow 中添加:
cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,0,LoadIcon(NULL,IDI_WARNING));
//cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW)//设置成缺省值
AfxRegisterWndClass
LPCTSTR AFXAPI AfxRegisterWndClass( UINT nClassStyle, HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0 );
Return Value
A null-terminated string containing the class name. You can pass this class name to the Create member function in CWnd or other CWnd-derived classes to create a window. The name is generated by the Microsoft Foundation Class Library.
Note The return value is a pointer to a static buffer. To save this string, assign it to a CString variable.
Parameters
nClassStyle
Specifies the Windows class style or combination of styles, created by using the bitwise-OR (|) operator, for the window class. For a list of class styles, see the WNDCLASS structure in the Win32 SDK documentation. If NULL, the defaults will be set as follows:
- Sets the mouse style to CS_DBLCLKS, which sends double-click messages to the window procedure when the user double-clicks the mouse.
- Sets the arrow cursor style to the Windows standard IDC_ARROW.
- Sets the background brush to NULL, so the window will not erase its background.
- Sets the icon to the standard, waving-flag Windows logo icon.
hCursor
Specifies a handle to the cursor resource to be installed in each window created from the window class. If you use the default of 0, you will get the standard IDC_ARROW cursor.
hbrBackground
Specifies a handle to the brush resource to be installed in each window created from the window class. If you use the default of 0, you will have a NULL background brush, and your window will, by default, not erase its background while processing WM_ERASEBKGND.
hIcon
Specifies a handle to the icon resource to be installed in each window created from the window class. If you use the default of 0, you will get the standard, waving-flag Windows logo icon.
Remarks
The Microsoft Foundation Class Library automatically registers several standard window classes for you. Call this function if you want to register your own window classes.
The name registered for a class by AfxRegisterWndClass depends solely on the parameters. If you call AfxRegisterWndClass multiple times with identical parameters, it only registers a class on the first call. Subsequent calls to AfxRegisterWndClass with identical parameters simply return the already-registered classname.
If you call AfxRegisterWndClass for multiple CWnd-derived classes with identical parameters, instead of getting a separate window class for each class, each class shares the same window class. This can cause problems if the CS_CLASSDC class style is used. Instead of multiple CS_CLASSDC window classes, you end up with one CS_CLASSDC window class, and all C++ windows that use that class share the same DC. To avoid this problem, call AfxRegisterClass to register the class.
在CStyleView::PreCreateWindow(CREATESTRUCT& cs)中修改:
BOOL CStyleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//修改窗口类
// cs.lpszClass="luowei.org";//修改成自己定义的类
//修改背景和光标
cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
LoadCursor(NULL,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0);
//cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW)//设置成缺省值
return CView::PreCreateWindow(cs);
}
5.窗口创建之后,再创建图标,光标及背景
利用SetClassLong函数,在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数中添加:
//修改图标
SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR));
修改光标和背景,对CStyleView类添加一个WM_CREATE消息响应,编辑:
int CStyleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
//修改背景
SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)GetStockObject(BLACK_BRUSH));
//修改光标
SetClassLong(m_hWnd,GCL_HCURSOR,(LONG)LoadCursor(NULL,IDC_HELP));
return 0;
}
6.实现动态图标
Insert -> 资源 -> 导入三个图标,在CMainFrame类上定义三个用于存放图标句柄的数组,对CMainFrame类添加一个HICON类型的私有成员变量m_hIcons[3],并在CMainFrame::OnCreate函数中支去加载图标:
extern CStyleApp theApp; //声明这个变量是在外部定义的
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
..................
..................
..................
//加载图标
m_hIcons[0]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));//方式一
m_hIcons[1]=LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2));
//方式二,theApp是外部的全局变量,在CMainFrame::OnCreate函数之前要声明
m_hIcons[2]=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));
SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[0]);//将图标设置成引入的第一个图标
//设置定时器
SetTimer(1,1000,NULL);
return 0;
}
再给CMainFrame类添加WM_TIMER消息处理,编辑:
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int index=1;//静态的变量是存放在数据区当中,而不是分配在栈当中
SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[index]);
index=++index%3;//让图标不断的循环变幻
CFrameWnd::OnTimer(nIDEvent);
}
7.工具栏的编程
在菜单Menu下IDR_MAINFRAME中添加一个菜单项Test,在图标Toolbar下IDR_MAINFRAME中添加一个图标。ID号都取为:IDC_TEST。对Test菜单添加一个COMMAND消息响应函数,编辑:
void CMainFrame::OnTest()
{
// TODO: Add your command handler code here
MessageBox("Test");
}
在工具栏图标之间,添加分隔符,可以用鼠标左键拖住图标往左移一点即可; 可以用鼠标左键把图标拖出工具栏外边即可!
8.创建工具栏
在ToolBar上新建一个工具栏IDR_TOOLBAR1,并在CMainFrame.h中添加:
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CToolBar m_newToolBar;//创建一个ToolBar
然后在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中编辑:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar/n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar/n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
//修改窗口的外观
//SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW);
//修改现有窗口的类型
//SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)& ~WS_MAXIMIZEBOX);//使最大化图标变灰
//修改图标
//SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR));
//加载图标
m_hIcons[0]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));//方式一
m_hIcons[1]=LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2));
//方式二,theApp是外部的全局变量,在CMainFrame::OnCreate函数之前要声明
m_hIcons[2]=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));
SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[0]);//将图标设置成引入的第一个图标
//设置定时器
SetTimer(1,1000,NULL);
if (!m_newToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_RIGHT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_newToolBar.LoadToolBar(IDR_TOOLBAR1))//对m_newToolBar的显示操作
{
TRACE0("Failed to create toolbar/n");
return -1; // fail to create
}
m_newToolBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_newToolBar);
return 0;
}
9.给新加的工具栏添加菜单响应
在查看菜单下新增一个菜单项,取名为:新的工具栏,ID号:IDM_VIEW_NEWTOOL,再添加COMMAN消息响应函数,编辑:
void CMainFrame::OnViewNewtool()
{
// TODO: Add your command handler code here
if(m_newToolBar.IsWindowVisible())
{
m_newToolBar.ShowWindow(SW_HIDE);
}
else
{
m_newToolBar.ShowWindow(SW_SHOW);
}
RecalcLayout();
DockControlBar(&m_newToolBar);
}
10.利用ShowControlBar显示工具栏
在CMainFrame::OnViewNewtool()函数中编辑:
void CMainFrame::OnViewNewtool()
{
// TODO: Add your command handler code here
/* if(m_newToolBar.IsWindowVisible())
{
m_newToolBar.ShowWindow(SW_HIDE);
}
else
{
m_newToolBar.ShowWindow(SW_SHOW);
}
RecalcLayout();
DockControlBar(&m_newToolBar);
*/
ShowControlBar(&m_newToolBar,!m_newToolBar.IsWindowVisible(),FALSE);
}
11.给新的工具栏菜单项添加复选标记
给新的工具栏添加一个UPDATE_COMMAND_UI消息响应,编辑:
void CMainFrame::OnUpdateViewNewtool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_newToolBar.IsWindowVisible());
}
12.状态栏的编程
在字符串表中添加两个字符串,IDS_TIMER(时钟)和IDS_PROGERSS(进度条),然后在MainFrm.cpp文件中修改:
static UINT indicators[] = //指示器的数组
{
ID_SEPARATOR, // status line indicator
IDS_TIMER, //时钟字符串
IDS_PROGRESS, //进度条字符串
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
运行,可以发现状态栏多了两个分隔符。
13.在状态栏显示系统的时间
在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中编辑:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
..........
..........
..........
//设置状态栏一时钟显示当前系统时间
CTime t=CTime::GetCurrentTime();
CString str=t.Format("%H:%M:%S");
//方式1:
//m_wndStatusBar.SetPaneText(1,str,TRUE);//将时间到状态栏
//方式2(IDS_TIMER的索引号未知):
int index=0;
index=m_wndStatusBar.CommandToIndex(IDS_TIMER);
m_wndStatusBar.SetPaneText(index,str,TRUE);
//SetPaneText()函数是CStatusBar的成员函数,IDS_TIMER在指示器中的索引为1
return 0;
}
14.让状态栏时钟的指示器面板宽度
修改状态栏时钟的指示器面板宽度,使秒数也显示出来。同样在CMainFrame::OnCreate函数在编辑:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...........
...........
...........
//设置状态栏一时钟显示当前系统时间
CTime t=CTime::GetCurrentTime();
CString str=t.Format("%H:%M:%S");
CClientDC dc(this);//构造一个DC
CSize sz=dc.GetTextExtent(str);//获取符串在屏幕上显示的宽度和高度信息
//方式1:
//m_wndStatusBar.SetPaneText(1,str,TRUE);//将时间到状态栏
//方式2(IDS_TIMER的索引号未知):
int index=0;
index=m_wndStatusBar.CommandToIndex(IDS_TIMER);
m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,sz.cx);//设置指示器面板的宽度
m_wndStatusBar.SetPaneText(index,str,TRUE);
//SetPaneText()函数是CStatusBar的成员函数,IDS_TIMER在指示器中的索引为1
//改变指示器面板的宽度
return 0;
}
15.让状态栏面板中的时间动起来
在CMainFrame::OnTimer函数中编辑:
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int index=1;//静态的变量是存放在数据区当中,而不是分配在栈当中
SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[index]);
index=++index%3;//让图标不断的循环变幻
CTime t=CTime::GetCurrentTime();
CString str=t.Format("%H:%M:%S");
CClientDC dc(this);//构造一个DC
CSize sz=dc.GetTextExtent(str);//获取符串在屏幕上显示的宽度和高度信息
int t_index=0;
t_index=m_wndStatusBar.CommandToIndex(IDS_TIMER);
m_wndStatusBar.SetPaneInfo(t_index,IDS_TIMER,SBPS_NORMAL,sz.cx);//设置指示器面板的宽度
m_wndStatusBar.SetPaneText(t_index,str,TRUE);
//SetPaneText()函数是CStatusBar的成员函数,IDS_TIMER在指示器中的索引为1
CFrameWnd::OnTimer(nIDEvent);
}
16.创建一个进度栏
首先,在MainFrm.h头文件中创建一个进度栏对象的头文件,
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CToolBar m_newToolBar;//创建一个ToolBar(工具栏)对象
CProgressCtrl m_progress;//创建一个进度栏对象
在CMainFrame::OnCreate函数中继续添加:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.........
.........
.........
//创建进度条
//m_progress.Create(WS_CHILD|WS_VISIBLE|PBS_VERTICAL,CRect(100,100,120,250),this,123);//创建一个水平进度条
m_progress.Create(WS_CHILD|WS_VISIBLE,CRect(100,100,250,120),this,123);//创建一个水平进度条,默认是创建水平的
m_progress.SetPos(50);//设置进度栏的进度位置
return 0;
}
17.把进度条设置到状态栏
在MainFrm.h头文件中添加:
if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//自定义一个消息
#define UM_PROGRESS WM_USER+1
//WM_USER+1是为了避免与系统消息发生冲突,WM_USE是系统保留的
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnTest();
afx_msg void OnViewNewtool();
afx_msg void OnUpdateViewNewtool(CCmdUI* pCmdUI);
//}}AFX_MSG
afx_msg void OnProgress();//声明消息响应函数
DECLARE_MESSAGE_MAP()
在MainFrm.cpp当中添加:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_TIMER()
ON_COMMAND(IDM_TEST, OnTest)
ON_COMMAND(IDM_VIEW_NEWTOOL, OnViewNewtool)
ON_UPDATE_COMMAND_UI(IDM_VIEW_NEWTOOL, OnUpdateViewNewtool)
//}}AFX_MSG_MAP
ON_MESSAGE(UM_PROGRESS,OnProgress)//消息映射
END_MESSAGE_MAP()
//自定义消息响应函数的实现部分
void CMainFrame::OnProgress()
{
//创建进度条
CRect rect;
m_wndStatusBar.GetItemRect(2,&rect);
//m_progress.Create(WS_CHILD|WS_VISIBLE,rect,&m_wndStatusBar,123);//在状态栏创建一个进度条
m_progress.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH,rect,&m_wndStatusBar,123);//设置进度条成平滑的类型
m_progress.SetPos(50);//设置进度栏的进度位置
}
在CMainFrame::OnCreate函数在修改:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.........
.........
.........
//SendMessage(UM_PROGRESS);//发送一个自定义的消息
//SendMessage发送消息后,就由消息响应函数处理,处理完后返回仍就向下执行,
//所以这里用SendMessage发送消息去创建在状态栏上的进度条是不能成功的。
PostMessage(UM_PROGRESS);//它将消息存放到消息队列中后,就立即返回了
return 0;
}
18.对进度栏改进
注释CMainFrame::OnCreate中的PostMessage(UM_PROGRESS);语句。在CMainFrame类上添加一个WM_PAINT消息处理编辑:
void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
//创建进度条
CRect rect;
m_wndStatusBar.GetItemRect(2,&rect);
if(!m_progress.m_hWnd)//判断进度栏是否创建
{
//m_progress.Create(WS_CHILD|WS_VISIBLE,rect,&m_wndStatusBar,123);//在状态栏创建一个进度条
m_progress.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH,rect,&m_wndStatusBar,123);//设置进度条成平滑的类型
}
else
{
m_progress.MoveWindow(rect);//移动矩形区域到状态栏指定的矩形区域
}
m_progress.SetPos(50);//设置进度栏的进度位置
// Do not call CFrameWnd::OnPaint() for painting messages
}
注:要注释CMainFrame::OnCreate函数中的://PostMessage(UM_PROGRESS);语句。
让进度条动起来,在CMainFrame::OnTimer函数中添加:
//让进度条每隔1秒前进
m_progress.StepIt();
19.捕获鼠标当前的位置
方式一:
在CStyleView类中添加一个WM_OnMouseMove消息响应函数,编辑:
void CStyleView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CMainFrame*)GetParent())->m_wndStatusBar.SetWindowText(str);
//将鼠标坐标点的位置设置到状态栏最左端的面板
CView::OnMouseMove(nFlags, point);
}
在这里还要将MainFrm.h头文件中的m_wndStatusBar的属性改为public,如下:
public:
CStatusBar m_wndStatusBar;
还要在StyleView.cpp文件中添加头文件:#include "MainFrm.h"
其它方式:
在CStyleView::OnMouseMov函数中编辑:
void CStyleView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
//方式一
//((CMainFrame*)GetParent())->m_wndStatusBar.SetWindowText(str);
//将鼠标坐标点的位置设置到状态栏最左端的面板
//方式二,利用SetMessageText
//((CMainFrame*)GetParent())->SetMessageText(str);
//方式三,利用GetMessageBar得到状态栏的指针
//((CMainFrame*)GetParent())->GetMessageBar()->SetWindowText(str);
//利用GetMessageBar()获取状态栏的指针,不需要将m_wndStatusBar对象改为public类型也可以
//方式四,
GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR)->SetWindowText(str);
//GetDescendantWindow函数:Call this member function to find the descendant window specified by the given ID
//AFX_IDW_STATUS_BAR是状态栏创建是时候,系统给它指定的一个ID号
CView::OnMouseMove(nFlags, point);
}
20.让程序带上启动画面
选择 project->Add To Project…->conponents and controls… ->visual C++ conponents ->splash screen->Insert->(类名、位图ID默认)->OK->Close 。
运行,OK!! ^_^