Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded web browsers?

Status
Not open for further replies.

JayinCanada

Programmer
Joined
Aug 15, 2002
Messages
2
Location
CA
Hello all,

I would like to embed a web browser in to my Win32 app much like the WebBrowser component in MFC but with out using MFC. Is there a way to use IE in my app if it is installed on the client computer? All I would like to do is display an HTML page in my C++ app. Any help and/or guidance would be greatly appreciated.

Jason
 
Perhaps the easiest way to accomplish what you have in mind is to use the ShellExecute() function, eg:

ShellExecute(0,"open","
This one line of code will open the user's default web browser, request an internet connection (or automatically connect) and load the web page specified.

You can also do the same thing with local HTML files by specifying the local address on the user's machine.

Hope this is what you're looking for.
 
For IE in a window, You can use this:
#include <Afxwin.h>
#include <afxext.h> // MFC-Extensions
#include <afxole.h> // MFC OLE
#include <Afxhtml.h>

IWebBrowser * g_pBrowser = NULL; //Interface

BOOL ShowHTML(char * URL, HWND hWnd)
{
if(hWnd == NULL) {
return FALSE;
}
if(URL == NULL) {
return FALSE;
}
RECT rect;
GetClientRect (hWnd, &rect);

if(g_pBrowser == NULL) {
// Create the control.
g_pBrowser = new IWebBrowser;
}
if(g_pBrowser) {
if (!g_pBrowser->Create(NULL,NULL,WS_VISIBLE, rect, pWnd, NULL))
{
MessageBox(NULL, &quot;failed to create browser!&quot;, &quot;ERROR:&quot;, MB_OK | MB_ICONSTOP);
delete g_pBrowser;
g_pBrowser = NULL;
return FALSE;
}

// Initialize the first URL.
COleVariant noArg;
g_pBrowser->Navigate(URL, &noArg, &noArg, &noArg, &noArg);
}
else {
MessageBox(NULL, &quot;Error by creating browser!&quot;, &quot;ERROR:&quot;, MB_OK | MB_ICONSTOP);
return FALSE;
}

return TRUE;
}

This functions starts IE embedded in hWnd with URL as start page. Do not forget delete g_pBrowser after You do not need it more!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top