One day, I tried to fade in and out the startup screen, so I went to google for a long time, but it was fruitless. But I understand the function of AnimiateWindow. Okay, let's get started. 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 ).
Reference content is as follows: # 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:
Reference content is as follows: 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.
Reference content is as follows: 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 seconds Return true; } |
The OnClose message function is used to add the fade-out window or background bitmap code:
Reference content is as follows: Void CSplashWnd: OnClose () { AnimateWindow (GetSafeHwnd (), 500, AW_BLEND | AW_HIDE); // fades out the image for 0.5 seconds CWnd: OnClose (); } |
The OnEraseBkgnd message function is to add a background bitmap:
Reference content is as follows: BOOL CSplashWnd: OnEraseBkgnd (CDC * pDC) { DDB mSplashBitmap; MSplashBitmap. DisplayDDB (pDC, IDB_SPLASH); // display bitmap resource IDB_SPLASH Return true; } |
The OnTimer message function adds the Timed Shutdown code:
Reference content is as follows: Void CSplashWnd: OnTimer (UINT nIDEvent) { KillTimer (1); // disable timer 1 PostMessage (WM_CLOSE, 0, 0); // send the Close Window Information } |
Isn't it very easy? I think it is complicated to fade in and out the bitmap and window. I just learned VC and can't understand it. I had to come up with this simple method.