Windows Interface Programming Article 6 animation startup effect (animation effect display and hiding Windows)

Source: Internet
Author: User

This article supporting procedures: http://download.csdn.net/detail/morewindows/5128647

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/8656068

Welcome to Weibo: http://weibo.com/MoreWindows

 

Five previous articles have introduced Windows interface programming. The directory is as follows:

1. The first bitmap background and bitmap painter in Windows Interface Programming

2. Windows Interface Programming Article 2 translucent forms

3. Windows Interface Programming Article 3 Special-shaped forms normal Edition

4. Windows Interface Programming Article 4 Special-shaped form rich handsome Edition

5. The fifth static control background transparency in Windows Interface Programming

 

Here are three more articles:

1. Windows Interface Programming Article 6 animation startup effect (animation effect display and hiding Windows)

2. Windows Interface Programming Article 7 file drag and drop (File drag and drop)

3. Windows Interface Programming Article 8 ListBox Color Display

 

Animation effects display and hide windows and greatly beautify the program interface. QQ login windows also use animation effects to display and hide windows.

This article "Windows Interface Programming sixth animation start effect (animation effect display and hide window)" describes how to use the animation effect to show hidden windows. To facilitate code reuse, I have encapsulated it into a window animation effect class. Let's take a look at the implementation of this window animation effect class.

Header file canimatewindow. h

# Pragma once // Windows Interface Programming Article 6 animation startup effect (animation effects show and hide windows) // http://blog.csdn.net/morewindows/article/details/8656068//By morewindows-(http://blog.csdn.net/MoreWindows) Class canimatewindow {public: canimatewindow (hwnd = NULL); void setwindowhwnd (hwnd); hwnd get1_whwnd (); bool animatewindow (DWORD dwtime = 400, bool bshow = true, bool bslide = true ); PRIVATE: int getrandomnumber (); Private: int m_nanimatetype; hwnd m_hwndwindow ;};

CPP file canimatewindow. cpp

// Windows Interface Programming Article 6 animation startup effect (animation effects show and hide windows) // http://blog.csdn.net/morewindows/article/details/8656068//By morewindows-(http://blog.csdn.net/MoreWindows) # include <windows. h> # include <stdlib. h> # include <time. h> # include "canimatewindow. H "canimatewindow: canimatewindow (hwnd) {m_hwndwindow = hwnd; m_nanimatetype = getrandomnumber ();} void handle: encrypt (hwnd) {m_hwndwindow = hwnd;} hwnd ca Nimatewindow: getjavaswhwnd () {return m_hwndwindow;} bool canimatewindow: animatewindow (DWORD dwtime, bool bshow, bool bslide) {DWORD dwflags; dwflags = bshow? Aw_activate: aw_hide; dwflags | = bslide? Aw_slide: aw_blend; If (m_nanimatetype = 0) dwflags | = aw_hor_positive; else if (m_nanimatetype = 1) dwflags | = empty; elsedwflags | = aw_center; Return :: animatewindow (m_hwndwindow, dwtime, dwflags);} int canimatewindow: getrandomnumber () {srand (uint) Time (null); Return rand () % 3 ;}

The code is very simple and mainly uses the animatewindow function. The function prototype of this function is as follows:

Boolanimatewindow (

Hwndhwnd,

Dworddwtime,

Dworddwflags

);

This function is also extremely simple. Three parameters, one representing the window handle, one representing the animation duration (milliseconds), and the last parameter representing the animation effect. You can have the following parameters:

Aw_slide

Uses slide animation. By default, roll animation is used. This flag is ignored when used with aw_center.

Aw_activate

Activates the window. Do not use this value with aw_hide.

Aw_blend

Uses a fade effect. This flag can be used only if hwnd is a top-level window.

Aw_hide

Hides the window. By default, the window is shown.

Aw_center

Makes the window appear to collapse inward if aw_hide is used or expand outward if the aw_hide is not used. The varous direction flags have no effect.

Aw_hor_positive

Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with aw_center or aw_blend.

Aw_hor_negative

Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with aw_center or aw_blend.

Aw_ver_positive

Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with aw_center or aw_blend.

Aw_ver_negative

Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with aw_center or aw_blend.

There are a lot of parameters, but in summary we can see that they are divided into the horizontal direction, vertical direction, from the inside out or from the inside out.

 

The following is an example of the animation display window class.

The centerwindow in the code is used to display the window in the center. In this function, getsystemmetrics (sm_cxscreen); and getsystemmetrics (sm_cyscreen ); you can refer to "VC ++ get screen size first article pixel size getsystemmetrics".

// Windows Interface Programming Article 6 animation startup effect (animation effects show and hide windows) // http://blog.csdn.net/morewindows/article/details/8656068//By morewindows-(http://blog.csdn.net/MoreWindows) # include "stdafx. H "# include" resource. H "# include" canimatewindow. H "bool callback dlgproc (hwnd hdlg, uint message, wparam, lparam); // center the window void centerwindow (hwnd); int apientry winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) {// todo: Place code here. dialogbox (hinstance, makeintresource (response), null, dlgproc); Return 0;} bool callback dlgproc (hwnd hdlg, uint message, wparam, lparam) {static hbrush response; static canimatewindow s_aw; Switch (Message) {Case wm_initdialog: {setwindowtext (hdlg, "show and hide window animations-morewindows"); // load the hinstance = (hinstance) getwindowlong (hdlg, gwl_hinstance); hbitmap = loadbitmap (hinstance, makeintresource (idb_bitmap1); worker = createpatternbrush (hbitmap); centerwindow (hdlg); worker (hdlg ); s_aw.animatewindow (600);} return false; Case wm_command: Switch (loword (wparam) {Case idok: Case idcancel: s_aw.animatewindow (400, false); enddialog (hdlg, false ); return true;} break; Case wm_ctlcolordlg: Return (bool) s_hbrushdlgbackground;} return false;} // center the window void centerwindow (hwnd) {rect rcdlg; int ndlgwidth, ndlghight; int nscreenwidth, nscreenhight; nscreenwidth = getsystemmetrics (sm_cxscreen); nscreenhight = getsystemmetrics (sm_cyscreen); getwindowrect (hwnd, & rcdlg); ndlgwidth = rcdlg. right-rcdlg. left; ndlghight = rcdlg. bottom-rcdlg. top; movewindow (hwnd, (nscreenwidth-ndlgwidth)/2, (nscreenhight-ndlghight)/2, ndlgwidth, ndlghight, false );}

The running effect is as follows. Of course, the animation effect is not good. You can download it from http://download.csdn.net/detail/morewindows/5128647( with source code and points free) and run it on your own to see the effect.

 

For more information, see the following two articles: Windows Interface Programming Article 7 file drag and drop (File drag and drop) and

Windows Interface Programming Article 8 ListBox color display line color

The addresses are

1. http://blog.csdn.net/morewindows/article/details/8634451

2. http://blog.csdn.net/morewindows/article/details/8656061

 

This article supporting procedures: http://download.csdn.net/detail/morewindows/5128647

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/8656068

Welcome to Weibo: http://weibo.com/MoreWindows

 

 

Related Article

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: info-contact@alibabacloud.com 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.