Activating ActiveX Controls
This topic contains the following sections.
- Affected Versions
- Understanding Control Activation
- Loading Interactive Controls Externally
- Programmatically Determining Whether a Control is Inactive
- Accessibility Impact
- WebBrowser Control Impact
- Appendix A: DHTML Events Blocked by Inactive Controls
For an introduction to the user experience, please see Internet Explorer 6: ActiveX Update.
For additional information regarding the platforms affected by this update, please see Internet Explorer ActiveX Update.
Affected Versions
The information in this article is now deprecated; it originally applied to the following versions of Internet Explorer.
- Microsoft Internet Explorer 6 in Windows XP Service Pack 2 (SP2)
- Internet Explorer 6 in Windows Server 2003 Service Pack 1 (SP1)
- Internet Explorer 6 in Windows Server 2003 Release 2 (R2)
- Internet Explorer 6 in Windows Server 2003 Service Pack 2 (SP2)
- Windows Internet Explorer 7 in Windows XP SP2
- Internet Explorer 7 in Windows Server 2003 SP1
- Internet Explorer 7 in Windows Server 2003 SP2
- Internet Explorer 7 on Windows Vista
When the April 2008 Internet Explorer Cumulative Update is applied to any of these versions, the behavior described in this article is removed from Internet Explorer. In addition, the update also affects applications hosting the WebBrowser Control.
Understanding Control Activation
Interactive controls are ActiveX controls that provide user interfaces. When a web page uses the APPLET, EMBED, or OBJECT elements to load an ActiveX control, the control's user interface is blocked until the user activates it. If a page uses these elements to load multiple controls, each interactive control must be individually activated.
When a control is inactive, the following effects occur.
-
Dynamic HTML (DHTML) events related to user interaction, such as onblur and onclick, are blocked. Appendix A lists the DHTML events that are blocked when a control is inactive.
-
The control does not respond to window messages generated by the keyboard or mouse, such as WM_CLICK and WM_KEYPRESS, and so on.
-
An overlay window, created on the control's OLE site, prevents keyboard and mouse messages from reaching the inactive control.
When an inactive control is created, Internet Explorer uses different techniques to prevent keyboard or mouse window messages from reaching the control. When the inactive control is a windowed control, such as the HTML Help Control, Internet Explorer uses the EnableWindow Function to disable the inactive control's window. When the user activates a windowed control, the same function activates the disabled window. When the inactive control is a windowless control, such as the Office Web Components, keyboard and mouse messages are filtered by the control's container.
When a control is inactive, it does not respond to user input; however, it does perform operations that do not involve interaction. If, for example, you open a web page that uses Microsoft Windows Media Player to play a music file, the music plays after the page loads. You cannot interact with Windows Media Player until the control's user interface is activated, as shown in the following figure.
.gif)
To activate an interactive control, either click it or use the TAB key to set focus on it and then press the SPACEBAR or the ENTER key. Interactive controls loaded from external script files immediately respond to user interaction and do not need to be activated.
Some windowed controls use Windows API functions, such as GetKeyState and GetCursorPos, to determine the state of the keyboard and mouse and then respond to the 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 loads. After loading, the control will not require activation. At present, the following controls have this behavior, but the vendors are working on new controls that would not have this behavior.
- Virtools (TM) Web Player from Virtools SA
- Macromedia Shockwave Player (TM) from Adobe Systems Inc.
- QuickTime (TM) from Apple Computer, Inc.
When loaded from external script files, these controls do not display a prompt.
The following screen shot shows the prompt dialog box.
.gif)
Loading Interactive Controls Externally
To create Web pages that load interactive controls that respond immediately to user input, use Microsoft JScript to load controls from external script files. You cannot write script elements inline with the main HTML page to load your control externally. If the script is written inline programmatically, for example with the writeln function, the loaded control will behave as if it was loaded by the HTML document itself and will require activation. To ensure a control is interactive when it is loaded, use one of the following techniques to load your control from an external file.
The following example uses document.write to load a control dynamically.
<!-- HTML File -->
<html>
<body leftmargin=0 topmargin=0 scroll=no>
<script src="docwrite.js"></script>
</body>
</html>
// docwrite.js
document.write('<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">');
document.write('<param name="URL" value="example.wmv">');
document.write('<param name="autoStart" value="-1"></object>');
External script files can also modify an element's outerHTML property to achieve the same effect, as shown in the following example.
<!-- HTML File -->
<html>
<body>
<div id="embedControlLocation">
<script src="embedControlOuterHTML.js"></script>
</div>
</body>
</html>
// outerhtml.js embedControlLocation.outerHTML = '<embed src="examplecontrol">';
The next example uses document.createElement to load an ActiveX control using the OBJECT element.
<!-- HTML File -->
<html>
<body>
<div id="DivID">
<script src="createElementExplicit.js"></script>
</div>
</body>
</html>
// createElementExplicit.js
var myObject = document.createElement('object');
DivID.appendChild(myObject);
myObject.width = "200";
myObject.height = "100";
myObject.classid= "clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6";
myObject.URL = "example.wmv";
myObject.uiMode = "none" ;
The next example uses innerHTML and a JScript function to load an ActiveX control while specifying parameter values.
<!-- HTML File -->
<html>
<head>
<script src="external_script.js" language="JScript"></script>
</head>
<body>
<div id="EXAMPLE_DIV_ID">
This text will be replaced by the control
</div>
<script language="JScript">
CreateControl( "EXAMPLE_DIV_ID",
"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6",
"EXAMPLE_OBJECT_ID", "600", "400", "example.wmv",
"-1")
</script>
</body>
</html>
// external_script.js
function CreateControl(DivID, CLSID, ObjectID,
WIDTH, HEIGHT, URL, AUTOSTART)
{
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 requires activation. To load a control without requiring activation, use one of the previous examples.
<!-- HTML File -->
<html>
<body>
<div id="embedControlLocation">
<script id="elementid" src="embedControl.js"></script>
</div>
</body>
</html>
// embedControl.js
document.writeln('<script>');
document.write('document.writeln(\'');
document.write( '<object classid =
"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
width="100" height="100" />');
document.write('\');');
document.writeln('</script>');
Programmatically Determining Whether a Control is Inactive
You cannot use JScript functions or server-side scripts to determine whether or not a control is active. Application hosting the web browser control cannot determine whether or not a control is active.
Controls can determine activation state via the DISPID_AMBIENT_UIDEAD ambient property by calling through IDispatch::Invoke. Controls that implement the IOleControl interface are notified when this property changes through IOleControl::OnAmbientPropertyChange.
Accessibility Impact
When accessibility tools encounter ActiveX controls, they can use the object's IAccessible interface to obtain information about the control. Inactive controls can be activated with the IAccessible::accDoDefaultAction method.
The following table describes the results when IAccessible methods are called on inactive controls.
| Method | Description |
|---|---|
| IAccessible::accDoDefaultAction | Activates the control and will expose the ActiveX control or Java Applet within the MSAA tree. |
| IAccessible::accHitTest | Returns CHILDID_SELF |
| IAccessible::accLocation | Location of the underlying ActiveX control or Java Applet |
| IAccessible::accNavigate | Returns E_NOTIMPL |
| IAccessible::accSelect | Returns E_NOTIMPL |
| IAccessible::get_accChild | Returns S_FALSE |
| IAccessible::get_accChildCount | Returns 0 and S_OK |
| IAccessible::get_accDefaultAction | Returns "Select this control" |
| IAccessible::get_accDescription | Returns E_NOTIMPL |
| IAccessible::get_accFocus | Returns E_NOTIMPL |
| IAccessible::get_accHelp | Returns "This control is inactive. Select the control to activate and use it." |
| IAccessible::get_accHelpTopic | No Change - Returns E_NOTIMPL |
| IAccessible::get_accKeyboardShortcut | No Change - Delegates the object. If there is no object, the method returns E_NOTIMPL. |
| IAccessible::get_accName | Returns "Inactive Control" |
| IAccessible::get_accParent | No Change - Returns the closest accessible element in the parent chain. |
| IAccessible::get_accRole | Returns ROLE_SYSTEM_PUSHBUTTON |
| IAccessible::get_accSelection | Returns E_NOTIMPL |
| IAccessible::get_accState | Returns current state of the object. This state always includes STATE_SYSTEM_FOCUSABLE |
| IAccessible::get_accValue | Returns E_NOTIMPL |
| IAccessible::put_accName | Returns E_NOTIMPL |
| IAccessible::put_accValue | Returns E_NOTIMPL |
For information on activated controls, or controls that do not require activation please see the Microsoft Active Accessibility SDK.
WebBrowser Control Impact
By default, custom applications hosting the WebBrowser Control do not block interactive ActiveX controls loaded by the APPLET, EMBED, or OBJECT elements.
Inactive control blocking only applies to the following applications.
- Windows Explorer
- Internet Explorer
- MSN Explorer
- AOL® Explorer
- AOL® 8.0
- AOL® 9.0
- CompuServe 2000
- AIM®
- NetCaptor
- Browse3D
- Macromedia Dreamweaver
- Macromedia Contribute
- Netscape® 8 (when using Internet Explorer as the rendering engine)
To match the behavior of Internet Explorer in your application, add the DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE flag to the dwFlags parameter of your DOCHOSTUIINFO structure, 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 your 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
Applications can register to incorporate ActiveX control activation by default. For more information, please engage your Technical Account Manager or contact Microsoft Product Support.
Appendix A: DHTML Events Blocked by Inactive Controls
The following table lists the DTHML events that are blocked when ActiveX controls are inactive.