MedVision ad

online help (1 Viewer)

xeriphic

Member
Joined
May 7, 2004
Messages
452
Location
Sydney
okai here is the problem, i'm at the end of making my major work and i need to link online help function through the program by pressing a command button, so the browser pops up with the main page, can anyone tell me the code to do something like that, thanks
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Use the ShellExecute API.

Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1

' somewhere in your code
ShellExecute Me.hWnd, vbNullString, "http://www.boredofstudies.org", vbNullString, "C:\", SW_SHOWNORMAL
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
So you have it open a HTML based help when you press F1.

Online help isn't restricted to F1.
 

hornetfig

Member
Joined
Jun 27, 2004
Messages
65
Location
Sydney. oddly
Gender
Male
HSC
2003
that being the case, the CommonDialog's ShowHelp() function will be useful. Provided, of course, this is VB...
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Originally posted by menty
sunny, i used taht as an example
Sorry I took you literally, since you used ie instead of eg. :)
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Put the declarations in a module:
Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
Use ShellExecute when you want to launch the browser, say in a button click
Code:
Private Sub Command1_Click()
  ' somewhere in your code
  ShellExecute Me.hWnd, vbNullString, "http://www.boredofstudies.org", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
 

xeriphic

Member
Joined
May 7, 2004
Messages
452
Location
Sydney
it works great, though what happens if the html files are offline, then do i just change it into the path
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Yes. Use something like App.Path if your HTML files are in your program directory.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
App.Path is a function that returns the directory that the executable is in. If your EXE was in C:\project, App.Path returns "C:\project"

So if you had a folder in your project folder called HelpFiles, you can use this for your path:
Code:
App.Path & "\HelpFiles\main.html"
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
Sunny a question with that piece of coding

works fine and all but im a bit curious
"C:\", SW_SHOWNORMAL"

what does this mean?? and why is it set to c:\ drive??? since who knows what drive letter the program can be opened from
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Originally posted by Seraph
Sunny a question with that piece of coding

works fine and all but im a bit curious
"C:\", SW_SHOWNORMAL"

what does this mean?? and why is it set to c:\ drive??? since who knows what drive letter the program can be opened from
The C:\ there has no particular use. I just pinched it out of an old program of mine. That particular parameter is useful when you are dealing with files and have to tell ShellExecute where to find the file. In this case its not needed, you can replace it with even vbNullString if you want.

SW_SHOWNORMAL tells ShellExecute what mode to start the program that executes in. There are other modes such as starting the program maximised, minimised, etc etc. SW_SHOWNORMAL just opens the program normally and gives it focus.
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
SUnny one more thing sorry What are the variables hwnd Loperation and etc doing ???

sorry its just that i have to add this to my data dictionary

oh and ill acknowledge you in my coding btw
 

hornetfig

Member
Joined
Jun 27, 2004
Messages
65
Location
Sydney. oddly
Gender
Male
HSC
2003
OK, I'll go through it:

Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
hWnd is the Handle to the Window that is calling the function. All windows in Windows have handles which identify the uniquely. This includes forms and most all controls that accept window focus. Sufficeit to say, it is mostly irrelevant for this function, and in VB in general, but you must provide a valid hWnd or the function will not work. You would typically use Me.hWnd or alternatively use the API function GetDesktopWindow() to get (surprisingly) the handle to the desktop, but you'd have to declare that like any other API function --> painful!.

lpOperation - long pointer to a char array (irrelevant in VB, it's a string) that is the operation to be performed. Generally OPEN, PRINT (which causes a program to attempt to print) or EXPLORE. This can be any action that appears on the right-click menu when right-clicking a file of the type being executed.

lpFile - long pointer to a char array (irrelevant, as above) that is the file to be executed.

lpParamaters - long pointer (blah blah, you know now) that is the parameters being passed to the executing program. Nothing unexpected here.

lpDirectory - like the "Run In" text box in the Shortcut Properties dialog

nShowCmd - one of

Code:
SW_HIDE			Hides the window and activates another window.
SW_MAXIMIZE		Maximizes the specified window.
SW_MINIMIZE		Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE		Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW			Activates the window and displays it in its current size and position. 
SW_SHOWDEFAULT		Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED	Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED	Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE	Displays the window as a minimized window. The active window remains active.
SW_SHOWNA		Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE	Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL		Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
(That's from the Platform SDK doc)


and there's a whole heap of return values too

http://msdn.microsoft.com/library/d...rm/shell/reference/functions/shellexecute.asp
 

gabn

Member
Joined
Mar 29, 2004
Messages
81
Location
North maitland
Gender
Male
HSC
2004
Can i use this code do launch other file types ? word docs.

I can only seem to get it to open up websites with the http:// at the start of the location not localy stored. html files or docs.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top