Use flash in VC to beautify your program

Source: Internet
Author: User
Tags strcmp

 

 

Use flash in VC to beautify your program

Source code download


Code running

Flash can be used to make beautiful animations. Do you want your programs to have such beautiful interfaces?
^ _ ^, In fact, it is not difficult to do this. Here we will introduce how to embed the falsh interface into your own program and allow Flash animation to interact with your program.

We can take two steps:

1. Embed Flash animation into your own program. This is relatively simple. Shockwave Flash is used.
Object Control. This control is installed on your system when Flash is installed. The file name below Flash5.0 is swflash. ocx and later versions 5.0.
The name of this document is flash. ocx, which can be found in the system directory;

2. Transfer Messages in Flash Animation and your program for interaction. This is also implemented through controls, but you have to do some processing in Flash Animation and your own programs.

The procedure is described as follows:

1. Embed Flash animation into your own program. All software development tools that support OCX controls on Windows can do this. I am using VC ++ 6.0.
.

1. Check whether Shockwave Flash exists on your system.
The object control is registered. If Flash is installed on your system, this control is available. Otherwise, you can download and install it online.
2. Create an MFC dialog box application named playflash.
3. Add Shockwave Flash
Object Control. After creating the dialog box application, select "project"> "add project"> "components" from the main menu.
And controls "menu option, a components and controls will pop up
The gallery file selection dialog box contains two folders: Registered
ActiveX controls, one is Visual C ++
Components. After selecting the first folder, a series of ActiveX controls that have been registered on the system will appear. Select Shockwave
Flash
Object (if you don't have this control on your system, you won't be able to find it here. You can download it and install it). Click Insert to insert it into the project. Because
The control needs to be operated through a class, so VC will prompt you to specify a class name for the control, you can use the default class name. After being inserted, VC automatically adds this class to the project.
4. generate an object for this control. Set Shockwave Flash
After the object control is successfully inserted into its own project, there will be more icons on the controls panel in the VC dialog box editor. This icon is the icon of the newly added control. Well, how can this happen next?
You can see it again. Like other Windows controls such as button and edit, pull it to the dialog box and associate it with an object. The class of the object is the control we just inserted.
Class. We can use the member functions of this class to manipulate this object, control Flash animation, and interact with our own programs. Assume the name of the associated object.
M_flashplayer.
5. Use the member functions loadmovie and play to import and play animations.
M_flashplayer.loadmovie (0,
Strmovieurl); this function is used to import an animation into a program. strmovieurl is the flash path to be played and must use an absolute path.
M_flashplayer.play (); call this function to start playing the animation. Add these two function calls to the functions in the initialization dialog box.
How are you doing? run the program now and you can see that flash is embedded into your program. There are also several common functions that can be used to control the playback of an animation, such as gotoframe (long

Framenum) can be switched to framenum for playback (the number of detection tasks starts from 0), stopplay () can stop playing..., there are many more, you can try it yourself ^_^. Below we
This article describes how to control interaction.
  

2. Transfer Messages in Flash Animation and your program for interaction.

After embedding flash into your own program, you can operate on Flash Animation. If you want to know what operations the user has performed, you have to let Flash Animation tell us. People who have done flash should know
Action Script Language of FLASH: Action

Script. There is a command named fscommand (command, argS) in it. We want to use this command to send messages to the outside world. This command has two parameters, both of which are characters.
String, you can specify any string in the Flash script. For example, if you press a button of the Flash animation to send a message such as fscommand ("BT", "Bt1,
Press another button to send the fscommand ("BT", "bt2"). After receiving the fscommand message, our program judges that the user presses
Which button is used.

The principle is like this. To achieve this, you have to use fscommand in Flash animation to send messages and receive and process fscommand messages in our program. Flash part
. Then how can our program receive this message? As we mentioned above, Shockwave
Flash
After an object is inserted into our program, it can be used as a common Windows Control. To receive and process the message, you must use the MFC class Wizard to map the message. Do
Method:
1. Add a message processing function.
Select "View-> Class Wizard" in the main menu, select message ing in the pop-up dialog box, and select shockwave of the program we just inserted in the list box on the left.
The ID of the Flash Object Control. Select fscommand on the right,
Click addfunction to add a fscommand message processing function. The format is probably like this:
Void cplayflashdlg: onfscommandshockwaveflash1 (lpctstr command,
Lpctstr
ARGs); the function has two parameters: Flash Action
Two Parameters in the fscommand statement in script. In fact, not both parameters are used. A parameter can be used in the Flash script. In this way, the function only needs to set the first parameter.
Number.
2. Write the Message Processing code.
In the newly added fscommand message processing function, process two parameters. It is actually a string comparison operation, based on which strings to determine what operations the user has performed. This is probably
What it looks like:

Void cplayflashdlg: onfscommandshockwaveflash1 (lpctstr command, lpctstr ARGs)
{
// Todo: add your control notification handler code here
If (0 = strcmp (command, "BT "))
{
If (0 = strcmp (ARGs, "enter "))
{
MessageBox ("welcome to the system! ");
}
}
Else if (0 = strcmp (command, "quit "))
{
MessageBox ("you have chosen to exit! ");
Cdialog: oncancel ();
}
}

This is only the simplest form of processing. Of course, you can send complicated strings in flash, and more processing is required here.

3. Set and read the variables in the Flash animation.

Shockwave Flash Object also provides two functions for interaction. One is cstring.
Getvariable (lpctstr
Name), used to obtain the value of the variable name in Flash Animation. The value is returned to the caller in the form of cstring; the value is void.
Setvariable (maid name, maid
Value), which can be used to set a value for the name variable in the Flash animation.

Using the functions described above, we can interact well between our program and Flash Animation. Shockwave
The Flash Object Control also provides many other functions. If you have any new functions, don't forget to tell me.

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.