Easy use of ActiveX controls in BCB

Source: Internet
Author: User

With Microsoft's strong support, more and more software companies are beginning to support ActiveX, which is a happy thing for friends who like programming! Because we can easily call the external OCX file in the program to achieve complex functions, while in the BCB only a few ActiveX controls, most of us need to install ourselves, the following through the RealPlayer and Flash control installation and application, Let's learn how ActiveX components are used in BCB:

First, install, import ActiveX control

C + + Builder is very good at supporting ActiveX, we can easily import ActiveX controls in the system: Click 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 want in the list of controls above, and then click the "Install" button below. If the control list does not have it, then the control you are looking for is not registered in the system, it does not matter, we can click the "Add" button in your computer to find this OCX file after Install,c++ Builder will automatically register for it.

Understanding all methods of ActiveX controls

General ActiveX controls are not help files, in the C + + Builder IDE Environment we can only see its design period properties and events, then how to know its run-time 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 not be the case), Just open it and look at it at a glance! Of course, if you're under BCB6, you can double-click the name of the ActiveX control in the Code browser (the source Code Explorer) on the left half of the code editor in the programming Editor, and you'll see her header file in the right-hand area, and slowly realize it:

In addition, we must understand the meaning of various properties, methods and their parameters, it is necessary to program to try, for each want to understand the properties and methods to create a menu item, click on the InputBox input parameters to test the effect, you can also create a status bar to display the value of its related variables.

Iii. Examples of applications

There are a lot of popular ActiveX controls, here we take RealPlayer and flash controls as examples.

1. Use of RealPlayer controls

Now RealPlayer streaming media files with its powerful video compression ratio is gradually emerging. RealPlayer Plus player is also rightfully the preferred software for playing RealPlayer format files. Others in the good is also other people, in fact, we can use C + + Builder to create a fully meet their own requirements of the RealPlayer player. Below I will show you how to use BCB to complete your RealPlayer. You must have a RealPlayer plus player in your machine because we want to use its own ActiveX control.

First, we want to import the required ActiveX controls in C + + Builder. Click on the menu "Component→import ActiveX control ..." To open the Import ActiveX dialog box, in the Import ActiveX list box, we can see all registered Axctivex controls in Windows. Select the RealPlayer ActiveX control Library (Version 1.0) controls. Then click the "Install" button.

Back to the C + + Builder main interface, you will find a component named RealAudio added to the ActiveX tab in the VCL panel. Let's put it in the form first. However, by default, the RealAudio component does not have a video playback window, that is, only sound can be played. Me we just add the following code to the controls attribute of the RealAudio component:

Imagewindow,controlpanel,statusbar

(of which: Imagewindow, ControlPanel, StatusBar, respectively, display video playback window, control bar status bar)

After adding the code, we can see that the control's appearance has changed to the Video Playback window shape. Then set the Align property to alclient, so that the play window can change with the form changes, convenient for everyone to watch movie animation can be free to pull the playback window size.

Then, add the Timage component, Topendialog (Odgrealplay), Trealplayer (Radmyplayer) component to the form, and add two TButton (Btnopenclick,btnexitclick )。 Import your favorite pictures in the image so that the window is too single, two TButton one set to start, and one set to end. The name in parentheses is the name of the control's life in my application.

Double-click Btnopen to add the following code:

void __fastcall TForm1::btnOpenClick(TObject *Sender)
{
  if(odgRealplay->Execute())
        {
radMyPlayer->Source=odgRealplay->FileName
radMyPlayer->DoPlay();打开并启动播放器
}
}
    双击btnExit添加如下代码:
//---------------------------------------------------------------------------
void __fastcall TForm1::btnExitClick(TObject *Sender)
{
Close(); //终止程序运行
}

To make it easy for users to select files when opening a file, set the Odgreplayer Filter property as follows: All media files (*.rm,*.ram,*.ra,*.swf,*.mp3) |*.rm;*.ram;*.ra;*.swf;*.mp3 |*.*|*.*.

Click F9, find a song to listen to:

What are the other attributes and methods? Her properties are really very few, and most of the bool type, in addition to the above, basically there is nothing to let you do not use, the method is a lot, but not much, to her head file, you see it: P

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.