ActiveX control is a user interface component created using COM (Component Object Model) technology. ActiveX controls are small, fast, and powerful, and can simplify the process of integrating and reusing software components. This article discusses how to create ActiveX controls for Pocket Internet Explorer on the Pocket PC, and describes how to use ActiveX controls in Pocket Internet Explorer-based applications.
The following software is required to develop and use ActiveX controls on a Windows-driven device:
1. Microsoft Embedded Visual C + + 3.0
2. Microsoft Windows CE platform software development kit (SDK) for Pocket PC
3. Microsoft Windows CE services 2.2 or later
Visual c ++ provides three methods for creating ActiveX controls based on Windows CE devices:
The lowest degree of automation is to use the standard Windows CE Ole Application Programming Interface (API) instead of using the programming framework to write controls ).
With Active Template Library (ATL) for Windows CE, we strongly establish this method because it can get a smaller and faster control.
Microsoft Foundation Classes (MFC) for Windows CE is also feasible, but it is not covered in this article.
In this article, we will focus on How to Use ATL for Windows CE to develop small and lightweight controls for Pocket Internet Explorer.
ActiveX control using ATL
Using embedded Visual C ++ to create an ATL-based ActiveX control is very simple. Run Embedded Visual C ++ and Use atl com Appwizard to create a new project. Atl com Appwizard will create a good starting point for your ActiveX control.
Then, you need to add a COM Object to the project. Select Insert/new ATL Object (insert/create ATL Object) from the menu, select simple object (Simple Object), and name your ActiveX object.
That's all! You have just created a Pocket Internet Explorer ActiveX control! Although it does not perform any operation, this control can indeed be loaded on the Pocket Internet Explorer.
Let's look at how to add some functions to the ActiveX control.
Add User Interface
Using ATL to add the UI to the ActiveX Control "skeleton" is very simple. You only need to add two implementation methods defined by ATL and then draw your object.
Adding the following implementation method to an ActiveX object defines an ActiveX object as a control and defines an interface that allows the object to display itself directly without calling a program (iviewobject) transmit data objects. In addition, the iviewobject interface allows you to create and manage connections with the notification receiver so that the caller can obtain notifications of control changes.
Ccomcontrol <caxsamplectl>
Iviewobjecteximpl <caxsamplectl>
After adding these two implementation methods to the ActiveX control, you can overwrite the ondraw () method implemented by the ccomcontrol that the object just inherits.
In this example, the ActiveX control draws four circles in the customer window area allocated to the control (we will see how to create the control with the specified width and height later ). Hresult caxsamplectl: ondraw
Hresult caxsamplectl: ondraw
(
Atl_drawinfo & di
)
{
Rect rc = * (rect *) Di. prcbounds );
HDC = Di. hdcdraw;
Ellipse (HDC, 0, 0, (RC. Right/2), (RC. Bottom/2 ));
Ellipse (HDC, (RC. Right/2), 0, RC. Right, (RC. Bottom/2 ));
Ellipse (HDC, 0, (RC. Bottom/2), (RC. Right/2), RC. Bottom );
Ellipse (HDC, (RC. Right/2), (RC. Bottom/2), RC. Right, RC. Bottom );
Return s_ OK;
}
The ondraw () function is used to create a UI (User Interface) for the control ).
Get user input
The following implementation method is added to ActiveX objects to implement communication between the control and the Pocket Internet Explorer, so that the Pocket Internet Explorer can process window messages in the control and user interaction.
Iolecontrolimpl <caxsamplectl>
Ioleobjectimpl <caxsamplectl>
Ioleinplaceactiveobjectimpl <caxsamplectl>
Ioleinplaceobjectwindowlessimpl <caxsamplectl>
Through these implementation methods and message ing, You can process common window messages assigned to the ActiveX control. In this example, a function is used to indicate the time when the user clicks the control. First, we will define a message ing for wm_lbuttondown, and then create an onlbuttondown function, which will be called when you click the ActiveX control.
Begin_msg_map (caxsamplectl)
Message_handler (wm_lbuttondown, onlbuttondown)
Chain_msg_map (ccomcontrol <caxsamplectl>)
End_msg_map ()
Lresult onlbuttondown (uint umsg, wparam, lparam, bool & bhandled );
With this message ing, the control will be notified when you click the control. In this example, we will change the circle color when you click the control. For example, the circle is changed from Black (all 0) to white (all 1 ).
Lresult caxsamplectl: onlbuttondown
Lresult caxsamplectl: onlbuttondown
(
Uint umsg,
Wparam,
Lparam,
Bool & bhandled
)
{
Point Pt = {loword (lparam), hiword (lparam )};
Rect rcclient; getclientrect (& rcclient );
If (ptincircle (PT, 0, 0, (rcclient. Right/2), (rcclient. Bottom/2 )))
Put_fillcolor (~ M_crfillcolor );
Else
Messagebeep (0 );
Bhandled = true;
Return 0;
}
In the put_fillcolor () method, we send a view change notification to the container (Pocket Internet Explorer. This notification will allow Pocket Internet Explorer to update the display of the control (that is, re-paint ActiveX control ).
Stdmethodimp caxsamplectl: put_fillcolor
(
Colorref crfillcolor
)
{
If (fireonrequestedit (dispid_fillcolor) = s_false)
Return s_false;
M_crfillcolor = crfillcolor;
M_brequiressave = true;
Fireonchanged (dispid_fillcolor );
Fireviewchange ();
Sendondatachange (null );
Return s_ OK;
}
Access ActiveX control in Pocket Internet Explorer
Next, we will add support for accessing ActiveX control attributes and methods in scripts. Add the following ATL implementation method:
Idispatchimpl <iaxsamplectl, & iid_iaxsamplectl, & libid_axsamplelib>
Iprovideclassinfoimpl <& clsid_axsamplectl, & iid_iaxsamplectl>
Through these implementation methods, we can access the properties and methods of ActiveX controls in the Pocket Internet Explorer Script. But first we need to create an ActiveX Object in HTML.
Html provides a tag that allows you to create ActiveX controls in Pocket Internet Explorer.
<Object
Id = "axsample"
Classid = "CLSID: 546e636a-dd23-4e22-a6f7-07ad4cb96642"
Width = 100
Height = 100
>
</Object>
This control is created for the preceding labels and their attributes. It is identified by classid and the size is 100x100 pixels.
If the ActiveX control does not have a UI, you can create an instance and use the activexobject method to access the ActiveX control through JScript.
<Script language = scripting script?
VaR AX = new activexobject ("axsample. axsamplectl ");
?
</SCRIPT>
The creation of the activexobject dynamic control will implement some special interaction methods between the script code and the ActiveX control.
The following is an HTML code snippet. It changes the fillcolor (fill color) of the axsample ActiveX control when you click the HTML form button named "change fill color ).
<Script language = "jscript">
Function fillcolorchange ()
{
Axsample. fillcolor = 32000;
}
</SCRIPT>
<Form>
<Input type = "button" value = "change fill color" onclick = "fillcolorchange ()">
<Br>
</Form>
Tag of the processing object
The tag also provides an additional feature that allows you to set the default property values of the control when creating the control. Therefore, you do not need to create script code to preset properties (such as the fillcolor attribute in the example ).
This feature can only be obtained through the following ATL implementation:
Ipersistpropertybagimpl <caxsamplectl>
And Property map information
Begin_prop_map (caxsamplectl)
Prop_entry ("fillcolor", dispid_fillcolor, clsid_null)
End_prop_map ()
Adding this information to the ActiveX control allows you to set information in the tag to overwrite these default property values when creating the control.
For example, the following code sets the fillcolor attribute of the circle in the axsample control to black.
<Object
Id = "axsample"
Classid = "CLSID: 546e636a-dd23-4e22-a6f7-07ad4cb96642"
Width = 100
Height = 100
>
</Object>
Declare the control as "safe for scripting"
Pocket PC is the first Windows Device that implements ActiveX controls in Pocket Internet Explorer. Therefore, the browser will verify whether the control is secure for the script. The verification is implemented through the IObjectSafety interface. When creating a control, the Pocket Internet Explorer for Pocket PC calls QueryInterface on the control to obtain the IObjectSafety value.
If the control does not support this interface, the user will receive a prompt "this page may contain insecure controls. Do you want to enable this control ?" Dialog box.
IObjectSafety is implemented in ATL through iobjectsafetyimpl:
Iobjectsafetyimpl <caxsamplectl,
Interfacesafe_for_untrusted_caller |
Interfacesafe_for_untrusted_data>
In this example, we set general security options in the ActiveX control Creator:
M_dwcurrentsafety = interfacesafe_for_untrusted_caller
| Interfacesafe_for_untrusted_data;
This allows the control to be created and displayed without user intervention.
Get access to browser Object Model
During the creation of the ActiveX control, Pocket Internet Explorer calls the QueryInterface of the control to obtain the iobjectwithsite value. If the control supports this interface, Pocket Internet Explorer uses a pointer to the browser interface to call the setsite method. On the Pocket PC, Pocket Internet Explorer supports the ibrowser, ibrowser2, and browserevents Display Interfaces. Ibrowser
Ibrowser
Navigate
Refresh
Stop
Busy
Title
Locationurl
Isframe
Scrollstyle
Marginwidth
Marginheight
Framenavigate
Selectedcodepage
Ibrowser2
Layoutwidth
Layoutheight
Locationbaseurl
Cleartypeenabled
Cleartypeenabled
Scriptingenabled
Fittowindow
Showimages
Playsounds
Zoomlevel
_ Browserevents
Beforenavigate
Commandstatechange
Downloadbegin
Downloadcomplete
Navigatecomplete
Newwindow
Titlechange
Framebeforenavigate
Framenavigatecomplete
Onstatusbar
Distribution ActiveX Controls
After ActiveX controls are created, they can be used internally or distributed to third parties.
To use an activexate control internally, you only need to set the control to the runtime location and use regsvrce.exe to register ActiveX control on a Pocket PC device.
An installer is required for ActiveX controls used by third parties. The installer must register the control. The regsrvce.exe tool can register the activexc on the Pocket PC device. The regsvr32.exe tool can register ActiveX controls on the desktop system (generally, finished controls can be used on desktops and small devices ). Another option is to write the installer and register the control directly.
The installer provided with ActiveX should install the. dll (Dynamic Link Library) file of the control and the necessary distributable. DLL files in the Windows System directory. If some DLL files already exist on your machine, the installer will compare the versions of these DLL files. Only when the original dll version is earlier than the new dll version will it be overwritten. ActiveX controls can only be used in OLE container applications, so you do not need to distribute all Ole dynamic link library files with the control.
Summary
You can use the Active Template Library (ATL) for Windows CE to develop ActiveX controls and use the developed controls in Internet Explorer of the Pocket PC. Developing reusable code components for devices is a fast and powerful method. The components are small in size and fast in execution, and allow developers to expand their browser functions as needed.