Free Educational Resource Center for teachers and students. Includes Interviews,
Sourcecode, Free Software, Research Papers, Articles, Tutorials and much more..
     R E S E A R C H A C T I V I T Y . C O M
Our Fellow Research Center for Ph.D Schollars
Home About Submit & Earn Archives: C And C + + Programming » Dev Packages » Interviews » Php Mysql Programming » Windows Programming
search
Windows Programming > creating web browser easily in c with mingw gcc dev cplusplus



This resoruce is specific to MingW-GCC users only.

Your firewall software might start reporting your executable as as spyware (becuase browsers connect to internet), so better is compile project yourself and execute it, rather than executing precompiled exe file.



Screenshot


Ther have been hundreds of requests in MingWMailing list as well as few have reported bugs, which were not actually bugs, those were linker errors and complaints of missing declarations in headers that are dispatches with MingW. Most of the reporting parties were Dev C++ users.

Now when MingW has almsot all the required headers and libraries, we can easily create our web browser within another window and enjoy creating our first web browser in simple C style syntax. Comparing MSVC that already has CWebBrowser, that makes life easier, what are MignW usr going to do, ofcourse they mostly end-up linking thirdparty DLL files explicitely or implicitely, and still cant get their program standalone.

Ok, come to the porint. The ZIP package provided here includes a Dev C++ projec ready to compile, as well as a precompiled library file that was created using Resource of Jeff Glatt provided at codeproject.com, which helped alot getting this library ready. It is very lightweight and small library that can directly be linked to your applciation.

The library Includes a header file, that you need to include.

So, the steps for creating your fist browser window are:
1. Create a Dialog
2. Call function CreateBrowserWindow and pass it the handle of the dialog
3. Open a website in teh browser control, by calling function OpenURL this way:

OpenURL(myDialogHandle, "http://www.apitalk.com");

4. Finally - destry the browser when your application termiantes by calling DestroyBrowserWindow

Furthermore you can get the browser HEND handle through function GetBrowserHandle

That's it.

Now grab the Dev C++ project files from here:
http://www.apitalk.com/files/webbrowser-mingw-gcc-decpp.zip


Make user you have following link libraries options in linker tab of project:
-loleaut32
-lole32
-luuid


Project includes:

   Webbrowser.h - include file
   libwebbrowser.a - static link library
   Main.c - demo program
   WebBrowser.exe - demo binary
   WebBrowser.dev - DEV C++ project file


Webbrowser.h


//input is parent window / dialog handle
long CreateBrowserWindow(HWND);

//input is parent window / dialog handle
void DestroyBrowserWindow(HWND);

//Retrieve HWND handle of Browser - input is parent window / dialog handle
HWND GetBrowserHandle(HWND);

//Open desired url - 1st argument is parent window handle, 2nd is URL
long OpenURL(HWND, const char *);



Main.c


#include <windows.h>
#include "WebBrowser.h"


LRESULT CALLBACK myProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE a, HINSTANCE b, LPSTR c, int sh){

OleInitialize(NULL);


HWND myDialog = CreateWindowEx(
0,WC_DIALOG, "APITalk.com - Embed IE in C", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100,100,1000,600,NULL,NULL,NULL,NULL
);
SetWindowLong(myDialog, DWL_DLGPROC, (long)myProc);


CreateBrowserWindow(myDialog); //--------- CREATE BROWSER
OpenURL(myDialog, "http://localhost/speak+/index.php");

MSG msg;

while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

OleUninitialize();
return 0;
}

//////////////// Dialog's callback procedure
LRESULT CALLBACK myProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CLOSE){
DestroyBrowserWindow(hwnd); //--------- DESTROY BROWSER
PostQuitMessage(0);
}

if (uMsg == WM_SIZE) {
HWND browser = GetBrowserHandle(hwnd);

if(browser) {
//resize it so that it fits the parent window
MoveWindow(browser,0,0,LOWORD(lParam),HIWORD(lParam),TRUE);
UpdateWindow(hwnd);
}
}

return 0;
}