IonicWind Software

Aurora Compiler => Software Projects => Topic started by: Ionic Wind Support Team on March 12, 2006, 12:49:32 AM

Title: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 12:49:32 AM
I've been working on Aurora's own web browser window.  Definately much easier using classes.  As an example of how simple it can be to load and show a web page:


#include "webbrowser.inc"

global sub main()
{
CWebBrowser browse;
browse.Create(0,0,640,480,AWS_VISIBLE|AWS_SIZE|AWS_SYSMENU|AWS_MINIMIZEBOX|AWS_MAXIMIZEBOX,0,"Browser Test",0);
browse.Navigate("http://www.ionicwind.com");
do{wait(); }until browse.m_hwnd = 0;
}


That's all it takes ;)

Will have the library and include file posted by tomorrow.
Title: Re: CWebBrowser class
Post by: Parker on March 12, 2006, 02:27:30 PM
Do you think there's a possibility of doing a CWebBrowserCtrl class also, to act as a control just in case you don't want the web browser to take up all the window?

This is great timing, since I was just thinking that maybe I should look into making a web browser control for Aurora yesterday since it hasn't been done yet.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 02:53:30 PM
You can use it like a control.  Just don't have a caption or border.
Title: Re: CWebBrowser class
Post by: Zen on March 12, 2006, 03:09:43 PM
Will this have more control than IBasic's web browser? From reading the windows API i know it is possible to act on certain things such as if a web page tries to open a link in a new window, you could make it do something, rather than it opening internet explorer like in IBasic.

Lewis
Title: Re: CWebBrowser class
Post by: Parker on March 12, 2006, 03:27:04 PM
QuoteYou can use it like a control.  Just don't have a caption or border.
Oh, of course! From using IBasic's I just ignored the styles I guess, sorry.

QuoteWill this have more control than IBasic's web browser?
As an owner of the source and a partner developer, you can always extend it since (at least I assume) it's written in Aurora since COM is much easier now due to classes. I wonder though if it's possible to change the handlers for different events and give the control new handlers... I'm not very knowledgeable in COM (it probably shows)
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 03:39:55 PM
Yes it has much more functionality then IBasic.   Since I could link it directly to OOP handlers.

Quote
such as if a web page tries to open a link in a new window, you could make it do something, rather than it opening internet explorer like in IBasic.

You can make it open another instance of your browser window. Or ignore the request.  I am still working on that functionality though as it's a pain.  So there will be at least one update after the initial release ;)

Here is the current include file:


#use "webbrowser.lib"
class CWebBrowser : CWindow
{
declare CWebBrowser();
declare _CWebBrowser();
declare virtual Create(int l,int t,int w,int h,int style,int exstyle,string title,CWindow *parent),int;
declare virtual Destroy(),int;
declare virtual OnClose(),int;
declare virtual WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
//Messages from browser control
declare virtual OnBeforeNav(string url,string headers,string *pPostData),int;
declare virtual OnDownloadBegin(),int;
declare virtual OnDownloadComplete(),int;
declare virtual OnNavComplete(string url),int;
declare virtual OnProgressChange(int progress,int progressmax),int;
declare virtual OnStatusTextChange(string status),int;
declare virtual OnTitleChange(string title),int;
//Actions
declare CancelNav();
declare LoadFromString(string html);
declare Navigate(string url);
declare GetTitle(),heap;
declare GoBack();
declare GoForward();
declare GoHome();
declare IsBackEnabled(),int;
declare IsForwardEnabled(),int;
declare PrintPage();
declare Refresh();
declare Search();
declare Stop();
void *m_pBrowser;

}

declare extern BROWSERWAIT(opt int nosleep=0);


OnTitleChange event solves the annoying issue with IBasic's browser window, where the title string would not reflect the pages title all of the time.

OnProgressChange lets you display either a progress bar for the loading page, or show remaining bytes to be loaded.

Paul.
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 12, 2006, 05:36:48 PM
I downloaded the latest release - I guess this is not ready since it is not there.
Any Idea when it will be released?
Title: Re: CWebBrowser class
Post by: Parker on March 12, 2006, 05:50:39 PM
Alpha 3 (the next update) ;D
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 05:52:28 PM
As I mentioned I will be posting the library and include file here shortly.  Working on a few example programs.
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 12, 2006, 06:08:50 PM
OK - waiting quietly :D
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 07:46:03 PM
Attached to this message is the zip archive.  Contained in the archive:

webbrowser.lib - copy to your libs directory (usually c:\program files\aurora\libs)
webbrowser.inc - copy to your include directory (usually c:\program files\aurora\include)
Examples - A folder containing two example programs.  browser_test.src and browser_demo.src

To use the CWebBrowser class simply put #include "webbrowser.inc" at the top of your source file.

Test your installation by compiling and running the example programs.

Have fun,
Paul.

download link below
Title: Re: CWebBrowser class
Post by: John S on March 12, 2006, 08:19:13 PM
cool!

In the demo, can you change the "home" button to go to the Aurora site (http://www.ionicwind.com) by default?
Title: Re: CWebBrowser class
Post by: LarryMc on March 12, 2006, 08:41:15 PM
Paul,
Should I add the browser to the documentation?

Larry
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 12, 2006, 10:53:04 PM
Quote from: John S on March 12, 2006, 08:19:13 PM
cool!

In the demo, can you change the "home" button to go to the Aurora site (http://www.ionicwind.com) by default?


It goes to wherever your IE home page is set to.  Just stick a Navigate command in there if you want to change that.
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 13, 2006, 09:05:04 AM
Can I get the lib source?
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 13, 2006, 09:11:29 AM
I'll post the source code in the developers area once it's finished.  Uses both C++ and Aurora code combined to get the job done.  The event sink for the IWebBrowser2 interface is written in C++ until I get the time to convert the COM header files over to Aurora.

The cool thing is you can take a .obj file directly from VC++ 6.0 and add it to a project as an external file to link with.  The rest was easily done on the Aurora side as a class.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 13, 2006, 03:45:09 PM
Here is the link to the download again.  The forum uses a very small font making it hard to see in the attachment post.

Download (http://www.ionicwind.com/forums/index.php?action=dlattach;topic=465.0;id=124)
Title: Re: CWebBrowser class
Post by: Bruce Peaslee on March 13, 2006, 10:28:07 PM
I like the browswer window because you can program HTML as a string and load it in. My latest project - soon to be postedÂÃ,  ::)ÂÃ,  - makes a Q&D (quick and dirty) help page in just that manner.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 13, 2006, 10:32:04 PM
It is probably one of the more useful features of the class.  LoadFromString allows creating dynamic html content on the fly.  I have an example I am working on the combines that with the CDatabase class to show tables of data.

I will also add a SplitPairs method soon to parse a posted form into the name/value pairs for easy access. 
Title: Re: CWebBrowser class
Post by: Zen on March 14, 2006, 02:21:20 AM
Hmm already made somthing back in IBasic that parses Key => Value pairs for get and post data, ill dig it out if i have it on my laptop here.

Lewis
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 14, 2006, 06:02:05 AM
I am trying to use this to get a stock quote. Part of my monster example program.
I need to send an html string and capture the return.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 14, 2006, 06:15:35 AM
This is just the WebBrowser control.  Your probably looking for something different.

You can create an html page with a form on it and load it with LoadFromString.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 14, 2006, 06:20:55 AM
Larry,
Here is how to read a site through code using wininet.  You'll need to create the import library (from the 'tools' menu). 

You can use this to request a specific page from a server and read the results back.


#use "wininet.lib"

// example of how to use the internet functions in wininet.dll
// the html source of the website is retrieved and displayed
// in the console window
// for descriptions of the various functions see http://msdn.microsoft.com

// Compile as a CONSOLE target

#define INTERNET_SERVICE_FTP 1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP 3

#define INTERNET_PRECONFIG 0
#define INTERNET_DIRECT 1
#define INTERNET_PROXY 3
#define INTERNET_FLAG_RELOAD 0x80000000

DECLARE IMPORT,InternetOpenA(agent as string,access as int,proxyname as string,proxybypass as string,flags as int),int;
DECLARE IMPORT,InternetConnectA(session as int,server as string,port as word,username as string,pass as string,service as int,flags as int,context as int),int;
DECLARE IMPORT,InternetCloseHandle(handle as int),int;
DECLARE IMPORT,HttpOpenRequestA(session as int,verb as string,name as string,version as pointer,referer as string,types as pointer,flags as int,context as int),int;
DECLARE IMPORT,HttpSendRequestA(handle as int,headers as pointer,headerlength as int,option as pointer,optionlength as int),int;
DECLARE IMPORT,InternetReadFile(hfile as int,buffer as string,count as int,bytesread as pointer),int;
DECLARE IMPORT,InternetQueryDataAvailable(hfile as int,bytesavail as pointer,flags as int,context as int),int;

DEF hopen,hconnect,hhttp as int;
DEF buffer,site,doc,ref as STRING;
DEF br,avail as int;
global sub main()
{
// change the site to any site you want.
site = "www.ionicwind.com";
// the doc refers to the actual document, directory or page being retrieved.
doc = "";
ref = "Aurora Compiler";

hopen = InternetOpenA(ref,INTERNET_PRECONFIG,"","",0);
IF hopen
{
PRINT( "Wininet initialized" );
hconnect = InternetConnectA(hopen,site,80,"","",INTERNET_SERVICE_HTTP,0,0);
IF hconnect != 0
{
PRINT( "Connection established" );
hhttp = HttpOpenRequestA(hconnect,"GET",doc,null,"",null,INTERNET_FLAG_RELOAD,0);
IF hhttp
{
IF HttpSendRequestA(hhttp,null,0,null,0)
{
PRINT( "Request Made" );
DO
{
InternetReadFile(hhttp,buffer,254,br);
buffer = left$(buffer,br);
IF(br)
PRINT( buffer,);
buffer = "";
}
UNTIL br = 0;
}
InternetCloseHandle(hhttp);
}
InternetCloseHandle(hconnect);
}
InternetCloseHandle(hopen);
}

PRINT();
PRINT( "Press any key to close" );
while GetKey() = "";
}

Title: Re: CWebBrowser class
Post by: Mike Stefanik on March 14, 2006, 10:36:29 AM
Ah, good ol' WinInet. Has to be one of the ugliest APIs created by man. Here's how you'd do it using SocketTools:


#autodefine "off"
#include "cstacl45.inc"

global sub main()
{
ÂÃ,  ÂÃ,  string strWebsite = "www.ionicwind.com"; // Server to connect to
ÂÃ,  ÂÃ,  string strResource = "/";ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  // Document or script
ÂÃ,  ÂÃ,  pointer lpBuffer = null;ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, // Result buffer
ÂÃ,  ÂÃ,  unsigned int dwLength = 0;ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, // Length of the buffer
ÂÃ,  ÂÃ,  int bResult = false;

ÂÃ,  ÂÃ,  CHttpClient http;
ÂÃ,  ÂÃ,  if (http.Connect(strWebsite))
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  bResult = http.GetData(strResource, &lpBuffer, &dwLength);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  http.Disconnect();
ÂÃ,  ÂÃ,  }

ÂÃ,  ÂÃ,  if (bResult)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  writeln(*(string)lpBuffer);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  delete lpBuffer;
ÂÃ,  ÂÃ,  }

ÂÃ,  ÂÃ,  return 0;
}


Of course, up to you which you prefer. WinInet will give you a lot of typing practice, even to do the simplest things. :)
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 14, 2006, 02:42:06 PM
The following works on Linux:
        int fd = open_socket (url->host, url->port);
        /* url->path = http://finance.yahoo.com/d/quotes.txt?s=BLS&f=sl1n */
        sprintf (text, "GET %s\n", url->path);
        write (fd, text, strlen (text) + 1);

but the following does not work in Aurora:
       hhttp = HttpOpenRequestA(hconnect,"GET http://finance.yahoo.com/d/quotes.txt?s=BLS&f=sl1n",
doc,null,"",null,null,0);
      /* doc = "" */

What is wrong?
Title: Re: CWebBrowser class
Post by: Mike Stefanik on March 14, 2006, 03:27:33 PM
You're feeling masochistic, I see.  ;)

The lpszVerb parameter only accepts valid HTTP verbs (GET, POST, etc.) as far as I know. You can't slide a URL in there. The actual session has to be created using InternetConnect.


Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 14, 2006, 04:06:37 PM
In my example change the 'doc' string to the page you're requesting.
Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 14, 2006, 05:28:33 PM
Did that - same results.
Title: Re: CWebBrowser class
Post by: Ionic Wind Support Team on March 14, 2006, 06:33:14 PM
You don't use http in the string.

site = "finance.yahoo.com";
doc = "d/quotes.txt?s=BLS&f=sl1n";

Title: Re: CWebBrowser class
Post by: Rock Ridge Farm (Larry) on March 15, 2006, 07:02:50 AM
That works - thanks.
It is always the simple things I dork up with skill.