help files whys it so hard to open one!

prostheticHead

Registered User.
Local time
Tomorrow, 07:22
Joined
Dec 14, 2004
Messages
42
Having a little problem i want to have a button on my main form that will hopen a HTMLhelp file (Chm) problem is only way i can find to do it is Aplication.FollowHyperLink "help.chm"

which is all well and good if ya know what thouse two anoing boxes are and know to just press ok.. but as you can emadgen if you need to click help in a simplistic Database.. then ya not going to be clicking ok to these boxes.

there must be a way i haveing a button on my form to open this help file without these two msg boxes coming up.. also i know theres a reg edit. i cant edit everyones comp who may use it in the future :)
 
Why not use the Shell command to open your help files? You have to point to the location of the help file executable on your computer and then to the location of your help file.

For HTML .chm files
Code:
Call Shell("C:\WINDOWS\hh.exe X:\YourHelpFile.chm", vbNormalFocus)

For the old .hlp files
Code:
Call Shell("C:\WINDOWS\system32\winhlp32.exe X:\YourHelpFile.hlp", vbNormalFocus)
 
Or you could use this:
Code:
'Execute Module
'ExecAss: Executes based on its OS association
'ExecCmd: Executes and waits for a process to finish
'2000 Chris Beach
'
Option Explicit

'Type Definitons
'===============
Private Type STARTUPINFO
   cb As Long
   lpReserved As String
   lpDesktop As String
   lpTitle As String
   dwX As Long
   dwY As Long
   dwXSize As Long
   dwYSize As Long
   dwXCountChars As Long
   dwYCountChars As Long
   dwFillAttribute As Long
   dwFlags As Long
   wShowWindow As Integer
   cbReserved2 As Integer
   lpReserved2 As Long
   hStdInput As Long
   hStdOutput As Long
   hStdError As Long
End Type

Private Type PROCESS_INFORMATION
   hProcess As Long
   hThread As Long
   dwProcessID As Long
   dwThreadID As Long
End Type

'Declarations
'============
Declare Sub SetWindowPos Lib "user32" _
    (ByVal hWnd As Integer, _
    ByVal hWndInsertAfter As Integer, _
    ByVal X As Integer, _
    ByVal Y As Integer, _
    ByVal cx As Integer, _
    ByVal cy As Integer, _
    ByVal wFlags As Integer)

Private Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" _
    (ByVal lpApplicationName As Long, _
    ByVal lpCommandLine As String, _
    ByVal lpProcessAttributes As Long, _
    ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, _
    ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, _
    ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, _
    lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function ShellExecute Lib "shell32" 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

'Constants
'=========
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Const SW_SHOW = 5

Public Sub ExecAss(hWnd As Long, sCmdLine As String)
'Executes scmdline via file association ie c:\bootlog.txt will run notepad!
Dim Ret As Long

Ret = ShellExecute(hWnd, "open", sCmdLine, vbNullString, CurDir$, SW_SHOW)
If Ret < 32 Then
    'Error can't shell
    msgbox "Failed to execute: " & sCmdLine
End If
End Sub

Public Sub ExecCmd(sCmdLine As String)
'Executes cmdline and waits for it to finsh
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim Ret As Long

' Initialize the STARTUPINFO structure:
Start.cb = Len(Start)

' Start the shelled application:
Ret = CreateProcessA(0&, sCmdLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)

' Wait for the shelled application to finish:
Ret = WaitForSingleObject(proc.hProcess, INFINITE)
Ret = CloseHandle(proc.hProcess)
End Sub
ExecAss executes via windows association, so if double clicking works then your ok
ExecCmd executes then waits for the process to finish before returning.
 
Thanks HEAPS guys!
sorry it took a while to get back been pritty flat out

cable your code worked sweet! very nice!
 
Further assistance please

Why not use the Shell command to open your help files? You have to point to the location of the help file executable on your computer and then to the location of your help file.


Will this work if I want to install the database on someone else's machine? Or will I have to know whether they have the executable on their machine too?
 
nikkypickles said:
Will this work if I want to install the database on someone else's machine? Or will I have to know whether they have the executable on their machine too?
the execass function will work whatever windows! (well it will if the pc still has help associations setup...which 99% will do)
 
ghudson said:
Why not use the Shell command to open your help files? You have to point to the location of the help file executable on your computer and then to the location of your help file.

For HTML .chm files
Code:
Call Shell("C:\WINDOWS\hh.exe X:\YourHelpFile.chm", vbNormalFocus)

For the old .hlp files
Code:
Call Shell("C:\WINDOWS\system32\winhlp32.exe X:\YourHelpFile.hlp", vbNormalFocus)
Those commands should work with any version of Windows.
 

Users who are viewing this thread

Back
Top Bottom