Activating ActiveX Controls _javascript Tips

Source: Internet
Author: User
Tags activex update

Activating an ActiveX control

Release date: 2006-3-29 | update: 2006-3-29

Internet Development Index

Users cannot interact directly with Microsoft ActiveX controls loaded by applets, EMBED, or OBJECT elements. Users can interact with these controls after they activate the user interface for those controls. This article describes how Microsoft Internet Explorer handles ActiveX controls, shows how ActiveX controls can be loaded to activate their interfaces, and also describes how this behavior affects the application of accessibility tools and host WebBrowser controls.

This topic contains the following sections.

Content of this page

Understanding Control Activation
To load an interactive control externally
To programmatically determine whether a control is not activated
Auxiliary impact
WebBrowser Control Effects
Appendix A: DHTML events that are blocked by the control not activated

For additional information about the platform affected by this update, see Internet Explorer ActiveX update.

Understanding Control Activation

An interactive control is an ActiveX control that provides a user interface. When a Web page uses an APPLET,EMBED , or OBJECT element to load an ActiveX control, the user interface for that control is blocked until the user activates it. If a page uses these elements to load multiple controls, each interaction control must be activated separately.

If a control is not active, the following results appear.

Dynamic HTML (DHTML) events (such as onblur and onclick) associated with user interaction are blocked. Appendix A lists the DHTML events that are blocked when the control is not activated.

The control does not respond to keyboard or mouse-generated window messages, such as Wm_click, wm_keypress, and so on.

Overwriting a window (created in the control's OLE site) prevents keyboard and mouse messages from reaching an inactive control.

After you create an inactive control, Internet Explorer uses different techniques to prevent keyboard or mouse window messages from reaching the control. If an inactive control is a window-enabled control (such as an HTML help control), Internet Explorer uses the enablewindow function to disable the window for this inactive control. When a user activates a control with a window, the function activates the disabled window. If an inactive control is a windowless control, such as an Office Web component, the container for the control filters keyboard and mouse messages.

If a control is not activated, it does not respond to user input, but performs an interaction-independent operation. For example, if you open a Web page that uses a Microsoft Windows media Player to play music files, the page will not play music until it is loaded. You can interact with the Windows Media Player only after the user interface for the control is activated, as shown in the following illustration.


note Although controls are not activated to respond to any direct user interaction, they respond to script commands.

To activate an interactive control, you can click the control, or you can use the Tab key to set the focus on the control, and then press SPACEBAR or ENTER. An interactive control loaded from an external script can respond immediately to user interaction without activation.

Some controls with Windows use Windows API functions such as getkeystate and GetCursorPos to determine the state of the keyboard and mouse, and then respond to function results. For these controls only, a prompt appears before the control is run in Internet Explorer. To run the control, the user needs to click the button in the message window before the page is loaded. After loading, the control does not need to be activated. Currently, the following controls have this behavior, but the vendor is continuing to develop new controls that do not have the behavior.

Virtools™web Player from Virtools SA

Macromedia Shockwave Player™from Adobe Systems Inc.

Quicktime™from Apple Computer, Inc.

When loaded from an external script file, these controls do not display hints.

The following illustration shows the prompt dialog box.


Back to the top of the page

To load an interactive control externally

To create a Web page that loads an interactive control that responds to user input immediately, loads the control from an external script file using Microsoft JScript. You cannot write script elements that are inline with the main HTML page to load controls from outside. If the script is written inline (for example, with the writeln function), the loaded control needs to be activated as if it were loaded by the HTML document itself. To make sure that the control is interactive after loading, use any of the following techniques.

The following example uses document.write to dynamically load controls.

HTML File

The next example uses document. createelement Loads an ActiveX control that uses the OBJECT element.

important When you use createelement to load an Object element or Embed element to a Web page, be careful to create the element, initialize its properties, add the element to the page's DOM, and then create an ActiveX control to be loaded by the new element. For more information, see the createelement documentation.

HTML File

The next example uses the InnerHTML and JScript functions to load ActiveX controls, specifying parameter values.

HTML File
External_script.js
function CreateControl (divID, CLSID, ObjectID,
      WIDTH, HEIGHT, URL, AUTOSTART)
{ C20/>var d = document.getElementById (divID);
 d.innerhtml = 
 ' <object classid= ' + CLSID + ' id= ' + ObjectID + 
 ' width= ' + width + ' height= ' + height + ' >
 <param name= "url" value= ' + URL + ' >
 <param name= ' autostart ' value= ' + autostart + '/> ';
}

Because the next example uses the writeln function to insert the script into the original HTML document, the resulting control needs to be activated. To load a control that does not need to be activated, use one of the examples above.

HTML File

Warning If the Disable script debugging (Internet Explorer) option is not selected in the Advanced tab of the Internet options in Control Panel, controls created with these techniques still need to be activated.

Back to the top of the page

To programmatically determine whether a control is not activated

You cannot use a JScript function or a server-side script to determine whether a control is active. The application hosting the Web Browser Control cannot determine whether a control is active.

The control can determine the activation state through the Dispid_ambient_uidead ambient property, which is invoked by IDispatch::Invoke . When this property is changed through iolecontrol::onambientpropertychange , the control that implements the IOleControl interface is notified.

Back to the top of the page

Auxiliary impact

When an auxiliary tool encounters an ActiveX control, you can use the object's iaccessible interface to get information about the control. You can use the iaccessible::accdodefaultaction method to activate a control that is not active.

The following table describes the results generated by invoking the IAccessible method on an inactive control.

Method Description

Iaccessible::accdodefaultaction

Activates the control and exposes ActiveX controls or Java applets within the MSAA tree.

Iaccessible::acchittest

Back to Childid_self

Iaccessible::acclocation

The location of the underlying ActiveX control or Java Applet

Iaccessible::accnavigate

Back to E_NotImpl

Iaccessible::accselect

Back to E_NotImpl

Iaccessible::get_accchild

Back to S_FALSE

Iaccessible::get_accchildcount

return 0 and S_OK

Iaccessible::get_accdefaultaction

Returns "Select this control"

Iaccessible::get_accdescription

Back to E_NotImpl

Iaccessible::get_accfocus

Back to E_NotImpl

Iaccessible::get_acchelp

Returns the ' this control ' inactive. Select the control to activate and use it.

Iaccessible::get_acchelptopic

No change-return to E_NOTIMPL

Iaccessible::get_acckeyboardshortcut

No change-Delegate the object. If there are no objects, the method returns E_NOTIMPL.

IAccessible::get_accName

Return to "Inactive control"

Iaccessible::get_accparent

No change-Returns the most recent accessible element in the parent chain.

Iaccessible::get_accrole

Back to Role_system_pushbutton

Iaccessible::get_accselection

Back to E_NotImpl

Iaccessible::get_accstate

Returns the current state of an object. This state always includes state_system_focusable

Iaccessible::get_accvalue

Back to E_NotImpl

IAccessible::p ut_accname

Back to E_NotImpl

IAccessible::p Ut_accvalue

Back to E_NotImpl

For information about activated controls or controls that you do not need to activate, see the Active Accessibility SDK.

Note The utility should refresh after the default action is triggered to correctly display the data of the ActiveX control and its child controls, if any.

Back to the top of the page

WebBrowser Control Effects

By default, custom applications that host WebBrowser control do not block interactive ActiveX controls that are loaded by applets,EMBED , or OBJECT elements. The control is not activated to apply only to the following applications.

Windows Explorer

Internet Explorer

MSN Explorer

Aol®explorer

aol®8.0

aol®9.0

CompuServe 2000

Aim®

Maxthon Browser

Netcaptor

Browse3d

Macromedia Dreamweaver

Macromedia Contribute

Netscape®8 (when using Internet Explorer as a rendering engine)

To match the behavior of Internet Explorer in your application, add the Dochostuiflag_enable_activex_inactivate_mode flag to the dochostuiinfo structure of the dwflags parameter, as shown in the following example.

HRESULT GetHostInfo (dochostuiinfo *pinfo)
{
 ...
 pinfo->cbsize = sizeof (dochostuiinfo);
 Pinfo->dwflags = {Other dochostuiflags} | 
  Dochostuiflag_enable_activex_inactivate_mode; 
 ...
 return S_OK;
}

You can also enable interactive control blocking by adding the application's process name to the following registry key.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
feature_enable_activex_inactivate_mode
process_name.exe= (DWORD) 0x00000001

Note Because the user can modify the registry, the Dochostuiinfo flag is the preferred method of enabling interactive control blocking.

By default, an application can register to incorporate ActiveX control activation. For more information, consult your Technical Account manager or contact Microsoft's product support department.

Back to the top of the page

Appendix A: DHTML events that are blocked by the control not activated

The following table lists the DHTML events that are blocked when an ActiveX control is not activated.

OnActivate

OnDragLeave

onmouseout

Onbeforeactivate

OnDragOver

onmouseover

Onbeforecopy

Ondragstart

OnMouseUp

Onbeforecut

OnDrop

OnMouseWheel

Onbeforedeactivate

onfocus

OnMove

Onbeforepaste

Onfocusin

Onmoveend

Onblur

Onfocusout

Onmovestart

OnClick

OnHelp

OnPage

OnContextMenu

OnKeyDown

Onpaste

Oncontrolselect

onkeypress

OnResize

Oncopy

OnKeyUp

Onresizeend

Oncut

Onlosecapture

Onresizestart

OnDblClick

OnMouseDown

Onscroll

OnDeactivate

Onmouseenter

Onselectstart

Ondragend

OnMouseLeave

-

OnDragEnter

OnMouseMove

-

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.