I have been playing with this webbrowser control example
I got it working and added some timers using ON_WM_TIMER.
Now I would like to access the m_Browser (CWebBrowser class instance) defined inside the protected CMyBrowserView class into a different class. (for example CMyBrowserApp in the code sample) and use .Navigate and other functions.
How can I do this?
(im using vi开发者_开发百科sual studio 6 c++)
Create a subclass of CMyBrowserView and add a method for each of the things you want the browser to do. The method should call the appropriate method on m_Browser.
E.g.
class CBrowserViewEx : public CMyBrowserView
{
...
void Navigate(LPCTSTR URL, VARIANT* Flags,
VARIANT* TargetFrameName, VARIANT* PostData,
VARIANT* Headers)
{
m_Browser.Navigate(URL, Flags, TargetFrameName, PostData, Headers);
}
...
}
That way you can access the functionality from outside, but still limit who can do what with the browser control and you can add extra wrapper code (such as parameter checking) if you need to.
(Edit) Also note you'll need to change the code in MyBrowser.cpp to pass the new view name into the new CSingleDocTemplate, so MFC automatically creates your new view for you.
Possible solution is to add function CWebBrowser* GetBrowser() { return &m_BrowserView.m_Browser; }
to the CMyBrowserApp
class.
精彩评论