Programming C++Builder Open New Url in My Custom Window Usging TCppWebBrowser in C-Builder
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149

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)
{
    CppWebBrowser1->Navigate(L"http://codeback.net");   
}
//---------------------------------------------------------------------------

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);
    fmNew->Show();
    *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
Refresh

Programming - C++Builder