Easily use ActiveX controls in BCB

zhaozj2021-02-16  47

Easily use ActiveX controls in BCB

(Copyright requirements: This article must not be reproduced in addition to 9CBS authorization or the author

Under Microsoft's strong support, more and more software companies began to support Activex, which is a very happy thing for friends who like to programmatically! Because we can easily call the external OCX files in the program to implement complex features, only a few ActiveX controls in BCB, most of us need us to install, below through RealPlayer and Flash controls Install and apply, let us learn how to use ActiveX components in BCB :)

First, install, import ActiveX control C Builder is very good to support ActiveX support, we can easily import ActiveX controls in the system: Click on the menu "Component → Import ActiveX Control ..." Open "Import ActiveX dialog box, in the Import ActiveX list box, we can see all registered AxctiveX controls in Windows. Select the control you need in the list list, then click the "Install" button below! If there is no in the list, then the control you have to find is not registered in the system, don't matter, we can click "Add" to find this OCX file in your computer, then C Builder will automatically register it .

Second, understanding all methods of the ActiveX control, all the ActiveX controls are not helping files. In the IDE environment of C Builder, we can only see its design period properties and events, so how can you know its runtime properties and methods? ? C Builder generates the corresponding header file (* .h) in the "E: / Program Files / Borland / CBuilder6 / Imports" directory after importing an ActiveX control (of course your directory may be opened), just open it. Look at it, it's okay! Of course, if you are in BCB6, you can double-click the name of the ActiveX control in the code browser (code editor) of the code editor (Code EDITOR) in the programming, and you will see her on the right code area. Head file, slowly experience :) In addition, we must also understand the meaning of various attributes, methods, and its parameters, then make a program to create a menu item for each of the idea of ​​understanding, clicking The input parameters are used to input parameters, and you can also create a status bar to display the value of the associated variable. Third, the application example

Nowadays, there are a lot of popular ActiveX controls, here we take RealPlayer as an example of Flash control.

1. RealPlayer control

Today's REALPLAYER's streaming media file is gradually rising with its powerful video compression. The RealPlayer Plus player is also a preferred software for playing the RealPlayer format file. People are in good people, in fact, we can use C Builder to create a RealPlayer player that fully meets yourself. Below I will introduce you how to use BCB to complete your RealPlayer. Prerequisites you must have a RealPlayer Plus player in your machine, because we have to use its own ActiveX control. First, we have to import the required ActiveX control in C Builder. Click on the menu "Component → Import ActiveX Control ..." Open the Import ActiveX dialog box. In the Import ActiveX list box, we can see all registered AxctiveX controls in Windows. Select "RealPlayer ActiveX Control Library" control. Then click the "Install" button. Go back to the main interface of the C Builder, you will find a component called Reaudio in the ActiveX tab in the VCL panel. Let us put it in the form. However, in the default, the Reaudio component has no video playback window, which is only to play sound. I just add the following code in the Controls property of the Reaudio component: ImageWindow, ControlPanel, Statusbar (where: ImageWindow, ControlPanel, Statusbar indicates the display video play window, the control strip, respectively, we can find that the appearance of the control has changed It became the shape of a video playback window. Then set the Align property to AlClient, so that the playback window can vary with the form of the form, so that everyone can pull the play window size at will when watching the movie animation. Then, in the form, TIMAGE components, TopEndialog (ODGRealPlay), each of the TREALPLAYER (RadmyPlayer), add two TButton (btnopenclick, btnexitclick). Import your favorite pictures in Image, so as not to single, two TButton is set to start, one is set to end. The name in parentheses is the name gives the control life in my application. Double click BTnOpen to add the following code: void __fastcall tform1 :: btnopenclick (TOBJECT * Sender) {if (odgrealplay-> execute ()) {

Radmyplayer-> source = odgrealplay-> filenameradmyplayer-> DOPLAY (); open and start the player

}} Double-click BTNEXIT to add the following code: // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------- void __fastcall tform1 :: btnexitclick (Tobject * sender) {close () ; / / Termination Program Operation}

In order to open a file, it is easy to select the file, set the ODGREPLAYER's Filter property as follows: All media files (* .RM, *. RAM, *. RA, *. SWF, *. Mp3) | * .rm; * .ram; *. ra; *. SWF; *. mp3 | *. * | *. Press F9 to find a song listening :) Other properties, what about the method? Her properties are really few, and most of them are Bool types. In addition to the above, there is basically nothing to make you don't have to use, the method is a lot, but there is not much, to her head file, See yourself: P 2. Flash control usage

First we have to install, import ActiveX control: Select "Component-> Import ActiveX Control", select "ShockWave Flash (Version 1.0)" in the above control list, then click the "Install" button below! If there is no in the list, then the ShockWave Flash control has not been registered in the system, don't tighten, we can click "Add" button to find this OCX file in your computer, and C Builder will automatically register it. After the introduction is successful, C Builder adds a "ShockWaveflash" control in the Activex page to create a new project. Place a ShockWaveFlash control in the appropriate location, adjust its size, then fill in its "Movie" property A Flash animation file name on your hard disk, then press F9 to run, how, don't write a line of code, we have made a program that shows Flash animation :) For better application, first we understand The properties and methods of the ShockWaveFlash control:

[Property] AlignMode (INT) and Salign (WideString type) Control the display position of the animation (listed in the two attributes), which are mutually associated, change one another change accordingly, the following is similar). The range and meanings are as follows: 0 empty current position 1 l The current position Left 2 R The current position is left to the right 3 LR Current position 4 T Current position on the upper left 6 TR upper right 7 LTR Above the upper 8 b Current position 9 LB left 10 RB Right 11 lrb under the lower right 12 TB Current position vertical cord 13 LTB leaning against left vertical 4 TRB Right vertical 1 15 LTRB Central location [Property] BackgroundColor (int "and BGColor (WideString type) Set background color BackgroundColor is an integer value, BGColor is its HEX string. [Property] Loop (BOOL) Whether the [Property] MENU (BOOL) is displayed to display the right-click menu, it is recommended to set it to True because it can complete most of the control work for Flash animation, without writing code. [Property] Movie (WideString) Flash animation file name, can be dynamically set in operation, turn off an animation, just set it to empty. [Property] Quality (int type) and Quality2 (WideString type) Control the display quality of the animation, generally set Quality to 1 to obtain high quality display effect. [Property] Scalemode and Scale (WideString type) Control the display ratio, value range and meanings as follows: 0 Showll Display all 1 noborder boundless box mode 2 Exactfit stretch to the entire screen 3 empty original size [method] PercentLoaded Returns the percentage of animation that has been loaded, and you can create a process bar to display the movie load. [Method] LoadMovie is used to load an animation on the network. The animation file is named a BSTR-type URL value, and the C Builder can be converted to a BSTR type with the Ansitoolestr function in C Builder. If you want to use your program to others, in order to prevent the program from being unable to run without installing or registering a swflash.ocx file, you must bring the OCX file together with it, and register it in the system, There are two ways to register: Method 1: Call external program Regsvr32.exe registration: 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 control itself The registration and anti-registration function included in each OCX control provides two output functions" dllregisterServer "and" DllunregisterServer ", You can register and reverse registration control itself, we can call them with loadLibrary () and getProcadDress (), which is the same as dynamic calling the DLL library, I am here.

You will ask me why I know how the use of these attributes and the use of the control method, first see the header file of this component, and then use the Inputbox input parameter to test the effect in the program, and create a status bar to display The value of the associated variable. I use this method, maybe you will have a better way, well, use the properties and methods described above, I believe you have used it very well! Of course, I haven't figured out, for example, I want to realize repeat playback in Replayer, the code is as follows: void __fastcall tfrmmyplayer :: btnreopenclick (Tobject * sender)

{

IF (ODGRealPlay-> Execute ())

{

INT N, I;

N = startbox ("" ​​playback number "," How many times do you want to play? "," 2 "));

IF (n <1)

{

ShowMessage ("The number of times must be positive!");

Return;

}

Radmyplayer-> Source = ODGREALPLAY-> FileName;

For (i = 1; i <= n; i )

{

Radmyplayer-> DOPLAY ();

ShowMessage (INTSTOSTR (i)); // Used to test whether there is a problem, you should remove this statement after testing

}

}

No matter how often, I think the problem may appear on doplay (), maybe she has a statement that jumps out of the program (return - I think should be her), directly jump out of the loop, because I don't know how to () What is the original code, maybe not this, is my program some questions, please advise, learn from each other :)

No way ActiveX control has to rely on our own learning, what is the way? But until I have learned a lot, in fact, it can also better learn other components of BCB, because there are still some common.

In any case, I think the ActiveX control brings a lot of convenience to our programming. It doesn't prevent you and makes your own Media Player9 in the above way. I feel happy to give you everything: P

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

New Post(0)