Sei sulla pagina 1di 13

12/10/2016

WTLBrowserCodeProject

Not quite what you are looking for? You may want to try:
Embedding a Chromium browser in an MFC application
Using HTML as UI Elements in a WinForms Application with Chrome / Chromium Embedded Framework CEF
12,634,788 members 27,457 online

articles

Q&A

forums

highlights off
Member 11096340

lounge

666 Sign out

embeddingachromiumbrowserinanmfc6.0

WTL Browser
Gilad Novik, 24 May 2004

Rate:

4.68 23 votes
How to create a simple browser using IE engine and WTL.

Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long
time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again.
Alternatively, you can update your subscriptions.

Download source files 68.9 Kb


Download demo project 46.9 Kb

Introduction
This tutorial will help you build a mini browser using IE engine. It is based on WTL and uses a wrapper class which I've wrote for handling IWebBrowser2 interface.
Since I know it can be hard to read code, this tutorial will help you develop a mini browser step by step.

Background
Most of my projects are related to internet browsing. I'm using SDI with HTML view a lot of time. Sometimes, I need to use real browser capabilities, so I've written a
wrapper for IWebBrowser2. This wrapper class can handle a window which is embedded in IE. It can also handle events sinking in a very easy way for example:
OnDocumentComplete.

Creating a new project


We first start by creating a new WTL project. I assume you have WTL files installed if not, check here. On the first wizard screen, select an SDI application and check for
generating .CPP files.

https://www.codeproject.com/Articles/7147/WTLBrowser

1/13

12/10/2016

WTLBrowserCodeProject

On the second screen, change the default view to an HTML view.

First step will be to edit stdafx.h. Please include atlmisc.h we'll use CString from time to time and atlctrlx.h for CMultiPaneStatusBarCtrl. We also need to
comment out the _ATL_DLL definition we don't want our executable to depend on atl.dll and to change IE version to version 5.
Hide Copy Code

//Changethesevaluestousedifferentversions
#defineWINVER0x0400
//#define_WIN32_WINNT0x0400
#define_WIN32_IE0x0500
#define_RICHEDIT_VER0x0100
//ThisisrequiredforhostingbrowserinATL7
//#define_ATL_DLL
#include<atlbase.h>
#include<atlapp.h>
externCAppModule_Module;
#include<atlcom.h>
#include<atlhost.h>
#include<atlwin.h>
#include<atlctl.h>
#include<atlmisc.h>
#include<atlframe.h>
#include<atlctrls.h>
#include<atldlgs.h>
#include<atlctrlw.h>
#include<atlctrlx.h>
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditional
//declarationsimmediatelybeforethepreviousline.

Updating the view


In out view class, we need to include browser.h and inherit the view class from it. We also need to chain it to the message map so the class can handle several messages
WM_CREATE, WM_DESTROY.
Hide Copy Code

#include"browser.h"
classCWTLBrowserView:publicCWindowImpl<CWTLBrowserView,
CAxWindow>,publicCWebBrowser2<CWTLBrowserView>
{
public:
DECLARE_WND_SUPERCLASS(NULL,CAxWindow::GetWndClassName())

https://www.codeproject.com/Articles/7147/WTLBrowser

2/13

12/10/2016

WTLBrowserCodeProject

BOOLPreTranslateMessage(MSG*pMsg);
BEGIN_MSG_MAP(CWTLBrowserView)
CHAIN_MSG_MAP(CWebBrowser2<CWTLBrowserView>)
END_MSG_MAP()
//Handlerprototypes(uncommentargumentsifneeded):
//LRESULTMessageHandler(UINT/*uMsg*/,WPARAM/*wParam*/,
//LPARAM/*lParam*/,BOOL&/*bHandled*/)
//LRESULTCommandHandler(WORD/*wNotifyCode*/,
//WORD/*wID*/,HWND/*hWndCtl*/,BOOL&/*bHandled*/)
//LRESULTNotifyHandler(int/*idCtrl*/,
//LPNMHDR/*pnmh*/,BOOL&/*bHandled*/)
};

Creating the menu


We need to add some new items to the menu. A typical browser handles back, forward, home, stop and refresh. We'll add those commands to the menu and the
toolbar.

Since some of the items aren't allowed from time to time, we need to handle their UI we can't always use back and forward. First, we need to add them to the UI
update map in mainfrm.h.
Hide Copy Code

UPDATE_ELEMENT(ID_VIEW_GOTO_BACK,UPDUI_MENUPOPUP|UPDUI_TOOLBAR)
UPDATE_ELEMENT(ID_VIEW_GOTO_FORWARD,UPDUI_MENUPOPUP|UPDUI_TOOLBAR)
We update them via the OnIdle function.
Hide Copy Code

UIEnable(ID_VIEW_GOTO_BACK,m_view.CanBack());
UIEnable(ID_VIEW_GOTO_FORWARD,m_view.CanForward());

CWebBrowser2 exposes 2 functions CanBack & CanForward which can determine the status of the back and forward actions.
Since the default wizard starts on microsoft.com, we need to change the code to about:blank, and start on the normal home page. We need to change the code in
CMainFrame::OnCreate.
Hide Copy Code

m_hWndClient=m_view.Create(m_hWnd,rcDefault,
_T("about:blank"),
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|
WS_HSCROLL|WS_VSCROLL,WS_EX_CLIENTEDGE);
.
.
.
m_view.GoHome();
return0;

Creating the address bar


We now have a working framework, but we still can't enter any URL there! To solve the problem, we'll create an address bar, so the user can enter a URL for navigating.
We'll add a new member variable CEdit to our mainframe class called m_URL. We'll create and initialize it from CMainFrame::OnCreate. Since we also want
auto completion for our address bar, we'll use SHAutoComplete function on the edit control.
Hide Copy Code

CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar,NULL,TRUE);
CStringszAddress;
szAddress.LoadString(IDS_ADDRESS);
m_URL.Create(m_hWnd,CRect(0,0,0,18),NULL,WS_CHILD|WS_VISIBLE,WS_EX_STATICEDGE);
AddSimpleReBarBand(m_URL,szAddress.GetBuffer(0),TRUE);
m_URL.SetFont(AtlGetDefaultGuiFont());
SHAutoComplete(m_URL,SHACF_URLALL);
CreateSimpleStatusBar();
If we try to compile the project, we'll get an error while linking the files. This error occurs since SHAutoComplete is exported from shlwapi.dll. To solve it, we need to
add the library shlwapi.lib to our project.

https://www.codeproject.com/Articles/7147/WTLBrowser

3/13

12/10/2016

WTLBrowserCodeProject

After compiling the project, we'll see our new bar waiting for us to type in. But hey! If we try to press the Enter key, our browser would just keep sleeping! Let's fix it!

Navigating
Since the HTML framework forwards all keystrokes to the HTML document, we can't just wait for the WM_CHAR message. We need to add some code to the
PreTranslateMessage function. We need to grab the WM_CHAR message from the address bar and handle the VK_RETURN character.
Hide Copy Code

BOOLCMainFrame::PreTranslateMessage(MSG*pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
returnTRUE;
if(pMsg>message==WM_CHAR&&m_URL==pMsg>hwnd)
{
switch(pMsg>wParam)
{
caseVK_RETURN:
{
CStringszURL;
intnLength=m_URL.GetWindowTextLength();
m_URL.GetWindowText(szURL.GetBuffer(nLength),nLength+1);
szURL.ReleaseBuffer();
m_view.Navigate(szURL);
returnTRUE;
}
}
returnFALSE;
}
returnm_view.PreTranslateMessage(pMsg);
}

Commands
We can now enter a URL and watch our browser navigate it. But something is still missing. Why can't we use back, forward and the rest of our new commands? We
need to add their functions to our mainframe class since there is nothing special there, simply check the source code to see how it's done.

UI Tweaks
Let's test our browser. Try to go to http://www.codeproject.com/ and click on the WTL section. Why can't we see the new location in our address bar? To fix it, we need
to update the address bar each time our location changes. A good place is to handle the OnNavigateComplete2 from our view class. Since we need to update
m_URL which resides inside the mainframe class, we'll create a new reference to it inside our view class and pass the variable on the constructor. We now can handle
our message and update the address bar.
Hide Copy Code

voidCWTLBrowserView::OnNavigateComplete2(IDispatch*pDisp,constString&szURL)
{
m_URL.SetWindowText(GetLocationURL());
}
Another useful tweak includes a progress notification, secured icon, and status bar text. They all reside on the status bar. It's time to bring our big guns
CMultiPaneStatusBarCtrl! We'll create a new variable inside the mainframe class, plus a reference inside our view class. The status bar should contain 3 parts:
the default text, a secured icon, and a progress notification. Since the default text has a unique id ID_DEFAULT_PANE, all we need to do is to create additional two
identifiers. From the "View>Resource Symbols" menu, we need to create our new symbols: IDR_LOCK and IDR_PROGRESS. After creating them, we can initialize our
new status bar from the CMainFrame::OnCreate function.
Hide Copy Code

CreateSimpleStatusBar();
m_StatusBar.SubclassWindow(m_hWndStatusBar);
intnPanes[]={ID_DEFAULT_PANE,IDR_LOCK,IDR_PROGRESS};
m_StatusBar.SetPanes(nPanes,sizeof(nPanes)/sizeof(int),false);
m_StatusBar.SetPaneWidth(IDR_LOCK,30);
m_StatusBar.SetPaneWidth(IDR_PROGRESS,50);
We also need to add a new icon to our project IDI_LOCK and load it into a variable m_hSecured. To handle proper UI updating, we'll add a new line to the UI
update map:
Hide Copy Code

UPDATE_ELEMENT(0,UPDUI_STATUSBAR)

https://www.codeproject.com/Articles/7147/WTLBrowser

4/13

12/10/2016

WTLBrowserCodeProject

In our view class, we'll add a new variable m_bSecured and some code to handle our status bar updates:
Hide Copy Code

voidCWTLBrowserView::OnStatusTextChange(constString&szText)
{
m_StatusBar.SetPaneText(ID_DEFAULT_PANE,szText);
}
voidCWTLBrowserView::OnProgressChange(longnProgress,longnProgressMax)
{
CStringszText;
if(nProgressMax>0)
szText.Format(_T("%d%%"),nProgress*100/nProgressMax);
m_StatusBar.SetPaneText(IDR_PROGRESS,szText);
}
voidCWTLBrowserView::OnSetSecureLockIcon(longnSecureLockIcon)
{
m_bSecured=nSecureLockIcon>0;
}
Finally, we need to add some code to CMainFrame::OnIdle:
Hide Copy Code

m_StatusBar.SetPaneIcon(IDR_LOCK,m_view.IsSecured()?m_hSecured:NULL);
UIUpdateToolBar();
UIUpdateStatusBar();
returnFALSE;

File Command
To allow the browser to save and print files, we need to handle file messages. To send a command to the browser, we need to use the ExecWB function. To query a
command status for the UI map, we can use the QueryStatusWB function. We need to add the proper functions for saving/printing, update the UI update map
and handle their UI from the OnIdle function. Since it is fairly simple, I won't include it in the article check the source code for more details.

Edit Command
Edit commands are a special case. Since they can be used with the browser, as well as with our address bar, we need to check our focus window each time we use those
commands. First, we add them to the UI update map, then we handle their update via the OnIdle function:
Hide Copy Code

if(GetFocus()==m_URL)
{
DWORDdwSelection=m_URL.GetSel();
BOOLbEnable=HIWORD(dwSelection)!=LOWORD(dwSelection);
UIEnable(ID_EDIT_CUT,bEnable);
UIEnable(ID_EDIT_COPY,bEnable);
if(m_URL.OpenClipboard())
{
UIEnable(ID_EDIT_PASTE,IsClipboardFormatAvailable(CF_TEXT));
CloseClipboard();
}
else
UIEnable(ID_EDIT_PASTE,FALSE);
UIEnable(ID_EDIT_UNDO,m_URL.CanUndo());
}
else
{
UIEnable(ID_EDIT_CUT,m_view.QueryStatusWB(OLECMDID_CUT)&OLECMDF_ENABLED);
UIEnable(ID_EDIT_COPY,m_view.QueryStatusWB(OLECMDID_COPY)&OLECMDF_ENABLED);
UIEnable(ID_EDIT_PASTE,m_view.QueryStatusWB(OLECMDID_PASTE)&OLECMDF_ENABLED);
UIEnable(ID_EDIT_UNDO,m_view.QueryStatusWB(OLECMDID_UNDO)&OLECMDF_ENABLED);
}
We also need to distinguish them while executing the actual commands:
Hide Shrink

Copy Code

LRESULTCMainFrame::OnEditCut(WORD/*wNotifyCode*/,
WORD/*wID*/,HWND/*hWndCtl*/,BOOL&/*bHandled*/)
{
if(GetFocus()==m_URL)
m_URL.Cut();
else
m_view.ExecWB(OLECMDID_CUT,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
return0;
}
LRESULTCMainFrame::OnEditCopy(WORD/*wNotifyCode*/,
WORD/*wID*/,HWND/*hWndCtl*/,BOOL&/*bHandled*/)
{
if(GetFocus()==m_URL)
m_URL.Copy();
else
m_view.ExecWB(OLECMDID_COPY,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
return0;
}
LRESULTCMainFrame::OnEditPaste(WORD/*wNotifyCode*/,
WORD/*wID*/,HWND/*hWndCtl*/,BOOL&/*bHandled*/)
{
if(GetFocus()==m_URL)
m_URL.Paste();
else
m_view.ExecWB(OLECMDID_PASTE,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
return0;
}
LRESULTCMainFrame::OnEditUndo(WORD/*wNotifyCode*/,
WORD/*wID*/,HWND/*hWndCtl*/,BOOL&/*bHandled*/)
{
if(GetFocus()==m_URL)

https://www.codeproject.com/Articles/7147/WTLBrowser

5/13

12/10/2016

WTLBrowserCodeProject

m_URL.Undo();
else
m_view.ExecWB(OLECMDID_UNDO,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
return0;
}

Final Words
Please excuse me for any typing/grammar mistakes I might have made. English is not my natural language, so I make mistakes from time to time. You can use any part
of the code posted with the article. If you use it within your software, please email me and let me know don't worry no money will be asked for it. Special thanks to
Michael Dunn, Ed Gadziemski and PJ Naughter. I've learned a lot from their articles.

License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author
via the discussion board below.
A list of licenses authors might use can be found here

Share
EMAIL

TWITTER

About the Author


Gilad Novik
Web Developer
Israel

Gilad was born accidently to a pair of old lesbians. His childhood was full of vibrators and drugs. Married without kids. Has 14 grandsons around the world, 4
crocodiles, 2 mushrooms and a green alien living behind the refrigerator.
Hobbies: Watching hardcore porn, sculpturing with snot, skydiving from stairs.
Check my Homepage for additional resources.
Quote: "There's always one more bug"

You may also be interested in...


Embedding a Chromium browser in an MFC application

SAPrefs - Netscape-like Preferences Dialog

Using HTML as UI Elements in a WinForms Application with


Chrome / Chromium Embedded Framework (CEF)

Generate and add keyword variations using AdWords API

10 Ways to Boost COBOL Application Development

Window Tabs (WndTabs) Add-In for DevStudio

Comments and Discussions

Add a Comment or Question

Search Comments

Go
First Prev Next

seems javascript doesn't work...


lemonObrien 8Jul08 1:07
i have javascript which goes to the browser's history; a 'back' command;

https://www.codeproject.com/Articles/7147/WTLBrowser

6/13

12/10/2016

WTLBrowserCodeProject

it doesn't work with this program, i'm not familiar with how ie work in a view.
is their another component needed?
Reply Email ViewThread Permalink Bookmark

How do you change the font of dialog of VC IDE?


sun.wizard 9Jan07 3:54
Great article, BTW, I found that the font in your captured picture is not default, it's really what i want, can you tell me how to change that? I didn't find the way
for a long time.
Reply Email ViewThread Permalink Bookmark

2.00/5 1 vote

Problems with VC++2005


Haydel 27May06 10:01
I'm new to WTL so I don't understand the error messages yet.
I'm working with VC++2005, Windows XP SP2, WTL 7.5
I've created a project using thew WTL Wizard following the steps above and compiled fine.
I've included the file #include "browser.h", inherited the view from the Browser class and chain it to the message map as described above.
At this point I compiled the project and this is the error I get:

error C3203: 'CWebBrowser2' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
browser.h771 : see reference to class template instantiation 'CWebBrowser2<T,nID>' being compiled
The error points to this line on Browser.h:
class CWebBrowser2 : public CWebBrowser2EventsBase , public IDispEventSimpleImpl<nID, CWebBrowser2, &DIID_DWebBrowserEvents2>

Any idea of what that means?


Thanks in advance.
______________
Haydel
Reply Email ViewThread Permalink Bookmark

1.00/5 1 vote

Re: Problems with VC++2005


Gilad Novik 27May06 13:38
Please post the exact syntax you are using to inherit from CWebBrowser2.
"There's always one more bug"
Reply Email ViewThread Permalink Bookmark

Re: Problems with VC++2005


Haydel 27May06 17:41
Thanks for your reply.
Here is the declaration of the class:

#include "Browser.h"
class CInfoXView : public CWindowImpl<CInfoXView, CAxWindow>, public CWebBrowser2<CInfoXView>
{
public:
DECLARE_WND_SUPERCLASSNULL, CAxWindow::GetWndClassName
BOOL PreTranslateMessageMSG* pMsg;
BEGIN_MSG_MAPCInfoXView
CHAIN_MSG_MAP CWebBrowser2<CInfoXView>
END_MSG_MAP
// Handler prototypes uncomment arguments if needed:
// LRESULT MessageHandlerUINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/
// LRESULT CommandHandlerWORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/
// LRESULT NotifyHandlerint /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/
};

Thanks for your help.

______________
Haydel

https://www.codeproject.com/Articles/7147/WTLBrowser

7/13

12/10/2016

WTLBrowserCodeProject
modified at 17:47 Saturday 27th May, 2006
Reply Email ViewThread Permalink Bookmark

Re: Problems with VC++2005


Gilad Novik 27May06 17:47
This is not how you inherit from WTL classes. Since they are template classes, you need to specify the class name too:
class CInfoXView : public CWindowImpl<cinfoxview>, public CWebBrowser2<cinfoxview>
{
...
};
"There's always one more bug"
Reply Email ViewThread Permalink Bookmark

Re: Problems with VC++2005


Haydel 27May06 18:13
I believe that I did.
Please see my last post again, I modified it because the first time I copy/paste the code but the < and > symbols where lost because of the html
code.
Please take a look at my last post again.
Thanks for your time.
______________
Haydel
Reply Email ViewThread Permalink Bookmark

Re: Problems with VC++2005


Gilad Novik 27May06 19:00
It looks fine. I don't have VC2005 so I can't test it. I'll try to do it when I'll have access to it.
Gilad
"There's always one more bug"
Reply Email ViewThread Permalink Bookmark

http://pantyhoseupskirt.ceroline.info/
http://pantyhoseupskirt.ceroline.info/ 4Dec07 20:17
http://pantyhoseupskirt.ceroline.info/
http://pantyhoseupskirt.ceroline.info/
Reply ViewThread Permalink Bookmark | Edit Delete

Re: Problems with VC++2005


satie.zhao 31May06 5:06
visual c++ 2005 compiler cannot allow unspecialed template be used as a template argument in a base class list.
You can fix it by changing the following line in browser.h :
template<class T,UINT nID=0>
class CWebBrowser2 : public CWebBrowser2EventsBase , public IDispEventSimpleImpl<nID, CWebBrowser2, &DIID_DWebBrowserEvents2>
to:
template<class T,UINT nID=0>
class CWebBrowser2 : public CWebBrowser2EventsBase , public IDispEventSimpleImpl<nID, CWebBrowser2<T, nID>, &DIID_DWebBrowserEvents2>
refer to : http://msdn2.microsoft.com/enus/library/ms177253d=robot.aspx
best regards
Reply Email ViewThread Permalink Bookmark

5.00/5 1 vote

Re: Problems with VC++2005


ChesterFool 5Oct06 19:44
I've just started to try and get this to work and have gotten to the point where I'm receiving the error in this thread. However, I don't get
what this post is saying I should be doing to resolve the error...the code looks incomplete to me...an I missing something?

https://www.codeproject.com/Articles/7147/WTLBrowser

8/13

12/10/2016

WTLBrowserCodeProject
Thanx for any and all input.
Reply Email ViewThread Permalink Bookmark

Re: Problems with VC++2005


LazyDave 23Jan07 8:01

What satie.zhao meant is that you need to pass CWebBrowser2 parameters as parameters to the bass class, thus:
template<class T,UINT nID=0>
class CWebBrowser2 : public CWebBrowser2EventsBase , public IDispEventSimpleImpl<nID, CWebBrowser2<T, nID>,
&DIID_DWebBrowserEvents2>
the message system decided the templ8 syntax was HTML code!

Reply Email ViewThread Permalink Bookmark

5.00/5 1 vote

Thank you for your good program.


urax 4May06 15:15
Gilad,
Thank you for your good program.
But I have a one question.
The Addressbar of this code cannot accept backspace and some keysfor example arrows.
Is there a good idea?
Hiromitsu Matsuura
Hiromitsu Matsuura
Reply Email ViewThread Permalink Bookmark

Re: Thank you for your good program.


Gilad Novik 4May06 15:47
You should play with the "IsDialogMessage" function. From within "PreTranslateMessage", check if the active control is the edit bos address bar. If so,
return value from "IsDialogMessage".
"There's always one more bug"
Reply Email ViewThread Permalink Bookmark

Re: Thank you for your good program.


urax 4May06 15:54
Gilad,
Thank you for your quick respons.
For your help, I found the Microsoft Information.
http://support.microsoft.com/kb/168777/ENUS/
and I solved my problem.
Many thanks

for your kindness.

Reply Email ViewThread Permalink Bookmark

Re: Thank you for your good program.


umeca74 7Aug08 11:20
the problem is that view forwards too many messages to the webbrowser. To correct the lost keystrokes add this into the view's
PreTranslateMessage
ifGetFocus == m_URL return FALSE;
hth
nikos

http://www.zabkat.com[^]
Reply Email ViewThread Permalink Bookmark

problem with VC7 and WTL7


daveice 4Sep05 6:49
Really very greate work, but
I can't use this class in VS2003 and WTL7..

https://www.codeproject.com/Articles/7147/WTLBrowser

9/13

12/10/2016

WTLBrowserCodeProject

m_hWndClient = m_view.Createm_hWnd, rcDefault, _T"www.google.com", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL |


WS_VSCROLL, WS_EX_CLIENTEDGE;
m_hWndClient was NULL after this statement!
What's your comment about this issue?Thanks in advance.

Reply Email ViewThread Permalink Bookmark

Re: problem with VC7 and WTL7


Gilad Novik 27May06 13:41
Did you call AtlAxInit?
"There's always one more bug"
Reply Email ViewThread Permalink Bookmark

1.00/5 1 vote

Doesn't call OnBeforeNavigate2


erez_me 25Mar05 20:44
Gilad,
Cool wrapper of the IWebBrowser2 events however for some reason my application doesn't trigger the "OnBeforeNavigate2" event.
All other events are called and intercepted just fine. I just can't get this one to fire...
I have moved your code to a Visual Studio 7.0 and it doesn't seem to work. In VS 6.0 it works great.
Any ideas?
Erez

Reply Email ViewThread Permalink Bookmark

Re: Doesn't call OnBeforeNavigate2


davidbak 21Jul05 20:25
Nothing like answering a post 4 months later.
1. OnBeforeNavigate2 fires for me.
2. To compile under VS.NET 2003 I needed to create an IDL file and add it to the resource file. The IDL file was trivial:
Hide Copy Code

import"atliface.idl";
[
uuid(C5990016280C43d79E8EE1C4ED75099A),
helpstring("WTLBrowser"),
lcid(0x0000),
version(1.0)
]
libraryWTLBrowser{
interfaceIAxWinAmbientDispatchEx;
};

Then, in _tWinMain I modified the line that called _Module.Init as follows:


Hide Copy Code

hRes=_Module.Init(NULL,hInstance,&LIBID_WTLBrowser);

Dave
Reply Email ViewThread Permalink Bookmark

OnNewWindow2
hosch179 14Jul04 11:26
greate work
there is a little error in Refresh2
return m_pBrowser>Refresh2CComVariantnLevel;
it must be
return m_pBrowser>Refresh2&CComVariantnLevel;
Can you help me with the OnNewWindow2 Event.
In MFC you can use this Event to open the new
window in your own Browser like this :
void CYourView::OnNewWindow2LPDISPATCH FAR* ppDisp,
BOOL FAR* Cancel
{

https://www.codeproject.com/Articles/7147/WTLBrowser

10/13

12/10/2016

WTLBrowserCodeProject

// Get a pointer to the application object


CWinApp* pApp = AfxGetApp;
// Get the correct document template
CDocTemplate* pDocTemplate;
POSITION pos = pApp>GetFirstDocTemplatePosition;
pDocTemplate = pApp>GetNextDocTemplatepos;
ASSERTpDocTemplate;
// Create the new frame
CFrameWnd* pNewFrame = pDocTemplate>CreateNewFrameGetDocument,
CFrameWnd*AfxGetMainWnd;
ASSERTpNewFrame;
// Activate the frame and set its active view
pDocTemplate>InitialUpdateFramepNewFrame, NULL;
CYourView* pWBVw = CYourView*pNewFrame>GetActiveView;
ASSERTpWBVw;
pWBVw>m_webBrowser.SetRegisterAsBrowserTRUE;
*ppDisp = pWBVw>m_webBrowser.GetApplication;
}
In WTL i do:
BOOL CBrowserTestView::OnNewWindow2IDispatch** ppDisp
{
CMainFrame *pNewFrame = new CMainFrame;
if pNewFrame>CreateEx != NULL
{
pNewFrame>ShowWindowSW_SHOW;
}
if pNewFrame
{
pNewFrame>m_view.PutRegisterAsBrowserTRUE;
IWebBrowserApp* pApp = NULL;
if SUCCEEDEDpNewFrame>m_view.QueryControlIID_IWebBrowserApp, void** &pApp
{
*ppDisp = pApp;
return FALSE;
}
}
return TRUE;
}
The problem in WTL is that the opener referer in JavaScript is not supported.
First site calling the new Window like this
window.open....;
&lt;/script
The new Site have code like this:
<script language=javascript>
if window.opener
{
// do something
}
&lt;/script
In WTL is window.opener = null in MFC not.
Do you know what's the problem in WTL.
Thanks
hoschi
Reply Email ViewThread Permalink Bookmark

Sadly this won't build with ATL3 / VC++6


Mike Diack 26May04 8:04
Hi
I was seeking a project that is buildable with ATL3 and Visual C++ 6,
since I am looking to try my hand at embedding a web browser on a composite control.
I'm running VC6 SP6, Win XP SP1, ATL 3, WTL 7.5.
The build fails under VC6/ATL3.
Is there anyway to make it buildable under this legacy environment?
Cheers
Mike
Reply Email ViewThread Permalink Bookmark

https://www.codeproject.com/Articles/7147/WTLBrowser

11/13

12/10/2016

WTLBrowserCodeProject

What error do you get?


Gilad Novik 26May04 10:44
I'm using the same configuration and I don't have a special problem.
Whoa! The internet is even on computers now!
Reply Email ViewThread Permalink Bookmark

Re: What error do you get?


Mike Diack 31May04 3:44
Under WTL 7.5 not tried with WTL 7.0/7.1 with VC6 SP6 on Win XP SP2 2120:
I get the following on ATLFRAME.h while stdafx.cpp is building
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2146: syntax error : missing ';' before identifier 'lpnm'
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1179 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<TBase,TWinTraits>' being compiled
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2501: 'LPNMREBARCHEVRON' : missing storageclass or type
specifiers
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1179 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<TBase,TWinTraits>' being compiled
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2501: 'lpnm' : missing storageclass or type specifiers
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1179 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<TBase,TWinTraits>' being compiled
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2146: syntax error : missing ';' before identifier 'lpnm'
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1315 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<class ATL::CWindow,class ATL::CWinTraits<114229248,262400> >' being compiled
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2501: 'LPNMREBARCHEVRON' : missing storageclass or type
specifiers
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1315 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<class ATL::CWindow,class ATL::CWinTraits<114229248,262400> >' being compiled
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h415 : error C2501: 'lpnm' : missing storageclass or type specifiers
h:\program files\microsoft visual studio\vc98\wtl75\include\atlframe.h1315 : see reference to class template instantiation
'WTL::CFrameWindowImplBase<class ATL::CWindow,class ATL::CWinTraits<114229248,262400> >' being compiled
d:\wtl\wtlbrowser\stdafx.cpp8 : error C2856: #pragma hdrstop cannot be inside an #if block
Mike Diack
Reply Email ViewThread Permalink Bookmark

2.00/5 2 votes

Re: What error do you get?


Mike Diack 31May04 3:48
I see the problem....
The chevron etc is only defined in the VC7 VC .Net 2003, platform SDK:
H:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\CommCtrl.h2172:} NMREBARCHEVRON, *LPNMREBARCHEVRON;
Thus either I need a platform SDK update for VC 6, or else others will also
have my problems.
Reply Email ViewThread Permalink Bookmark

2.00/5 1 vote

SDK Update
Gilad Novik 31May04 4:48
I've downloaded WTL 7.5 http://sourceforge.net/projects/wtl and tested it. It works just fine. I guess it is a matter of SDK update. Try to
download the newest Platform SDK.
Whoa! The internet is even on computers now!
Reply Email ViewThread Permalink Bookmark

Re: What error do you get?


Michael Dunn 17Jun04 15:44
Get the latest Platform SDK see this article[^] for the steps to get WTL up and running
Mike
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClickEncrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ

Windows troubleshooting: Reboot first, ask questions later.

Reply Email ViewThread Permalink Bookmark

Re: What error do you get?


dge@cs.nott.ac.uk 2Sep04 5:19
Move the sdk lin and include directories to be first in the list in options>
directories and you will pick up the latest files.

https://www.codeproject.com/Articles/7147/WTLBrowser

12/13

12/10/2016

WTLBrowserCodeProject
Reply Email ViewThread Permalink Bookmark

Great
spyhole 24May04 18:30
a GREAT WROK
Reply Email ViewThread Permalink Bookmark

2.00/5 2 votes

Refresh
General

News

1
Suggestion

Question

Permalink | Advertise | Privacy | Terms of Use | Mobile


Web02 | 2.8.161208.2 | Last Updated 24 May 2004

https://www.codeproject.com/Articles/7147/WTLBrowser

Bug

Answer

Select Language

Joke

Layout: fixed |
fluid

Praise

Rant

Admin
Article Copyright 2004 by Gilad Novik
Everything else Copyright CodeProject, 19992016

13/13

Potrebbero piacerti anche