We are using a TCppWebBrowser Component in our program as a kind of chatwindow, but since the TCppwebrowser is using the IExplorerengine all links that are clicked is opening in IExplorer. One idea I have is to cancel the navigation in Onbeforenavigate2 an do a Shell.execute, but where hoping for a more elegant solution like a windowsmessage i could handle or an event or something.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- Is there a Delphi 5 component that can handle .png
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
In fact, when you did not handle the "webNewWindow2" of the
TCppWebBrowser
, the link in theTCppWebBrowser
you open will be used the system default browser. There is nothing you need to do.For more codes of
TCppWebBrowser
, see this link I found: http://codeback.net/tag/tcppwebbrowserThe example Jeroen gave is right, except it's not C++, and I thought you might find an example in the language you're using helpful. The TCppWebBrowser component is similar to the TWebBrowser component and has the same events. (It get more complicated when you try to access some of the internals, though.)
Here's an edited version of an OnBeforeNavigate2 method I use:
It cancels navigation within the web browser, except to
about:blank
(you could remove that bit if it's not a legal page for your control) and the URLm_strWebPage
that is the one I want it locked to. You could make this check more flexible, allowing it to, say, navigate anywhere on a certain domain but opening links to another domain in another window, for example.The code is also written for C++Builder 2009 / 2010, because of its use of
UnicodeString
and theL
string prefix. You don't say what version you're using, but if you are using 2007 or before cast toWideString
instead.Cheers,
David
Assuming that TCppWebBrowser is like TWebBrowser in Delphi, something like the code below should get you going.
The OnBeforeNavigate2 event gets fired before the TWebBrowser navigates to a new URL. What you do is cancel that navigation, and redirect the URL with ShellExecute to an external application (which is the default web browser as configured in Windows).
In order to get the code below working, double click on your form, then enter the FormCreate event method content. Then drop a TWebBrowser, go do the events page of the object inspector and double click on the OnBeforeNavigate2 event and enter that code.
Have fun with it!
--jeroen