Programming C++Builder Open New Url in My Custom Window Usging TCppWebBrowser in C-Builder

When we write our program using TCppWebBrowser, we always want it to open a new web page by our custom window. While if you do not handle the OnNewWindow2 event, it would runs the default webbrowser to open the new url. This example shows how to handle the OnNewWindow2 event and get the result of what we want.

Create a new project, put a TCppWebBrowser onto the form. Assign codes to the form's OnShow and CppWebBrowser1's OnNewWindow2 handler. As following.

void __fastcall TForm1::FormShow(TObject *Sender)

void __fastcall TForm1::CppWebBrowser1NewWindow2(TObject *Sender,
      LPDISPATCH *ppDisp, VARIANT_BOOL *Cancel)
    //ppDisp: Is the new TCppWebBrowser's interface.
    //Cancel: Set this value to true, will cause the new url opened in same window.
    TForm1 *fmNew = new TForm1(this);
    *ppDisp = fmNew->CppWebBrowser1->ControlInterface;

To see how to solve same problem in Delphi, check this article How to open a new web page in your custom window with TWebBrowser in Delphi .

Add comment

Security code

Programming - C++Builder