CWebBrowser2 ctrl provide two method to link a web page:
Navigate2(VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
Navigate(LPCTSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
My requirement is very simple, give a link: such as www.sina.com, navigate to web page.
At first, I use method Navigate because it is easy to use.
But sometimes I find that it get a error page while I can link the web page with other browser.
After a long time research, I can not find a good solution, then I found the method Navigate2. I wrote a method to rope it as follow:
Compare the implements:
I find that they invoked different dwDispID of InvokeHelper , get the explain from MSDN:
Who can tell me what's the differents of
0x1f4 between
0x68?
Navigate2(VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
Navigate(LPCTSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
My requirement is very simple, give a link: such as www.sina.com, navigate to web page.
At first, I use method Navigate because it is easy to use.
But sometimes I find that it get a error page while I can link the web page with other browser.
After a long time research, I can not find a good solution, then I found the method Navigate2. I wrote a method to rope it as follow:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
void
Navigate2(CString szHtmlUrl)
2 {
3 try
4 {
5 VARIANT vFlags = {VT_I4, navNoReadFromCache};
6 VARIANT vUrl;
7 VariantInit( & vUrl);
8 BSTR bstrUrl = szHtmlUrl.AllocSysString();
9 vUrl.vt = VT_BSTR;
10 vUrl.bstrVal = bstrUrl;
11 m_web.Navigate2( & vUrl, & vFlags, NULL, NULL, NULL); // refresh top browser's content
12 g_Logger.Add(LOGLEVEL_FYI, _T( " Navigate2TopBanner, Top link Url: %s " ), szHtmlUrl);
13 ::SysFreeString(bstrUrl);
14 }
15 catch ( ){}
16 }
It works well....
2 {
3 try
4 {
5 VARIANT vFlags = {VT_I4, navNoReadFromCache};
6 VARIANT vUrl;
7 VariantInit( & vUrl);
8 BSTR bstrUrl = szHtmlUrl.AllocSysString();
9 vUrl.vt = VT_BSTR;
10 vUrl.bstrVal = bstrUrl;
11 m_web.Navigate2( & vUrl, & vFlags, NULL, NULL, NULL); // refresh top browser's content
12 g_Logger.Add(LOGLEVEL_FYI, _T( " Navigate2TopBanner, Top link Url: %s " ), szHtmlUrl);
13 ::SysFreeString(bstrUrl);
14 }
15 catch ( ){}
16 }
Compare the implements:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
void
CWebBrowser2::Navigate(LPCTSTR URL, VARIANT
*
Flags, VARIANT
*
TargetFrameName, VARIANT
*
PostData, VARIANT
*
Headers)
2 {
3 static BYTE parms[] =
4 VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
5 InvokeHelper( 0x68 , DISPATCH_METHOD, VT_EMPTY, NULL, parms,
6 URL, Flags, TargetFrameName, PostData, Headers);
7 }
2 {
3 static BYTE parms[] =
4 VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
5 InvokeHelper( 0x68 , DISPATCH_METHOD, VT_EMPTY, NULL, parms,
6 URL, Flags, TargetFrameName, PostData, Headers);
7 }
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
void
CWebBrowser2::Navigate2(VARIANT
*
URL, VARIANT
*
Flags, VARIANT
*
TargetFrameName, VARIANT
*
PostData, VARIANT
*
Headers)
2 {
3 static BYTE parms[] =
4 VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
5 InvokeHelper( 0x1f4 , DISPATCH_METHOD, VT_EMPTY, NULL, parms,
6 URL, Flags, TargetFrameName, PostData, Headers);
7 }
2 {
3 static BYTE parms[] =
4 VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
5 InvokeHelper( 0x1f4 , DISPATCH_METHOD, VT_EMPTY, NULL, parms,
6 URL, Flags, TargetFrameName, PostData, Headers);
7 }
I find that they invoked different dwDispID of InvokeHelper , get the explain from MSDN:
Parameters
dwDispID
Identifies the method or property to be invoked.
Identifies the method or property to be invoked.