Wince interface development: Use HTML browser control

Source: Internet
Author: User

Wince interface development: Use HTML viewer Control

By cheungmine 2010-1

It is really hard to use C ++ for interface development on the Win32 platform. Whether using MFC, ATL, or wtl, it is very painful. HTML controls are usually introduced to make beautiful la s similar to webpage effects. Using Web controls in traditional Windows applications is the trend of the times, greatly simplifying the workload. However, on the wince platform, it is often difficult to do the same thing. After exploring for a long time, I summed up the following methods. The results are still very good.


First, use wtl (wtl8.0 with vs2005) to create a Windows Mobile 6 program, and select the new project cewtl-> wtl Mobile Application Wizard.

Platforms: Windows Mobile 6 Professional SDK.

Application Type: default.

User interface features: Select use a View window and select HTML browser control for view type.

Press finish.

 

I only modify the default generated cewtlframe. h file as follows:

// Cheungmine {{

What I added

// Cheungmine }}

 

// Cewtlframe. h: interface of the ccewtlframe class
//
//////////////////////////////////////// /////////////////////////////////////

# Pragma once

// Cheungmine {{
/**
Olemethod
Olemethod parameters es variable parameters. I. e., you can pass any number of parameters
Depending on the property/method. Following is a summary of the olemethod () parameters,
* Ntype-type of call to make, which can be any of the following values:
Dispatch_propertyput-set property value
Dispatch_propertyget-Get property value
Dispatch_method-call a method
* Pvresult-return value for the call made; it can be another idispatch object,
Or an integer value, or a Boolean, or so on ..
* Pdisp-idispatch interface object for which the call is to be made.
* Ptname-property or method name.
* Cargs-number of arguments followed after this parameter.
*... Parameters in reverse order for the call (it can be values of a property, or
Parameters of a method for the idispatch object ).

See also:
MS office OLE automation using C ++ by Naren neelamegam
A simple guide to automate MS word and MS Excel using C ++.

Http://www.codeproject.com/KB/office/MSOfficeAuto.aspx
*/
Static hresult olemethod (INT ntype,
Variant * pvresult,
Idispatch * Pdisp,
Lpolestr ptname,
Int cargs ...)
{
If (! Pdisp) return e_fail;

Va_list marker;
Va_start (Marker, cargs );

Dispparams dp = {null, null, 0, 0 };
Dispid dispidnamed = dispid_propertyput;
Dispid;
Char szname [200];

// Convert down to ANSI
Widechartomultibyte (cp_acp, 0, ptname,-1, szname, 256, null, null );

// Get dispid for name passed...
Hresult hR = Pdisp-> getidsofnames (iid_null, & ptname, 1,
Locale_user_default, & dispid );
If (failed (HR )){
Return hr;
}
// Allocate memory for arguments...
Variant * pargs = new variant [cargs + 1];
// Extract arguments...
For (INT I = 0; I <cargs; I ++ ){
Pargs [I] = va_arg (Marker, variant );
}

// Build dispparams
DP. cargs = cargs;
DP. rgvarg = pargs;

// Handle special-case for property-puts!
If (ntype & dispatch_propertyput ){
DP. cnamedargs = 1;
DP. rgdispidnamedargs = & dispidnamed;
}

// Make the call!
HR = Pdisp-> invoke (dispid, iid_null, locale_system_default,
Ntype, & DP, pvresult, null, null );
If (failed (HR )){
Return hr;
}

// End variable-argument section...
Va_end (Marker );
Delete [] pargs;
Return hr;
}
// Cheungmine }}

Class ccewtlframe:
Public cframeworkwimpl <ccewtlframe>,
Public cupdateui <ccewtlframe>,
Public cappwindow <ccewtlframe>,
Public cmessagefilter, public cidlehandler
{
Public:
Declare_app_frame_class (null, idr_mainframe, l "software // wtl // cewtl ")

Ccewtlview m_view;

Virtual bool pretranslatemessage (MSG * PMSG)
{
If (cframeworkwimpl <ccewtlframe>: pretranslatemessage (PMSG ))
Return true;

Return m_view.iswindow ()? M_view.pretranslatemessage (PMSG): false;
}

// Cappwindow operations
Bool apphib.pdf (bool bhibernate)
{
// Insert your code here or delete member if not relevant
Return bhibernate;
}

Bool appnewinstance (maid)
{
// Insert your code here or delete member if not relevant
Return false;
}

Void appsave ()
{
Cappinfo Info;
// Insert your code here
}

Virtual bool onidle ()
{
Uiupdatemedilbar ();
Return false;
}

Begin_update_ui_map (ccewtlframe)
End_update_ui_map ()

Begin_msg_map (ccewtlframe)
Message_handler (wm_create, oncreate)
Command_id_handler (id_app_exit, onfileexit)
Command_id_handler (id_file_new, onfilenew)
Command_id_handler (id_action, onaction)
Command_id_handler (id_app_about, onappabout)
Chain_msg_map (cappwindow <ccewtlframe>)
Chain_msg_map (cupdateui <ccewtlframe>)
Chain_msg_map (cframeworkwimpl <ccewtlframe>)
End_msg_map ()

// Handler prototypes (uncomment arguments if needed ):
// Lresult messagehandler (uint/* umsg */, wparam/* wparam */, lparam/* lparam */, bool &/* bhandled */)
// Lresult commandhandler (word/* wnotifycode */, word/* WID */, hwnd/* hwndctl */, bool &/* bhandled */)
// Lresult policyhandler (INT/* idctrl */, lpnmhdr/* pnmh */, bool &/* bhandled */)

Lresult oncreate (uint/* umsg */, wparam/* wparam */, lparam/* lparam */, bool &/* bhandled */)
{
Cappinfo Info;

Createsimplecemenubar ();
Uiaddtoolbar (m_hwndcecommandbar );

M_hwndclient = m_view.create (m_hwnd, rcdefault, null, ws_child | ws_visible | ws_clipsiblings | ws_clipchildren | hs_contextmenu );

// Register object for message filtering and idle updates
Cmessageloop * ploop = _ module. getmessageloop ();
Atlassert (ploop! = NULL );
Ploop-> addmessagefilter (this );
Ploop-> addidlehandler (this );

Return 0;
}

Lresult onfileexit (word/* wnotifycode */, word/* WID */, hwnd/* hwndctl */, bool &/* bhandled */)
{
Postmessage (wm_close );
Return 0;
}

Lresult onfilenew (word/* wnotifycode */, word/* WID */, hwnd/* hwndctl */, bool &/* bhandled */)
{
// Todo: Add code to initialize document

// Cheungmine {{
// File selection dialog box
M_view.addhtml (L "<input id =/" pathfile/"type =/" file/"/> ");
// Cheungmine }}

Return 0;
}

Lresult onaction (word/* wnotifycode */, word/* WID */, hwnd/* hwndctl */, bool &/* bhandled */)
{
// Cheungmine {{
Hresult hr;
Variant varout;
Ccomvariant varempty;

// Obtain the iwebbrowser2 Interface
Ccomptr <idispatch> spdispdoc;
M_view.getdocumentdispatch (& spdispdoc );
Atlassert (spdispdoc );

// Obtain the ihtmlelementcollection Interface
Varout. Vt = vt_dispatch;
Varout. pdispval = 0;
HR = olemethod (dispatch_propertyget, & varout, spdispdoc, l "all", 0 );
Atlassert (hR = s_ OK );

Ccomptr <idispatch> spelemcoll;
Spelemcoll. Attach (varout. pdispval );

// Obtain the ihtmlelement with the specified ID
Varout. Vt = vt_dispatch;
Varout. pdispval = 0;
Ccombstr bstrpathfile (L "pathfile ");
Variant name;
Name. Vt = vt_bstr;
Name. bstrval = bstrpathfile. m_str;
HR = olemethod (dispatch_method, & varout, spelemcoll, l "item", 1, name );
Atlassert (hR = s_ OK );

Ccomptr <idispatch> spelem;
Spelem. Attach (varout. pdispval );

// Obtain the value attribute and store it in bstrpathfile
Varout. Vt = vt_bstr;
Varout. bstrval = 0;
HR = olemethod (dispatch_propertyget, & varout, spelem, l "value", 0 );
Atlassert (hR = s_ OK & varout. Vt = vt_bstr );
Bstrpathfile. Empty ();
Bstrpathfile. Attach (varout. bstrval );

MessageBox (
Bstrpathfile
);
// Cheungmine }}


Return 0;
}

Lresult onappabout (word/* wnotifycode */, word/* WID */, hwnd/* hwndctl */, bool &/* bhandled */)
{
Caboutdlg DLG;
DLG. domodal ();
Return 0;
}
};

 

Compile and deploy the package to the device, and press menu> New to display the page. Select a file, follow action, and trace debugging. We can see that the file is as expected.

Sample Code:

 

Http://download.csdn.net/source/1984878

 

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.