forked from chrisguo/beijing_fushengji
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DLGHTML.cpp
executable file
·141 lines (103 loc) · 2.83 KB
/
DLGHTML.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// DLGHTML.cpp: implementation of the CHtmlDialog class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <mshtmhst.h>
#include "DLGHTML.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CHtmlDialog::CHtmlDialog()
{
TRACE0("Warning: Initialization may not be done: Non Functional contructor");
}
CHtmlDialog::~CHtmlDialog()
{
//Free the Mshtml.dll
::FreeLibrary(m_hInstMSHTML);
}
CHtmlDialog::CHtmlDialog(UINT nResID, CWnd* pParent/*= NULL*/)
{
m_hWndParent = pParent ? pParent->GetSafeHwnd() : NULL;
CString strTemp;
strTemp.Format("%d", nResID);
ResourceToURL(strTemp);
CommonConstruct();
}
CHtmlDialog::CHtmlDialog(LPCTSTR lpszURL, BOOL bRes, CWnd* pParent/*= NULL*/)
{
m_hWndParent = pParent ? pParent->GetSafeHwnd() : NULL;
if (bRes)
{
ResourceToURL(lpszURL);
}
else
m_strURL = lpszURL;
CommonConstruct();
}
int CHtmlDialog::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))
return -1;
return 0;
}
void CHtmlDialog::CommonConstruct()
{
m_hInstMSHTML = ::LoadLibrary(TEXT("MSHTML.DLL"));
}
inline void CHtmlDialog::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 CHtmlDialog::SetParam(VARIANT *pvarArgs)
{
m_varArgs = pvarArgs;
}
void CHtmlDialog::SetParam(LPCTSTR lpszArgs)
{
m_varArgs = lpszArgs;
}
CString CHtmlDialog::GetReturnString()
{
ASSERT(m_varReturn.vt == VT_BSTR);
CString str = m_varReturn.bstrVal;
return str;
}
LPCVARIANT CHtmlDialog::GetReturnVariant()
{
return (LPCVARIANT)m_varReturn;
}
void CHtmlDialog::SetSize(int x, int y)
{
m_strOptions.Format("dialogWidth: %d; dialogHeight: %d", x, y);
}
void CHtmlDialog::SetDlgOptions(LPCTSTR lpszOptions)
{
m_strOptions = lpszOptions;
}