西晋有那些诗人:WinCE 界面开发:使用HTML Browser Control
来源:百度文库 编辑:九乡新闻网 时间:2024/04/20 10:00:47
http://blog.csdn.net/cheungmine/archive/2010/01/11/5176124.aspx by cheungmine 2010-1 在Win32平台上用 C++做界面开发确实是很吃力的活。无论使用MFC还是ATL或者WTL都是很痛苦的。通常引入HTML控件,可以做出类似网页效果的精美布局。在传统的Windows应用程序中使用Web控件已是大势所趋,大大简化工作量。但是在WinCE平台上,做同样的事情,往往遇到很多困难。我自己摸索了半天,总结出下面的方法,效果还是很好的。
首先,使用WTL(WTL8.0 with VS2005)创建Windows Mobile 6的程序,选择新建项目ceWtl->WTL Mobile Application Wizard。 Platforms选择:Windows Mobile 6 Professional SDK。 Application Type:默认。 User Interface Features:勾选Use a view window,view type 选择Html Browser Control。 按Finish。 我仅修改默认生成的CeWtlFrame.h文件如下://cheungmine{{我增加的部分 //cheungmine}} // CeWtlFrame.h : interface of the CCeWtlFrame class
//
/////////////////////////////////////////////////////////////////////////////#pragma once//cheungmine{{
/**
OLEMethod
OLEMethod receives 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 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 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 CFrameWindowImpl,
public CUpdateUI,
public CAppWindow,
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(CFrameWindowImpl::PreTranslateMessage(pMsg))
return TRUE; return m_view.IsWindow() ? m_view.PreTranslateMessage(pMsg) : FALSE;
}// CAppWindow operations
bool AppHibernate( bool bHibernate)
{
// Insert your code here or delete member if not relevant
return bHibernate;
} bool AppNewInstance( LPCTSTR lpstrCmdLine)
{
// Insert your code here or delete member if not relevant
return false;
} void AppSave()
{
CAppInfo info;
// Insert your code here
} virtual BOOL OnIdle()
{
UIUpdateToolBar();
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)
CHAIN_MSG_MAP(CUpdateUI)
CHAIN_MSG_MAP(CFrameWindowImpl)
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 NotifyHandler(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{{
// 文件选择对话框
m_view.AddHTML(L"");
//cheungmine}} return 0;
} LRESULT OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//cheungmine{{
HRESULT hr;
VARIANT varOut;
CComVariant varEmpty; // 取得 IWebBrowser2 接口
CComPtr spDispDoc;
m_view.GetDocumentDispatch(&spDispDoc);
ATLASSERT(spDispDoc); // 取得 IHTMLElementCollection 接口
varOut.vt = VT_DISPATCH;
varOut.pdispVal = 0;
hr = OLEMethod(DISPATCH_PROPERTYGET, &varOut, spDispDoc, L"all", 0);
ATLASSERT(hr==S_OK); CComPtr spElemColl;
spElemColl.Attach(varOut.pdispVal); // 取得指定ID的 IHTMLElement
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 spElem;
spElem.Attach(varOut.pdispVal); // 取得value属性, 存放到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;
}
}; 编译部署到设备,按Menu->New显示界面。选择一个文件,按Action,跟踪调试,可以看到一起如我们期望那样。例子代码下载地址: http://download.csdn.net/source/1984878 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cheungmine/archive/2010/01/11/5176124.aspx ( # )
首先,使用WTL(WTL8.0 with VS2005)创建Windows Mobile 6的程序,选择新建项目ceWtl->WTL Mobile Application Wizard。 Platforms选择:Windows Mobile 6 Professional SDK。 Application Type:默认。 User Interface Features:勾选Use a view window,view type 选择Html Browser Control。 按Finish。 我仅修改默认生成的CeWtlFrame.h文件如下://cheungmine{{我增加的部分 //cheungmine}} // CeWtlFrame.h : interface of the CCeWtlFrame class
//
/////////////////////////////////////////////////////////////////////////////#pragma once//cheungmine{{
/**
OLEMethod
OLEMethod receives 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 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
} // 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 CFrameWindowImpl
public CUpdateUI
public CAppWindow
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(CFrameWindowImpl
return TRUE; return m_view.IsWindow() ? m_view.PreTranslateMessage(pMsg) : FALSE;
}// CAppWindow operations
bool AppHibernate( bool bHibernate)
{
// Insert your code here or delete member if not relevant
return bHibernate;
} bool AppNewInstance( LPCTSTR lpstrCmdLine)
{
// Insert your code here or delete member if not relevant
return false;
} void AppSave()
{
CAppInfo info;
// Insert your code here
} virtual BOOL OnIdle()
{
UIUpdateToolBar();
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
CHAIN_MSG_MAP(CUpdateUI
CHAIN_MSG_MAP(CFrameWindowImpl
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 NotifyHandler(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{{
// 文件选择对话框
m_view.AddHTML(L"");
//cheungmine}} return 0;
} LRESULT OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//cheungmine{{
HRESULT hr;
VARIANT varOut;
CComVariant varEmpty; // 取得 IWebBrowser2 接口
CComPtr
m_view.GetDocumentDispatch(&spDispDoc);
ATLASSERT(spDispDoc); // 取得 IHTMLElementCollection 接口
varOut.vt = VT_DISPATCH;
varOut.pdispVal = 0;
hr = OLEMethod(DISPATCH_PROPERTYGET, &varOut, spDispDoc, L"all", 0);
ATLASSERT(hr==S_OK); CComPtr
spElemColl.Attach(varOut.pdispVal); // 取得指定ID的 IHTMLElement
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
spElem.Attach(varOut.pdispVal); // 取得value属性, 存放到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;
}
}; 编译部署到设备,按Menu->New显示界面。选择一个文件,按Action,跟踪调试,可以看到一起如我们期望那样。例子代码下载地址: http://download.csdn.net/source/1984878 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cheungmine/archive/2010/01/11/5176124.aspx ( # )
WinCE 界面开发:使用HTML Browser Control
MFC Grid Control(VC4.2以上、WinCE)
转WINCE学习方法 - WINCE系统定制开发
WinCE开发中Boot Loader的点点滴滴
用WTL构建HTML界面应用程序1
转WINCE学习方法 - WINCE系统定制开发 - 天嵌科技 ARM开发社区 TQ244...
WinCE下临界区CriticalSection使用
Tab?Control控件的详细使用
使用SkinMagic Toolkit美化界面
Android开发:安卓版QQ登陆界面
在 WordPress 的 HTML 编辑界面中添加 SyntaxHighlighter 按钮
Fedora14 英文界面使用中文输入法
Fedora14 英文界面使用中文输入法 f14
WinCE的编译系统 - 开发板教程专区 - 天嵌科技 ARM开发社区 TQ2440,SK...
使用Cache-Control和gzip提升tomcat应用性能(整理)
html在线编辑器使用教程
双核处理器ARM+DSP如何实现协同工作 - 嵌入式ARM-Wince开发的blog | ...
WinCE Display驱动开发介绍 - 驱动设计 - 技术中心 - 嵌入式在线 | w...
巧借WinCE BSP移植 嵌入式系统开发有捷径(dos启动)
取消Windows欢迎界面,使用默认用户进入Windows
网易博客如何使用HTML自定义代码
HTML语言 [网易博客使用技巧]
善领DSA一机多图设置及使用教程 | wince常用工具和软件
MFC中List Control控件的使用及实时显示系统时间的方法 发.