C ++ Builder uses ActiveX to display Flash Animation

Source: Internet
Author: User
C ++ Builder uses ActiveX to display Flash animation-Linux general technology-Linux programming and kernel information. The following is a detailed description. With the strong support of Microsoft, more and more software companies are beginning to support ActiveX, which is a pleasure for friends who like programming! Because we can easily call the external OCX file in the program to implement complicated functions (Bill Gates finally did a good job this time ), for example, you can call IE in your program to display HTML files. Today, I want to introduce how to use ActiveX controls in C ++ Builder to display Flash animation.

1. Install and import ActiveX Controls

The main character of this article is: swflash. ocx, which is included in Windows 98. By default, Windows will install it in the "Windows \ System \ Macromed \ Flash" directory, if you do not select "default installation" during installation, you can find it in the win98_68.cab file on the Win98 installation disc.

C ++ Builder has done a great job in ActiveX support. We can easily Import ActiveX controls in the system: Select "Component-> Import ActiveX Control ", in the above control list, select "ShockWave Flash (Version 1.0)" () and click the "Install" button below! If it is not in the control list, ShockWave

The Flash control has not been registered in the system. It doesn't matter. We can click "Add" to find the OCX file in your computer and then Install it, C ++ Builder automatically registers for it.

2. programming Flash animation display

After the import is successful, C ++ Builder adds a "ShockWaveFlash" control () to the ActiveX page, creates a new project, and places a ShockWaveFlash control in a proper position, adjust the size of the animation, and fill in an existing Flash Animation file name (such as c: \ flash \ test.swf) on your hard disk in its "Movie" attribute ), then press F9 to run the program. You don't have to write a line of code, so we made a program that can display Flash animation!

However, to make it work better, we also need to know the attributes and methods of the ShockWaveFlash control:

[Attribute]

AlignMode (int type) and SAlign (WideString type)

Control the display position of an animation. (if these two attributes are listed together, they are correlated. Changing one or the other will also change accordingly. The following situations are not described ). The value range and meaning are as follows:

0 empty Current Position

1 L the current position is left

2 R: Right

3 LR current position Center

4 T the current position is up

5 LT upper left

6 TR upper right

7 center above LTR

8 B. The current location is down

9 LB bottom left

10 RB lower right

Center below 11 LRB

The current location of 12 TB is vertically centered

13 LTB center vertically to the left

14 TRB center vertically to the right

15 central location of LTRB

[Attribute]

BackgroundColor (int type) and BGColor (WideString type) set the background color. BackgroundColor is an integer value and BGColor is its HEX string.

[Attribute]

Loop (bool type) Loop display

[Attribute]

Whether or not Menu (bool type) displays the right-click Menu. We recommend that you set it to true because it can complete most of the Flash animation control work without writing code.

[Attribute]

The file name of a Movie (WideString) Flash Animation can be dynamically set in the running state. To disable an animation, set it to null.

[Attribute]

Quality (int type) and Quality2 (WideString type) control the display Quality of an animation. Generally, Quality is set to 1 for high-quality display.

[Attribute]

ScaleMode (int type) and scale (WideString type) control the display ratio of the animation. The value range and meaning are as follows:

0 ShowAll show all

1 NoBorder borderless Mode

2 ExactFit stretch to the entire Screen

3 empty original size

[Method]

PercentLoaded returns the percentage of animation loaded. You can create a progress bar to display the animation loading process.

[Method]

LoadMovie is used to load animations on the network. The animation file name is a bstr url value. In C ++ Builder, you can use the AnsiToOLESTR function to convert a Char string to BSTR.

Well, using the attributes and methods described above, I believe you have used it very well! Unfortunately, the ShockWaveFlash control is still not fully functional, for example, the actual size and background color of the animation cannot be returned. However, if we only need to display a specific Flash Animation in the program, these are not important.

3. Register ActiveX Controls

If you want to use your program to someone else, to prevent it from being installed or registering swflash. the ocx file causes the program to fail to run. You must attach the OCX file together and register it in the system in the program. There are two registration methods:

Method 1: Call the external program Regsvr32.exe

Register: ShellExecute(Handle,NULL,“regsvr32.exe "," swflash. ocx ", NULL, SW_SHOWNORMAL );

Anti-Registration: ShellExecute(Handle,NULL,“regsvr32.exe ","/u swflash. ocx ", NULL, SW_SHOWNORMAL );

Method 2: Call the registration and anti-registration functions contained in the control.

Each OCX control provides two output functions: "DllRegisterServer" and "DllUnRegisterServer". You can register and unregister the control itself. We can use LoadLibrary () and GetProcAddress () to call them, this is the same as the method for dynamically calling the DLL library. I will not talk about it here.

4. Experience

Finally, I would like to introduce some tips for using ActiveX controls.

Generally, ActiveX controls do not provide help files. In the C ++ Builder IDE environment, we can only see their design phase attributes and events, so how can we know its runtime attributes and methods? After importing an ActiveX control, C ++ Builder will generate the corresponding header file (*. h) in the "Imports" directory. You just need to open it and check it at a glance!

In addition, we must understand the meaning of various attributes, methods, and parameters. Then we need to compile a program to create a menu item for each attribute and method we want to know, when you click the button, use InputBox input parameters to test the effect. You can also create a status bar to display the value of its related variables.

I wonder if you understand it after writing so much? If you don't need to add the most popular Flash Animation in your program, you can envy your friends!
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.