扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
class CMshtmlDialog { public: void SetDlgOptions(LPCTSTR lpszOptions); void SetSize(int x, int y); LPCVARIANT GetReturnVariant(); CString GetReturnString(); void SetParam(LPCTSTR lpszArgs); void SetParam(VARIANT* pvarArgs); virtual int DoModal(); CMshtmlDialog(LPCTSTR lpszURL, BOOL bRes = FALSE, CWnd* pParent = NULL); CMshtmlDialog (UINT nResID, CWnd* pParent = NULL); CMshtmlDialog ( ); virtual ~ CMshtmlDialog( ); private: inline void ResourceToURL(LPCTSTR lpszURL); void CommonConstruct(); protected: HWND m_hWndParent; CString m_strOptions; COleVariant m_varArgs, m_varReturn; CString m_strURL; HINSTANCE m_hInstMSHTML; }; // CMshtmlDialog类的实现文件. CMshtmlDialog :: CMshtmlDialog () { TRACE0("Warning: Initialization may not be done: Non Functional contructor"); } CMshtmlDialog::~ CMshtmlDialog() { //释放Mshtml.dll ::FreeLibrary(m_hInstMSHTML); } CMshtmlDialog:: CMshtmlDialog(UINT nResID, CWnd* pParent/*= NULL*/) { m_hWndParent = pParent ? pParent-〉GetSafeHwnd() : NULL; CString strTemp; strTemp.Format("%d", nResID); ResourceToURL(strTemp); CommonConstruct(); } CMshtmlDialog::CMshtmlDialog(LPCTSTR lpszURL, BOOL bRes, CWnd* pParent/*= NULL*/) { m_hWndParent = pParent ? pParent-〉GetSafeHwnd() : NULL; if (bRes) { ResourceToURL(lpszURL); } else m_strURL = lpszURL; CommonConstruct(); } int CMshtmlDialog::DoModal() { //First get the proc ShowHTMLDialog SHOWHTMLDIALOGFN *pfnShowHTMLDialog; pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)GetProcAddress(m_hInstMSHTML, TEXT("ShowHTMLDialog")); if (!pfnShowHTMLDialog) return -1; //Now create a URL Moniker IMoniker* pmk = NULL; BSTR bstrURL = m_strURL.AllocSysString(); CreateURLMoniker(NULL, bstrURL, &pmk); if (!pmk) return -1; TCHAR* pchOptions = m_strOptions.IsEmpty() ? NULL : m_strOptions.GetBuffer(0); //Now show the HTML Dialog HRESULT hr = (*pfnShowHTMLDialog)(m_hWndParent, pmk, m_varArgs, pchOptions, m_varReturn); if (FAILED(hr))0 return -1; return 0; } void CMshtmlDialog::CommonConstruct() { m_hInstMSHTML = ::LoadLibrary(TEXT("MSHTML.DLL")); } inline void CMshtmlDialog::ResourceToURL(LPCTSTR lpszURL) { HINSTANCE hInstance = AfxGetResourceHandle(); ASSERT(hInstance != NULL); LPTSTR lpszModule = new TCHAR[_MAX_PATH]; if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH)) { m_strURL.Format(_T("res://%s/%s"), lpszModule, lpszURL); } delete []lpszModule; } void CMshtmlDialog::SetParam(VARIANT *pvarArgs) { m_varArgs = pvarArgs; } void CMshtmlDialog::SetParam(LPCTSTR lpszArgs) { m_varArgs = lpszArgs; } CString CMshtmlDialog::GetReturnString() { ASSERT(m_varReturn.vt == VT_BSTR); CString str = m_varReturn.bstrVal; return str; } LPCVARIANT CMshtmlDialog::GetReturnVariant() { return (LPCVARIANT)m_varReturn; } void CMshtmlDialog::SetSize(int x, int y) { m_strOptions.Format("dialogWidth: %d; dialogHeight: %d", x, y); } void CMshtmlDialog::SetDlgOptions(LPCTSTR lpszOptions) { m_strOptions = lpszOptions; } |
void CHDDemoApp::OnAppAbout() { CMshtmlDialog dlg(IDR_ABOUT_HTM, AfxGetMainWnd()); dlg.DoModal(); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者