First, add the following code to the CPP file or stdafx. H that needs to fade in and out of the window (note that it must be added before # include; otherwise, it will not work ).
# UNDEF winver // undefines the original version and redefines the version # Define winver 0x5000 // to make the animatewindow function available# Include <afxwin. h> |
Then, add the oncreate, onclose, onerasebkgnd, and ontimer message functions to the relevant files. Remember to add the following content to the relevant destructor:
Settimer (1, 3000, null); // sets the timer to 1 and the timer to 3 seconds. |
Add the fade-in window or background bitmap code to the oncreate message function.
Bool csplashwnd: oncreate (lpcreatestruct lpcs) { Centerwindow (); // The window is located in the center of the screen Animatewindow (getsafehwnd (), 500, aw_blend); // fade-in image for 0.5 secondsReturn true; } |
The onclose message function is used to add the fade-out window or background bitmap code:
Void csplashwnd: onclose () { Animatewindow (getsafehwnd (), 500, aw_blend | aw_hide); // fades out the image for 0.5 secondsCwnd: onclose (); } |
The onerasebkgnd message function is to add a background bitmap:
Bool csplashwnd: onerasebkgnd (CDC * PDC) { DDB msplashbitmap; Msplashbitmap. displayddb (PDC, idb_splash); // display bitmap resource idb_splashReturn true; } |
The ontimer message function adds the Timed Shutdown code:
Void csplashwnd: ontimer (uint nidevent) { Killtimer (1); // disable timer 1 Postmessage (wm_close, 0, 0); // send the Close Window Information } |