Opening a web browser from a B3D app?

Blitz3D Forums/Blitz3D Programming/Opening a web browser from a B3D app?

John Pickford(Posted 2006) [#1]
Is there a clean, reliable way to do this?

I remember trying this a few years ago in Sticky Balls but it didn't work on a lot of machine and caused problems in full screen mode.

I'm assuming that I'd have to switch back to windowed mode temporarily to do this. And perhaps put the app into a non-cpu-hogging mode till the user clicks on an icon or something.

Any ideas? Is this practical?


GfK(Posted 2006) [#2]
This works. If you call ExecFile too quickly after EndGraphics, then nothing happens.

There may be a better way of doing this via a DLL or something - I don't know, and how you get back from your browser to your app is anyone's guess. Maybe some way of getting the browser's handle and waiting for a close event, but that stuff's beyond me.

Graphics 800,600,16,1
Delay 3000;wait a bit
EndGraphics
Delay 3000;allow time to return to desktop

ExecFile "http://www.blitzbasic.com"

While Not KeyDown(1)
	;do stuff, or call End instead of a loop
Wend



semar(Posted 2006) [#3]
What about calling a batch file .bat from within Blitz ? The batch file executes internet explorer.

The content of the .bat file could be for example:
"%ProgramFiles%\Internet Explorer\IEXPLORE.EXE"
Sergio.


John Pickford(Posted 2006) [#4]
How will a batch file help?

I want to cleanly bring up the defaut browser on the PC and I want it to work on every PC.


Yan(Posted 2006) [#5]
What GFK said, except...
ExecFile chr$(34) + "http://www.blitzbasic.com" + chr$(34)



GfK(Posted 2006) [#6]
What difference do the quotes make?


Yan(Posted 2006) [#7]
Some systems require quotes for ExecFile() to work reliably.

Don't ask me why though. :o/


markcw(Posted 2006) [#8]
this uses WinExec to open Iexplore from the current windows drive. It needs 2 kernel32.dll decls given below.

The api says you should use CreateProcess but it's only a preference, this works just as well and is simpler.

No idea how to find the default browser though.

;WinExec example

;.lib "Kernel32.dll"
;Api_WinExec% (lpCmdLine$, nCmdShow%) : "WinExec"
;Api_GetWindowsDirectory% (lpBuffer*, nSize%) : "GetWindowsDirectoryA"

;winuser.h constants
Const SW_HIDE=0
Const SW_MAXIMIZE=3
Const SW_MINIMIZE=6
Const SW_RESTORE=9
Const SW_SHOW=5
Const SW_SHOWDEFAULT=10
Const SW_SHOWMAXIMIZED=3
Const SW_SHOWMINIMIZED=2
Const SW_SHOWMINNOACTIVE=7
Const SW_SHOWNA=8
Const SW_SHOWNOACTIVATE=4
Const SW_SHOWNORMAL=1

Graphics 640,480,0,2
SetBuffer BackBuffer()

bank=CreateBank(16)
charlen=Api_GetWindowsDirectory(bank,11) ;"C:\WINDOWS"
cmdline$=Chr(34)
For i=0 To 2 ;get drive letter from bank
 cmdline$=cmdline$+Chr(PeekByte(bank,i))
Next
cmdline$=cmdline$+"Program Files\Internet Explorer\IEXPLORE.EXE"+Chr(34)
cmdline$=cmdline$+" www.blitzbasic.com"

;result=Api_WinExec(cmdline$,SW_SHOW)

While Not KeyDown(1)
 Cls

 If KeyHit(57) ;space
  result=Api_WinExec(cmdline$,SW_SHOW)
 EndIf

 Text 0,0,"Press Space, result="+result
 Text 0,20,"cmdline$="+cmdline$

 Flip
Wend

;result
;"function succeeds">31
;"out of memory"=0
;ERROR_FILE_NOT_FOUND=2
;ERROR_PATH_NOT_FOUND=3
;ERROR_BAD_FORMAT=11




xmlspy(Posted 2006) [#9]
I use the BMax for opening pages. B3D failed a few times on my tests.