Sun Xin VC + + in-depth detailed: Lesson9 Part8---to add a splash screen to the program __c++

Source: Internet
Author: User


VC Menu bar: Project--->add to project--->components and Controls Select Visual C + + components find splash screen

After inserting the component, the Csplashwnd class is added to the project and a statement is added to the OnCreate function of the CMainFrame class:

Csplashwnd::showsplashscreen (this);

Because ShowSplashScreen (this) is defined as a static function in the Csplashwnd class, the invocation method is the class: the function name

The header file for this class is SPLASH.H

Cg:this file is added by the Splash screen component. #ifndef _splash_scrn_ #define _SPLASH_SCRN_//Splash.h:header File///////////////////////////////////////////////// Splash screen Class class Csplashwnd:public CWnd {//Construction PROTECTED:CSPL

Ashwnd ();

Attributes:public:CBitmap M_bitmap;
	Operations public:static void Enablesplashscreen (BOOL benable = TRUE);
	static void ShowSplashScreen (cwnd* pparentwnd = NULL);

Static BOOL Pretranslateappmessage (msg* pMsg); Overrides//ClassWizard generated virtual function Overrides//{{afx_virtual (csplashwnd)//}}afx_virtual//Implem
	Entation public: ~csplashwnd ();

virtual void PostNcDestroy ();
	Protected:bool Create (cwnd* pparentwnd = NULL);
	void Hidesplashscreen ();
	Static BOOL C_bshowsplashwnd;

Static csplashwnd* C_psplashwnd; Generated message map functions protected://{{afx_msg (csplashwnd) afx_msg int OnCreate (lpcreatestruct lpcreatestruct
	); Afx_msg void OnPaint ();
	afx_msg void OnTimer (UINT nidevent);

}}afx_msg declare_message_map ()};

Cg:this file is added by the Splash screen component.

Splash.cpp:implementation File//#include "stdafx.h"//E. G. stdafx.h #include "resource.h"//e.g. resource.h #include "Splash.h"//e.g. SPLASH.H #ifdef _DEBUG #define NEW debug_new #undef this_file static char Based_code This_fi
Le[] = __file__; #endif///////////////////////////////////////////////////////////////////////////////Splash screen class BOOL CSPL
csplashwnd* Csplashwnd::c_psplashwnd;
	Csplashwnd::csplashwnd () {} csplashwnd::~csplashwnd () {//clear the static window pointer.
	ASSERT (C_psplashwnd = = this);
C_psplashwnd = NULL; } begin_message_map (Csplashwnd, CWnd)//{{afx_msg_map (Csplashwnd) on_wm_create () On_wm_paint () ON_WM_TIMER ()//}}AFX 

_msg_map end_message_map () void Csplashwnd::enablesplashscreen (BOOL benable/*= true*/) {c_bshowsplashwnd = bEnable;} void Csplashwnd::showsplashscreen (cwnd* pparentwnd/*= null*/) {if (!c_bshowsplashwnd | | c_psplashwnD!= NULL) return;
	Allocate A new splash screen, and create the window.
	C_psplashwnd = new Csplashwnd;
	if (!c_psplashwnd->create (pparentwnd)) Delete C_psplashwnd;
else C_psplashwnd->updatewindow ();

	BOOL Csplashwnd::P retranslateappmessage (msg* pMsg) {if (C_psplashwnd = NULL) return FALSE;
	If we have a keyboard or mouse message, hide the splash screen.
	    if (pmsg->message = = Wm_keydown | |
	    Pmsg->message = = Wm_syskeydown | |
	    Pmsg->message = = Wm_lbuttondown | |
	    Pmsg->message = = Wm_rbuttondown | |
	    Pmsg->message = = Wm_mbuttondown | |
	    Pmsg->message = = Wm_nclbuttondown | |
	    Pmsg->message = = Wm_ncrbuttondown | |
		Pmsg->message = = Wm_ncmbuttondown) {c_psplashwnd->hidesplashscreen ();	return TRUE;	Message handled here} return FALSE; The message is not handled} BOOL csplashwnd::create (cwnd* pparentwnd/*= null*/) {if!m_bitmap.

	LoadBitmap (Idb_splash)) return FALSE;
	BITMAP BM; M_bitmap. Getbitmap (&amP;BM); Return CreateEx (0, AfxRegisterWndClass (0, AfxGetApp ()->loadstandardcursor (Idc_arrow)), NULL, Ws_popup |
ws_visible, 0, 0, bm.bmwidth, Bm.bmheight, Pparentwnd->getsafehwnd (), NULL);
	} void Csplashwnd::hidesplashscreen () {//Destroy the window, and update the mainframe.
	DestroyWindow ();
AfxGetMainWnd ()->updatewindow ();
	} void Csplashwnd::P Ostncdestroy () {//Free the C + + class.
Delete this;

	int csplashwnd::oncreate (lpcreatestruct lpcreatestruct) {if (cwnd::oncreate (lpcreatestruct) = = 1) return-1;
	Center the window.

	CenterWindow ();
	Set a timer to destroy the splash screen.

	SetTimer (1, 750, NULL);
return 0;

	} void Csplashwnd::onpaint () {CPAINTDC DC (this);
	CDC Dcimage;

	if (!dcimage.createcompatibledc (&DC)) return;
	BITMAP BM; M_bitmap.

	Getbitmap (&BM);
	Paint the image.
	cbitmap* Poldbitmap = Dcimage.selectobject (&m_bitmap); dc.
	BitBlt (0, 0, bm.bmwidth, bm.bmheight, &dcimage, 0, 0, srccopy); Dcimage.selectobjeCT (POLDBITMAP);
	} void Csplashwnd::ontimer (UINT nidevent) {//Destroy the splash screen window.
Hidesplashscreen ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.