Lab Animated Button Objective Create an animated button. When you put your mouse over the button, an opening animation will play. When you move your mouse away from the button, a reverse animation will play Task 1 turning BMP's into AVI 1. Our animated button depends on AVI's To turn a sequence of BMP's into an AVI, get videdit. It's free software provided by microsoft. Your teacher probably has a copy already. 2. Rename the BMP's You'll have to name the BMP's in a certain manner for videdit to read the BMP in the proper sequence. The first BMP should be named xxxx00.BMP. Second BMP should be named xxxxx01.BMP, and so on and so on. The xxxx can be any text. Warning: videdit is a Win 3.x program, you may have to adhere to DOS 8.3 file naming conventions. Make the last frame be the clicked frame(the frame displayed when the button is clicked). 3. Tell videdit to load the bmps as a DIB sequence. Hit the play button to test your animation. Adjust frame rate if necessary. File->Save As as a file with an AVI extension. 4. In addition to the forward animation there is the reverse animation. The reverse animation occurs when the mouse moves away from the button. You'll need to make a reverse animation AVI. Cut and paste in reverse order. Make the last frame, the clicked frame. Save as AVI Task 2 Adding the AVI as resource 1. Your animation control can either read an AVI resource or read directly from the AVI file. If you want to add AVI as a resource you'll have to import it like so: Insert->Resource, Import, select your AVI file, enter AVI for resource type. Task 3 Create the button 1. Do the previous lab for creating a custom bitmap button. Do not use CBitmapButton as you won't have the ability to add an animation control. tips: Don't forget to enable the bitmap check box of your button's properties 2. In the button's properties, enable the checkbox flat. You won't be needing that 3d look for your animated button. Task 5 Making an animation button out of a bitmap button 1. Add a CAnimateCtrl member variable to your button class. 2. In the previous lab you wrote ManualInit(). In ManualInit() call your CAnimateCtrl object's Create() with WS_CHILD to put the animation on the button. 3. Next call your CAnimateCtrl object's Open(). Even though the animation control is displayed on top of the button, all mouse events will be processed by the button correctly. Task 5 Make the animated button animate when the mouse is moved across 1. You want your button to receive an event when the user has placed the mouse over the button. The OnSetCursor() function is the appropiate handler. Tell class wizard to add the event WM_SETCURSOR to your animated button class. 2. Now add another WM_SETCURSOR for the dialog that contains the animated button. 3. There is now an OnSetCursor() within the animated button and the dialog. As the mouse passes into the button, run the forward animation. As mouse passes out of the button, run the reverse animation. While the mouse is within the button, the forward animation should run to completion. When the mouse is outside the button, the reverse animation should run to completion. Hint: Use OnSetCursor(), not OnSetFocus(). Alternative: Some students may not be comfortable with building an OnSetCursor() on both the button and the dialog. The alternative is use one OnSetCursor() in the button, but call SetCapture() and ReleaseCapture() to grab all mouse events whether inside or outside the button. 4. Play wav files to complement the forward and reverse animation. Include mmsystem.h, import winmm.lib, and call sndPlaySound(). Optional: You may notice that your animation is being interrupted if you move the mouse in and out quickly. You can't really check if the CAnimateCtrl is finished playing an animation. If your wav file's timing coincides with the animation, you may be able to use sndPlaySound() with SND_STOP to check if the wav file is done playing. By refusing to interrupt the wav file playing, you may be able to prevent your animation from being interrupted. Note, the author has not tried this out.