Simple method for making a startup screen for the application in the VC

zhaozj2021-02-16  122

Make a Splash Window for your application

BY KV300 040723

Step 1. First, Add The Following Two Files SplashWindow.cpp And SplashWindow.h To your project

/ * Splashwindow.cpp * /

#include "stdafx.h" #include "resource.h" #include "splashwindow.h" #include

Begin_Message_Map (CSPLASHWINDOW, CWND) ON_WM_PAINT () end_MESSAGE_MAP ()

CSplashWindow :: CSplashWindow () {m_Bitmap.LoadBitmap (MAKEINTRESOURCE (IDB_SPLASHWINDOW)); // Load Bitmap, must add a bmp to your resource with name IDB_SPLASHWINDOW !!! m_Bitmap.GetBitmap (& bmBitmap); // Get Bitmap Info / * Play SplashWindow.wav * / :: Plays ("SplashWindow.wav", Null, SND_ASYNC | SND_FILENAME); // if You NEED Sound Effect, Add a Valid WAV File Named SplashWindow.wav, and if not, comment this line}

CSPLASHWINDOW :: ~ csplashwindow () {}

void CSplashWindow :: Show () {CSplashWindow * m_pSplashWindow = new CSplashWindow; m_pSplashWindow-> CreateSplash (); m_pSplashWindow-> CenterWindow (); m_pSplashWindow-> ShowWindow (SW_SHOW); m_pSplashWindow-> UpdateWindow (); Sleep (3000); / / Delay 3 seconds, you can modify it as your idea m_psplashwindow-> destroyWindow (); // destroy splash window delete m_psplashwindow;}

void CSplashWindow :: CreateSplash () {// Create Splash Window CreateEx (0, AfxRegisterWndClass (0, AfxGetApp () -> LoadStandardCursor (IDC_UPARROW)), "Welcome", WS_POPUP, 0, 0, bmBitmap.bmWidth, // Bitmap Width = Splash Window Width Bmbitmap.Bmheight, // Bitmap Height = Splash Window Height Null, Null, NULL

void CSplashWindow :: OnPaint () {CPaintDC dc (this); MemDC.CreateCompatibleDC (NULL); // Create Memory DC Old_Bitmap = MemDC.SelectObject (& m_Bitmap); // Select DC dc.StretchBlt (0, 0, bmBitmap.bmWidth , bmBitmap.bmHeight, & MemDC, 0, 0, bmBitmap.bmWidth, bmBitmap.bmHeight, SRCCOPY); MemDC.SelectObject (Old_Bitmap); // Select Bitmap} / * SplashWindow.h * / # ifndef _SPLASH_WONDOW_ # define _SPLASH_WINDOW_

#pragma comment (lib, "winmm.lib") // needed for playss () Method

Class CsplashWindow: PUBLIC CWND {Private: CDC MEMDC; Bitmap Bmbitmap; cbitmap m_bitmap; cbitmap * Old_bitmap; csplashwindow * m_psplash;

Void createSplash ();

Public: csplashwindow (); ~ csplashwindow (); static void show (); afx_msg void onpaint (); declare_MESSAGE_MAP ()};

#ENDIF / / ~ _SPLASH_WINDOW_

Step 2: show splash screen in cwinapp :: initInstance ()

#include "splashwindow.h"

.....// Parse Command Line for Standard Shell Commands, DDE, File Open CCommandLineInfo CMDinfo; ParseCommandline (cmdinfo); csplashwindow :: Show (); // show your splashwindow here .....

Step 3: Bulid and Run Your Application ...

转载请注明原文地址:https://www.9cbs.com/read-13646.html

New Post(0)