MFC创建一个程序启动画面


在自己写程序的时候,我们可以为我们自己的程序添加一个类似于WORD,VS之类的初始化界面。

具体方法如下:

	CString str=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
		AfxGetApp()->LoadCursor(IDC_WAIT),(HBRUSH)(COLOR_WINDOW+1),NULL);

	CSplashWnd wnd;
	//用注册好的类来创建窗口
	wnd.CreateEx(WS_EX_CLIENTEDGE,str,_T(""),WS_POPUP,CRect(0,0,0,0),NULL,NULL);
	//Call this member function to change the size, position, 
	//and Z-order of child, pop-up, and top-level windows.
	wnd.SetWindowPos(NULL,100,100,wnd.m_bitmap.bmWidth,wnd.m_bitmap.bmHeight,SWP_NOZORDER);
	//This method centers a window relative to its parent.
	//If the pop-up window is not owned, it is centered relative to the screen.
	wnd.CenterWindow();
	//Sets the visibility state of the window. 
	wnd.ShowWindow(SW_SHOW);
	//Send a WM_PAINT msg
	wnd.UpdateWindow();
	::Sleep(3000);
	wnd.DestroyWindow();

CSplashWnd是我们自己编写的CWnd派生类,下面贴出CSplashWnd的相关代码。

在其头文件中,声明了:

	CBitmap m_CBitmap;
	BITMAP  m_bitmap;

用以处理初始化界面的位图。

在PreCreteWindow函数中,在窗口创建前,修改其style

	if(!CWnd::PreCreateWindow(cs))
		return FALSE;
	cs.style=WS_POPUP;
然后,在OnCreate中添加
	m_CBitmap.LoadBitmap(IDB_BITMAP1);
	//把m_CBitmap的图形信息填充到BITMAP结构的m_bitmap中
	m_CBitmap.GetObject(sizeof(BITMAP),&m_bitmap);

m_bitmap填充了IDB_BITMAP1的图形信息,其中的宽度高度等信息后面会用到

然后我们在OnPaint中添加下面代码,就大功告成了

	CPaintDC dc(this); 
	CDC dcMem;
	CBitmap *pBmp;
	CFont font;
	font.CreatePointFont(150,_T("Times New Roman"));
	dcMem.CreateCompatibleDC(&dc);
	//把位图选入到dcMem中。
	pBmp=(CBitmap *)dcMem.SelectObject(&m_CBitmap);

	dc.BitBlt(0,0,m_bitmap.bmWidth,m_bitmap.bmHeight,&dcMem,0,0,SRCCOPY);
	dc.SelectObject(&font);
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(RGB(255,255,0));
	dc.TextOut(50,m_bitmap.bmHeight-60,CString("初始化..."));
	//?????
	dcMem.SelectObject(pBmp);

最后一行代码,本人不明白有什么意义,还请路过的大神指点。

另外我是VC初学者,文中错漏之处,也请告诉我。



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麦麦大

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值