Recently, I recently saw an article "Animation popping and animation of dialogs". The article mentioned the effect of using the timer to achieve dialog box animations, but found that not only did not have animation, and even the window is not. After a simple revision, I finally realized the effects in the text, I found that the author said few places, here will be laid out in this applet, and it takes time to spend time. Believe me, according to this step, you can do it: ->.
First, create a dialog-based program in VC6 and create a dialog box;
The following sections are taken from the original text, pay attention to the important part, the key is in these places:
The following variables are defined in the class header file of the dialog, as follows:
INT NWIDTH, NHEIGHT;
INT DX, DY;
INT DX1, DY1;
Add the following code in OnInitDialog ():
CDIALOG :: OnInitdialog ();
CRECT DLGRECT;
GetWindowRect (dlgRect);
CRECT DESKTOPRECT;
GetDesktopWindow () -> getWindowRect (DesktopRect);
INT T1 = desktopRect.width ();
INT T2 = DLGRECT.WIDTH ();
INT T3 = desktopRect.height ();
INT T4 = DLGRECT.HEIGHT ();
MoveWindow (DesktopRect.width () - DLGRECT.WIDTH ()) / 2,
(DesktopRect.height () - DLGRECT.HEIGHT ()) / 2, 0, 0);
NWIDTH = DLGRECT.WIDTH ();
NHEIGHT = DLGRECT.HEIGHT ();
DX = 2;
DY = 4;
DX1 = 2;
DY1 = 2;
/ / Set the timer, pay attention to the differences, and the meaning of each parameter is as follows
// this-> m_hwnd is the handle of the current window, 1 is the timer identifier, not important here, as long as there is a value
// 10 is the timer interval, which is equivalent to 10 milliseconds, you can set it yourself to change the animation.
// 0 means an empty, so that the system will send a WM_TIMER message to the application queue
:: SetTimer (this-> m_hwnd, 1, 10, 0);
Return True;
Add the ONTIMER function, add the following code (these don't change, you can be inlant):
CRECT DLGRECT;
GetWindowRect (dlgRect);
CRECT DESKTOPRECT;
GetDesktopWindow () -> getWindowRect (DesktopRect);
IF (nidevent == 1)
{MoveWindow ((- DX DesktopRect.width () - DLGRECT.WIDTH ()) / 2,
(-dy desktoprect.height () - DLGRECT.HEIGHT ()) / 2,
DX DLGRECT.WIDTH (),
DY DLGRECT.HEIGHT ());
IF (DLGRECT.WIDTH ()> = nwidth)
DX = 0; // do not overgrow
IF (DLGRect.Height ()> = NHEight)
Dy = 0; // do not over y
IF ((DLGRECT.WIDTH ()> = nwidth) && (DLGRect.Height ()> = NHEight)) KillTimer (1); // stop the Timer
}
IF ((DLGRECT.WIDTH ()> = nwidth) && (DLGRect.Height ()> = NHEight))
KillTimer (1); // stop the timer
IF (nidevent == 2)
{MoveWindow (( DX DesktopRect.width () - DLGRECT.WIDTH ()) / 2,
( DY DesktopRect.Height () - DLGRECT.HEIGHT ()) / 2,
-DX1 DLGRECT.WIDTH (),
-dy1 DLGRECT.HEIGHT ());
IF (DLGRect.width () <= 0)
DX1 = 0; // Do Not Over Grow
IF (DLGRECT.HEIGHT () <= 0)
DY1 = 0; // do not over y
IF ((DLGRECT.WIDTH () <= 0) && (DLGRect.Height () <= 0))
{KillTimer (2); // stop the time
CDIALOG :: Onok ();
}
}
CDIALOG :: ONTIMER (Nidevent);
The following is to add, be sure to add on_wm_timer () in the message map of the custom dialog, otherwise the system does not process the Timer ONTIMER function, then the dialog can only be displayed according to the initial situation, that is, the length of 0, wide 0. Try it, don't you get it.
PS: Note The following statement in OnInitDialog ():
MoveWindow (DesktopRect.width () - DLGRECT.WIDTH ()) / 2,
(DesktopRect.height () - DLGRECT.HEIGHT ()) / 2, 0, 0);
This code sets the initial position and size of the custom dialog, and the two values are 0, indicating that the dialog is originally not displayed.