Implementation of the animation window

xiaoxiao2021-03-06  40

Summary: This article introduces the realization of the animation window by the analysis of the AnimateWindow function, and points out some of the problems and processing methods that will encounter in compilation when using the AnimateWindow function.

Keywords: animation window, AnimateWindow, MSDN

Implementation of the animation window

I. Introduction

As the saying goes, "Buddha's gold is gold, people relying on clothes", a good software can give more users to agree with it. Friends who like to go online will not be unfamiliar with Netant (Network Ants). Its download speed, the function of the breakpoint renewal gives us a deep impression, and its software interface is also quite awkward. In the 1.23 version of Netant, when the next task is completed or error, the center of the main window expands a window in an animation, report the current download situation; when the user turns off the window, the window is closed in a contracted manner. So how is this animated window implementation? Let's discuss how to implement this animation window in VC.

Second, the programming principle

To implement the programming effect of this animation window, mainly use the AnimateWindow function in the Windows API, to achieve the desired animation window effect when using this function during the creation or destruction process of the window. The animation effect provided by the AnimateWindow function is very rich, we can choose a variety of different animation effects in our own procedures, enhance the fun of the program. In order to make the reader have a basic understanding of the AnimateWindow function, let's make a brief introduction to the function:

Function prototype: BOOL AnimateWindow (HWND HWND, DWORD DWTIME, DWORD DWFLAGS)

Functional function: This function can generate two special types of animation effects when displaying and hidden windows: scrolling animation and sliding animation.

Parameter meanings:

HWND: Specifies the handle of the window that produces an animation.

DWTIME: Indicates the movie continued time (in microseconds), completes an animation standard time of 200 microseconds.

DWFAGS: Specifies the type of animation. This parameter can be a combination of one or more of the following marks. Sign Description:

AW_SLIDE: Use the slide type. The default is the type of animation. This flag is ignored when using the aw_center flag.

AW_ACTIVATE: Activate the window. This logo cannot be used after using the aw_hide flag.

AW_BLEND: Implement the fade out. This flag can only be used when HWND is the top window.

AW_HIDE: Hide the window, the window is displayed.

AW_CENTER: If the AW_HIDE flag is used, the window will overlap the window, the contraction window; if the AW_HIDE flag is not used, the window is expanded outward, that is, the window is expanded.

AW_HOR_POSTIVE: Displays the window from left to right. This logo can be used in rolling animations and sliding animations. This flag will be ignored when using the AW_Center flag.

AW_VER_POSTIVE: The window is displayed in the top. This logo can be used in rolling animations and sliding animations. This flag will be ignored when using the AW_Center flag.

AW_VER_NEGATIVE: Displays the window from the bottom. This logo can be used in rolling animations and sliding animations. This flag will be ignored when using the AW_Center flag.

Return Value: If the function is successful, the return value is non-zero; if the function fails, the return value is zero. The function will fail in the following cases:

The window uses the window boundary; the window is already visible to still display the window; the window has hidden the window. Third, the realization of the animation window

The following will use a simple single document program as an example, explaining how to use the AnimateWindow function in the VC to implement the animation effect when opening and closing the program. This article is not described in this article based on the method of multi-document and the dialog box. The development environment used by the author is: WindowsMe, Visual C 6.

1. Establish an MFC AppWizard (EXE) application engineering animal.

In the first step of the MFC AppWizard wizard, select Single Document, then click Press Finish-> OK to complete the project.

2. Add the black body bold some statement in the CMAINFRAME :: oncreate function.

INT CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct)

{...

m_wndtoolbar.enabledocking (CBRS_ALIGN_ANY);

Enabledocking (CBRS_ALIGN_ANY);

DockControlbar (& M_WndToolbar);

AnimateWindow (getsafehwnd (), 1000, aw_center;

Return 0;

}

3, add message processing functions using MFC ClassWizard

Use ClassWizard to add a WM_CLOSE message processing function in the CMAINFRAME class and increase the following statement.

Void cmainframe :: onClose ()

{// Todo: add your message handler code here and / or call default

AnimateWindow (GetsafehWnd (), 1000, aw_hide | aw_center;

CframeWnd :: onClose ();

}

Fourth, the problem that arises when compiling

When implementing a movie window, the author finds that if you use the AnimateWindow function directly in the VC, it will report an error when compiling. Take the above procedure as an example, the system will report when compiling:

'AnimateWindow': undeclared Identifier

'Aw_hide': undeclared Identifier

'Aw_center': undeclared Identifier

It can be seen by error hints that the compilation system considers the animateWindow function and aw_hide, and the two parameters of the AW_Center are not defined. Because the function is defined in the Winuser.h header file, the author is displayed in the program in the program, but still occurs when compiling the header file. Why can't compiled in VC? This function is supported by reviewing the MSDN author in MSDN to explicitly mention that WindowsNT5.0 and Windows98 or higher are supported. Through the author's research found, the problem is in the header file WinUser.h defining the AnimateWindow function. Enter the incrude subdirectory in the VC installation directory, open the Winuser.h file with Edit, press F3 key to find animatewindow, you can find two definitions One is to define the parameters used in this function; the other is the definition of the function prototype. In these two definitions, the WINDOWS version is displayed, # ix (winver> = 0x500) ......, the original problem is here, the various Windows main version numbers we currently have 5 o'clock below , When compiling the above programs in the VC, the compilation system naturally excludes the AnimateWindow function. So in order to use this function in our program, you have to make some small modifications to its header file, so that #IF (winver> = 0x500) is changed to #IF (WinVer> = 0x400), please pay attention to the two The part of the function defined must be modified, and then save the restart after finishing. After modifying the head file, it can be compiled.

Five, small knot

In fact, in the AnimateWindow function contains a variety of animation effects, we only need to add a few statements in the program to make the program's opening and closing will have fun.

In addition, in this example we can find that although it is clearly supported in the MSDN to support the AnimateWindow function in Windows 98, it is found that the definition of the function in the header file is over 5.0 or more, although I don't know What is the reason, but this article is unintentionally a new approach, hoping to play the effect of the readers' work.

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

New Post(0)