April 29, 2024, 10:45:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


CWebBrowser class

Started by Ionic Wind Support Team, March 12, 2006, 12:49:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Parker

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.

Ionic Wind Support Team

You can use it like a control.  Just don't have a caption or border.
Ionic Wind Support Team

Zen

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

Parker

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)

Ionic Wind Support Team

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.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

I downloaded the latest release - I guess this is not ready since it is not there.
Any Idea when it will be released?

Parker

Alpha 3 (the next update) ;D

Ionic Wind Support Team

As I mentioned I will be posting the library and include file here shortly.  Working on a few example programs.
Ionic Wind Support Team

Rock Ridge Farm (Larry)


Ionic Wind Support Team

March 12, 2006, 07:46:03 PM #10 Last Edit: March 12, 2006, 10:55:27 PM by Ionic Wizard
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
Ionic Wind Support Team

John S

cool!

In the demo, can you change the "home" button to go to the Aurora site (http://www.ionicwind.com) by default?
John Siino, Advanced Engineering Services and Software

LarryMc

Paul,
Should I add the browser to the documentation?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

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.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

Can I get the lib source?

Ionic Wind Support Team

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.
Ionic Wind Support Team

Ionic Wind Support Team

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
Ionic Wind Support Team

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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. 
Ionic Wind Support Team

Zen

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

Rock Ridge Farm (Larry)

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Ionic Wind Support Team

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() = "";
}

Ionic Wind Support Team

Mike Stefanik

March 14, 2006, 10:36:29 AM #23 Last Edit: March 14, 2006, 10:38:14 AM by Mike Stefanik
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. :)
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Rock Ridge Farm (Larry)

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?