Embed Internet explorer

Blitz3D Forums/Blitz3D Programming/Embed Internet explorer

Difference(Posted 2004) [#1]
Here is how:

Const SWP_SHOWWINDOW     = $40
Const GWL_STYLE      = -16
Const WS_CLIPCHILDREN    = $2000000

Const WS_CHILD           = $40000000
Const WS_VISIBLE         = $10000000
Const WS_DISABLED        = $8000000

Graphics3D 800,600,0,2

cam=CreateCamera()
cube=CreateCube()
light=CreateLight(2)
PositionEntity cam , 1,2,-3
PointEntity cam,cube
PositionEntity light, -300,200,-500
PointEntity light,cube


Global hWnd = GetActiveWindow()
style=GetWindowLong(hWnd ,GWL_STYLE)
style = style Xor WS_CLIPCHILDREN 
SetWindowLong hwnd,GWL_STYLE,style
cstyle = WS_VISIBLE + WS_CHILD + WS_DISABLED
child = CreateWindowEx(0,"Static","",cstyle ,10,10,400,400,hwnd,0,0,0)

brow=EmbedBrowserObject(child )

DisplayHTMLPage child , "www.blitzbasic.com"

While Not KeyHit(1)
	
	TurnEntity cube,1,2,3
	
	RenderWorld
	Flip
	
	count =count +1
Wend

UnEmbedBrowserObject child 


End


I disabled the window in order to make keystrokes reach Blitz, but it can be active.

OBS: call UnEmbedBrowserObject before quitting! (don't use the windows [X])

You need the dll from http://www.codeproject.com/com/cwebpage.asp
or http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4379/

and a few userlib declerations:
; Filename User32.decls

.lib "user32.dll"
 
GetActiveWindow%():"GetActiveWindow"
SetWindowLong%(hWnd%,Val%,Long%):"SetWindowLongA"
GetWindowLong%(hWnd%,Val%):"GetWindowLongA"
CreateWindowEx%(dwExStyle,lpClassName$,lpWindowName$,dwStyle,
x,y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam):"CreateWindowExA"


.lib "cwebpage.dll"
 
EmbedBrowserObject%(hwnd%):"EmbedBrowserObject"
UnEmbedBrowserObject(hwnd%):"UnEmbedBrowserObject"
DisplayHTMLPage%(hwnd%,page$):"DisplayHTMLPage"
DisplayHTMLStr%(hwnd%,page$):"DisplayHTMLStr"



semar(Posted 2004) [#2]
ERROR: EmbedBrowserObject function not found.

Should it declared in a second .decls ? Please elaborate.

Very interesting though, thanks for sharing.

Sergio.


Difference(Posted 2004) [#3]
Sorry. The missing decls is added above.


semar(Posted 2004) [#4]
Thanks, but still does not work.
I get an error on this line:

brow=EmbedBrowserObject(child )

stating: 'User Lib not found'

Where should the cwebpage.dll be located ? At the moment I've tryed to put it in the userlibs directory, and in the same place where the source file is located, but still no fun !

Also tryed to restart blitz each time I edit the .decls or copy the .dll in a new location...
Sergio.


BlackD(Posted 2004) [#5]
Try saving the code to a folder, and copying the dll to that folder. You won't be able to use a DLL with a <untitled> program in B3D IDE unless you use an absolute path in the .decls file (and I'm not sure you can even do that.. mm - must try it sometime, although it'd be uselss for distribution..).


Picklesworth(Posted 2004) [#6]
You need to disable debug mode at this point... And I just get a white rectangle.
Sounds handy though :)


Difference(Posted 2004) [#7]
@Mr.Picklesworth:

Yes, I have to disable debug mode too, I wonder why?

Try a local html file.
Are you connected to the internet? If so wait a little longer.


semar(Posted 2004) [#8]
Very strange:

- With debug enabled, it complains as above (user lib not found).

- With debug disabled, a blank box is displayed (and a spinning cube). If you move the window, then the box displays the html page correctly. The links does not work though, as well as the scroll bars.

- When I close the app, an error exception comes out stating that the JIT is not properly registered. Once registered as the message suggests, another error is displayed in all the next application close event:

AppName: blitzcc.exe AppVer: 0.0.0.0 ModName: shdocvw.dll
ModVer: 6.0.2900.2180 Offset: 0001c491

Sergio.


Beaker(Posted 2004) [#9]
semar - to avoid the crash don't click on the windows X box.

Also, you can get scrollbars and links by commenting out the WS_DISABLED style:
cstyle = WS_VISIBLE + WS_CHILD; + WS_DISABLED


John Blackledge(Posted 2004) [#10]
A great piece of work! I've been asking for this for ages!
A few points:
1. I've taken the liberty of simplifying your DisplayHTMLPage code so it will display 'fullwindow', which is what I need :) but also to show that it doesn't need a child window.
2. To get around the Close Button problem use 'BlitzClose' dll and decls (somewhere on the Blitz Research site).
- Put blitzclose.dll and blitzclose.decls into your userlibs directory.
3. Does anyone know why KeyHit(1) does not work unless you alt-tab, then alt-tab back again?
4. Anyone know why Debug has to be switched off?




Difference(Posted 2004) [#11]
Thanks, I'll check out the BlitzClose dll
[EDIT] It's here and works well : http://www.blitzbasic.com/codearcs/codearcs.php?code=832 [/EDIT]


ad 3 : The browser has the focus and gets all input.
When you alt+tab, the focus goes to the main blitz window, until you click in the browser.
That's why I disabled the child window in the first demo.

ad 4. I'd really like to know too. I experiemented but can't seem to find a soulution.


mongia2(Posted 2004) [#12]
not work

stating: 'User Lib not found'

cwebpage.dll not found

mongia


mongia2(Posted 2004) [#13]
work!! i find a cwebpage.dll


John Blackledge(Posted 2004) [#14]
Can I just add that I've been wanting to create a 'web-book' wrapper for some time now, so that manuals etc could be created web-style which is ideal and the least work, then thrown to the web-book wrapper for display. And needless to say I wanted to do it in Blitz, but until now no-one knew how to put a browser window into a Blitz window.
Thanks Peter Scheutz!


xmlspy(Posted 2004) [#15]
Nice Job! works fine. But it seems that you can't type in text boxes like the ones were you type for forums posts. So I had to type this message in Notepad, then copy it, and paste it.


John Blackledge(Posted 2004) [#16]
Hey, yeah. I just tested this and xmlspy is correct.
Peter, maybe I missed the point, and your idea of a child window _is_ necessary.
Are their some flags that need to be set to allow text input? (Drop-downs, radio button and listboxes all seem to work fine.)


Difference(Posted 2004) [#17]
My first guess without testing, is that it's the old "Blitz steals keystrokes from child windows" thing.

If that is the case, it's fixable with a global keyboard hook in a dll. I'll see if I can dig up some code.


Erroneouss(Posted 2004) [#18]
will somebody please help me get this to work??
ive gotten errors in both programs!!
ive been trying to get this to work!!! and it wont work!!!!
argh!!!!!!!!!
can somebody zip up a folder and email it to me with all of the files for this to work??


Erroneouss(Posted 2004) [#19]
somebody?


Difference(Posted 2004) [#20]
Give a detailed description, of what you've done so far, and I'm sure we can find out what is missing.

The "Send me a zip" approach does not compile, at least not with me.


Picklesworth(Posted 2005) [#21]
I have been trying to find this again. It's exactly what I needed to solve the mystery of my epic quest and I forgot that it was open source :D
Fix it up to perfection and make it work everywhere smart people! I order you!!

I'll pay you by breathing less so there's more oxygen for you.

For me, the window is inactive in the first example (although I can see the blitz home page), ie: scroll bars and links do not work and I can't highlight text. In the second example by John Blackledge, the window works fine except for not reciving key presses or any clicks other than on mouse1, after removing referances to the closeHandler dll (which I can't get because the link to download is broken, I'll try to dig it up though). Although, of course, either way it performs an illegal operation on exit.


jfk EO-11110(Posted 2005) [#22]
Although I don't like MSIE, especially it's security problems, this one is very handy for dialog things etc., or let's say plugins (flash in blitz), you could even display a VRML file trough a browser plugin - ehm wait, this is stupid. I didn't try it yet, trust you so far :)

So here's my question: does this work in fullscreen mode too? And would it be possible to hide it on the backbuffer, just to copy it to a texture and use a live-msie texture? Like you know, stock exchange info on a wall or something.

TheDuck - do you understand how userlibs have to be created and handled?


Picklesworth(Posted 2005) [#23]
I don't think it works in fullscreen.
Believe it or not, I'm thinking in the opposite of your vrml viewer idea :D I plan to make an alternative to using a vrml plugin to view the web site cybertown.com. Even with the crash on exiting, this app would crash less than blaxxun contact does :D


jfk EO-11110(Posted 2005) [#24]
Sounds good. And it would be a way to render 3D in Software Mode - well, kind of. AFAIK less than 0.3% of the Users have a VRML plugin installed -VRML is almost dead, what a shame. BTW what VRML plugin would you recommend?


Picklesworth(Posted 2005) [#25]
BS Contact, except don't download the new version. If you don't pay, it will harass you endlessly endlessly with a very obstructive "Demo version" thing.
Blaxxun Contact is the best free alternative, but it has a memory leak which has never been fixed and the download page is next to impossible to fin on the www.blaxxun.com web site.

Now... To find a way to find out what web page the user is currently viewing or to get a message to my app via a link. Darn! There's always something that will be hard :(


Picklesworth(Posted 2005) [#26]
By the way, for the example on the top of this page, the window is inactive because it has the WS_DISABLED flag. Just remove it and it will be fine.
cstyle = WS_VISIBLE + WS_CHILD + WS_DISABLED

Can be changed to:
cstyle = WS_VISIBLE + WS_CHILD

Anyone have any ideas what other flags there are?


jfk EO-11110(Posted 2005) [#27]
check this out:
http://www.blitzbasic.com/codearcs/codearcs.php?code=589


Picklesworth(Posted 2005) [#28]
Nice!


Picklesworth(Posted 2005) [#29]
The plot thickens!!!
Perhaps in a good way.

[edit]Okay, I figured out that my test was deeply flawed and obvious.[/edit]

Blitz still gets mouse actions for all buttons, but absolutely no key presses except when the window is alt-tabbed a few times. Although, mysteriously, holding down shift while clicking a link no matter what will still open it in a new window.


simcenter(Posted 2006) [#30]
So, I've been screwing around all day trying to figure out where to put the .dll, and also where the userlib declarations go...

I'm trying to have one of my viewports display the internet. And it seems as if this page is describing that. But for the life of me, I can't seem to understand which folder to put the .dll in, and what those declarations should be copied to (a .bb file? In the original .bb file that I'm trying to write?)


Difference(Posted 2006) [#31]
Put the dll in your userlib folder, and when you make an exe file, in the same folder as the exe.

Save the .decls files as "User32.decls" and "cwebpage.decls"
and put them in the "Userlibs" folder of you blitz3d installation.


Picklesworth(Posted 2006) [#32]
And when you do a full compilation of your app, be sure to put the DLL in the same directory as the exe.

Edit:
Err... oops :P
I somehow missed that you already told him that.


simcenter(Posted 2006) [#33]
Okay,
so I'm supposing I need to use another program to save the above declarations as .decls files? Can I just copy and paste those lines of text above? Or can I use B3D to save them as .decls?

And, wow, thanks for the insanely quick response. This community is really nice and helpful. Once I know more I hope to contribute from the "helping" side.

--Brian.


RGR(Posted 2006) [#34]
It works fine - but always ends with a windows error message ... translated something like: Windows has detected an error ... do you want to send the problem ...
No matter how I end it Alt-F4 or clicking x

[Edit} Solved the error problem ... instead of KeyHit(1) I use Mousedown(2) ... The error appeared because the child window was not closed properly with Alt-F4 as it seems...
So, adding BlitzClose should solve it as well


Difference(Posted 2006) [#35]
@simcenter : Yes - just save them as textfiles. You can use Windows Notepad to do it.


simcenter(Posted 2006) [#36]
After creating the two .decls files and placing in my userlibs folder;
After downloading the cwebpage.dll and placing in my userlibs and folder containing the Blitz app;
And After placing the blitzclose.dll into my userlibs and folder containing the Blitz app:

I'm still getting "function not found" for "GetActiveWindow()"

I had to create my own userlibs folder because there wasn't one originally in my Blitz folder in my C drive, could that be the problem? Or should it go in the "bin" folder?

I'm copying the decls text above into notepad, saving as text files, and then manually retyping the extension from ".txt" to ".decls", is that also a problem? Otherwise I don't see a way to directly save as a decls.

I'm also assuming that to check to see if this works, I can copy and paste one of the above two codes into B3D and run them. Is that assuming too much?


RGR(Posted 2006) [#37]
@simcenter
Try GetActiveWindow%():"GetActiveWindow":GetActiveWindowA instead of GetActiveWindow%():"GetActiveWindow"
You do not have to place the dll into the userlib folder. This is actually contraproductive. Because if your pathes to the blitz folders are right then this works great for you. But if you then want to deliver your program to someone else, you often forget which dlls the program needs and then they have the "User lib not found" problem, too. The best place for user dlls is the folder where the Mainprogram expects them (= same folder).


simcenter(Posted 2006) [#38]
Thanks RaGR,

your suggestion works. But I still get the "function not found" pop up for the following lines of code:

brow = EmbedBrowserObject(hWnd)

DisplayHTMLPage hWnd, MyWebPage$

InstallCloseHandler(72, MyAppTile$)

UnInstallCloseHandler()

UnEmbedBrowserObject hWnd

Is there any other way of embedding a browser? I guess its not as easy as I had hoped it would be.


Picklesworth(Posted 2006) [#39]
EEEeek!

No need to use GetActiveWindow.

Just call SystemProperty("apphwnd") and it should work fine... and properly.


Which line of code is the function not found for?



I have developed another way of embedding a web browser in an application using native Blitz code and User32.decls:
http://www.blitzbasic.com/Community/posts.php?topic=48327

I wouldn't trust it as it is, though...

I recently released a DLL which executes a program and returns its process handle, allowing you to do all manner of things to it via kernel32.dll. (Including checking whether it is still running).
By editing the DLL's source, you can change the window title of the app being launched, get its window handle, or even force it to have a particular parent window!
http://www.blitzbasic.com/toolbox/toolbox.php?tool=151


Now that I've sparked my own interest in it again, I may try my hand at doing this myself...


RGR(Posted 2006) [#40]
.

Last edited 2012