C++,请问一下,这个类的作用是什么,那些代码是自动生成的
class ie_browser_dlg :
public CAxDialogImpl<ie_browser_dlg>,
public IDispEventImpl<IDC_EXPLORER,ie_browser_dlg>
{
typedef IDispEventImpl<IDC_EXPLORER,ie_browser_dlg> WebBrowser;
public:
ie_browser_dlg();
~ie_browser_dlg(void);
enum { IDD = IDD_DLG_BROWSER };
BEGIN_MSG_MAP(ie_browser_dlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
MESSAGE_HANDLER(WM_CTLCOLORDLG, OnCtlColor)
CHAIN_MSG_MAP(CAxDialogImpl<ie_browser_dlg>)
END_MSG_MAP()
BEGIN_SINK_MAP(ie_browser_dlg)
SINK_ENTRY(IDC_EXPLORER, DISPID_DOCUMENTCOMPLETE, DocumentCompleteExplorer)
END_SINK_MAP()
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCtlColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
void __stdcall DocumentCompleteExplorer(LPDISPATCH pDisp, VARIANT* URL);
// 用于管理回调的一些函数
ATL::CString GetHisMsgContent(LONG callbackId);
void PutHisMsgContent(const ATL::CString & content, int type);
LONG GetNextCallbackId();
int GetCallbackIdType(LONG callbackId);
virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
LONG m_plugincookie;
std::map<LONG, std::pair<ATL::CString , int> > m_hisSysMsg;
LONG m_pluginmsgid;
HACCEL m_hAccel;
// 工作台窗口是否打开标记, 插件应该根据工作台打开来显示不同的界面操作
// 屏蔽掉工作台关闭后无效的操作按钮, 比如插入聊天记录到输入框这些操作.
// 每次工作台打开, 再动态显示这些操作按钮.
bool m_eservice_maindlg_exist;
IWebBrowser2 *m_spWebBrowser;
public:
HRESULT QueryHost(REFIID iid, void** ppUnk);
inline HWND get_ax_wnd() {
return m_hAxWnd;
}
private:
void ReadUrlFromInitFile();
private:
void InitHostObj();
HRESULT CreateSimpleBrowser();
private:
TCHAR m_tszUrl[MAX_PATH + 1];
CComPtr<IWebBrowser2> m_pWeb2;
ATL::CString m_strDir;
CComObject<CSimpleHost> *m_pHost;
STR_VECT m_url_vect;
STRING m_strModulePath;
HWND m_hAxWnd;
CComPtr<Icpp_call_js_obj> m_spCallCppExternal;
};
这个类的作用是在一个对话框控件上显示一个能够嵌入在ActiveX宿主中的浏览器控件。
嗯,这个CreateSimpleBrowser函数的作用是什么
HRESULT ie_browser_dlg::CreateSimpleBrowser(void)
{
InitHostObj();
IDocHostUIHandlerDispatchPtr spDocHost = m_pHost;
if (spDocHost != NULL)
{
IAxWinHostWindowPtr ptrHostWindow;
HRESULT hr = QueryHost(IID_IAxWinHostWindow, (void**)&ptrHostWindow);
if (FAILED(hr))
return hr;
hr = ptrHostWindow->SetExternalUIHandler(spDocHost);
if (FAILED(hr))
return hr;
IObjectWithSitePtr ptrObjWithSite = ptrHostWindow;
if (ptrObjWithSite != NULL)
{
ptrObjWithSite->SetSite(spDocHost);
}
}
if ( m_pHost && m_spCallCppExternal == NULL) {
Ccpp_call_js_obj::CreateInstance( &m_spCallCppExternal );
m_pHost->m_spExternal = (IDispatch*)m_spCallCppExternal;
}
CAxWindow AxWin = GetDlgItem(IDC_EXPLORER);
AxWin.QueryControl(&m_pWeb2);
m_hAxWnd = AxWin.m_hWnd;
return S_OK;
}
这是它的源码
@newlist: 从它的函数名来看,是指新建一个简单的浏览器控件。但从代码来看,它只是对已经创建好的浏览器控件做了些设置,用于设置UI和页面样式。再调用 CAxWindow AxWin = GetDlgItem(IDC_EXPLORER); AxWin.QueryControl(&m_pWeb2); 之前,你必须首先创建它,不排除它是通过设计器拖了一个Shell.Explorer到对话框上。也可以用代码创建,如下:
HRESULT CreateWebBrowser(CAxWindow& axWindow) throw() { if(!axWindow.IsWindow()) { axWindow.Create(m_hWnd,RECT_NEWS,_T("Shell.Explorer"), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,NULL,IDC_EXPLORER);
if(!axWindow.IsWindow()) return S_FALSE; }
CComQIPtr<IWebBrowser2> spWebBrowser; if(FAILED(axWindow.QueryControl(&spWebBrowser))) { // 这里代码是永远都不会执行的。 if(FAILED(axWindow.CreateControlEx( L"Shell.Explorer", NULL, NULL, (IUnknown **)(&spWebBrowser), DIID_DWebBrowserEvents2, (IUnknown*)(IDispEventImpl<IDC_EXPLORER,CMainDlg,&DIID_DWebBrowserEvents2,&LIBID_SHDocVw>*)this))) return S_FALSE; }
CComPtr<IAxWinAmbientDispatch> spHost; if(FAILED(axWindow.QueryHost(IID_IAxWinAmbientDispatch,(void **)&spHost))) return S_FALSE;
HRESULT hr = spHost->put_DocHostFlags( DOCHOSTUIFLAG_SCROLL_NO | DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_NO3DOUTERBORDER | DOCHOSTUIFLAG_NO3DBORDER);
if(hr != S_OK) ::MessageBox(NULL,AtlGetErrorDescription(hr),ADP::pszTitle,MB_OK | MB_ICONWARNING);
return hr; }