Home
Page
About
ToolBook
ToolBook
Tips
ToolBook
Projects
ToolBook
Links
Guest
Book


How to run Internet browser from ToolBook
(or run any program with document)
  Internet browsers can be executed with an URL as a parameter. For example:
iexplore.exe "https://cbook.ru"
  or
netscape.exe "https://cbook.ru"
  or may be some other browsers

  There are no problems if you know exact path of browser,
but you can't know it if your program must work on different computers.
So main problem is how to find browser name and path.
  First variant: Scan all disks and directories for browser names (iexplore.exe or netscape.exe).
Standard searching algorithm with recursion can be simply realized in Delphi or C++ but not in ToolBook
because of a lot of iterations and a lot of nesting calls.
  Second variant: Find executable file associated with "htm" extension.
To do it you need a "FindExecutable" function from "shell.dll".
        
to handle buttonClick
        linkDll "shell.dll"
                WORD    FindExecutable(STRING,STRING,POINTER)
        end
        linkDLL "tb40win.dll"
                POINTER getMemBlock(DWORD)
                WORD    freeMemBlock(POINTER)
        end linkDLL

        -- ATTENTION!!!
        -- This script works on Windows 3.1, Windows 95 and Windows 98,
        -- but it doesn't work on Windows NT because
        -- function FindExecutable returns full long name of executable file instead of DOS name
        -- and operator "run" can't work with long names
        -- (This script was tested in ToolBook 4)

        myParameter = "https://cbook.ru"
        sysCursor = 4
        lpBuffer = getMemBlock(256)
        if lpBuffer = NULL
                break
        end
        myErrorText = "Internet browser not found." & CRLF & \
                "If Internet browser is installed in your system, associate extension" && \
                QUOTE & "*.htm" & QUOTE && "with your browser and try once more."

        -- Determine current path
        myPath = name of this book
        while last char of myPath <> "\"
                clear last char of myPath
        end while

        status = FindExecutable("blank.htm",myPath,lpBuffer)
        -- "blank.htm" must be real file in directory myPath (In that example I assume that myPath is application path)

        if status <= 32  -- associated file not found
                request myErrorText
                break
        end
        myExe = pointerString(0,lpBuffer) -- Browser name with full path
        get freeMemBlock(lpBuffer)
        clear sysError
        run (myExe && myParameter)
        if sysError <> null
                request myErrorText
        end if
        sysCursor = default
end

-- P.S. The same method is used to run any program with document as parameter:
-- Word with *.doc, Adobe Acrobat Reader with *.pdf, etc.
Back to Tips Menu