Logic Question

OSVBNET 1,386 Reputation points
2022-07-01T13:54:29.127+00:00

Hello experts,
Need a how-to-do advise:
I use this to show my help file:

Help.ShowHelp(Me, "path\help.chm", "StartPage.htm")

I need to delete this file after my app's exit:
"path\help.chm"

The problem's that if the help file is being shown and the time of app's shut down, can't delete on startup form's Closed/Finalized events!
Help. does not have a method to close the shown help, also can't find it using process.kill before trying to delete on Closed/Finalized event!
* Since on each form's help_requested Help.ShowHelp is being called for the same file but with different pages I have to use it...
Any advise you might think of?
Thanks indeed.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,780 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 86,986 Reputation points
    2022-07-02T11:10:52.467+00:00

    You can use directly HtmlHelp API, which returns a window handle and has a command to close it
    I tested with your code and it worked with my .chm

    Global variables :

    Public HelpFile As String = Path.GetTempPath() + "\Help.chm"  
    Public hWndHelp As IntPtr = Nothing  
    

    To open a .chm (I tested the topic with my .chm, to be changed...) :

    hWndHelp = HtmlHelp(Me.Handle, HelpFile + "::/inet401/help/itt/CommCtls/Common/Common.htm#Using_Common_Control",  
                HH_DISPLAY_TOPIC, IntPtr.Zero)  
    

    To close HTMLHelp window (before deleting the .chm)

     HtmlHelp(Me.Handle, Nothing, HH_CLOSE_ALL, IntPtr.Zero)  
    

    Declarations :

    <DllImport("Hhctrl.ocx", SetLastError:=True, CharSet:=CharSet.Unicode)>  
    Public Shared Function HtmlHelp(hwndCaller As IntPtr, pszFile As String, uCommand As UInteger, dwData As IntPtr) As IntPtr  
    End Function  
    
    Public Const HH_DISPLAY_TOPIC = &H0  
    Public Const HH_HELP_FINDER = &H0  ' WinHelp equivalent  
    Public Const HH_DISPLAY_TOC = &H1  
    Public Const HH_DISPLAY_INDEX = &H2  
    Public Const HH_DISPLAY_SEARCH = &H3  
    Public Const HH_SET_WIN_TYPE = &H4  
    Public Const HH_GET_WIN_TYPE = &H5  
    Public Const HH_GET_WIN_HANDLE = &H6  
    Public Const HH_ENUM_INFO_TYPE = &H7  ' Get Info type name, call repeatedly to enumerate, -1 at end  
    Public Const HH_SET_INFO_TYPE = &H8  ' Add Info type to filter.  
    Public Const HH_SYNC = &H9  
    Public Const HH_RESERVED1 = &HA  
    Public Const HH_RESERVED2 = &HB  
    Public Const HH_RESERVED3 = &HC  
    Public Const HH_KEYWORD_LOOKUP = &HD  
    Public Const HH_DISPLAY_TEXT_POPUP = &HE  ' display string resource id or text in a popup window  
    Public Const HH_HELP_CONTEXT = &HF  ' display mapped numeric value in dwData  
    Public Const HH_TP_HELP_CONTEXTMENU = &H10  ' text popup help, same as WinHelp HELP_CONTEXTMENU  
    Public Const HH_TP_HELP_WM_HELP = &H11  ' text popup help, same as WinHelp HELP_WM_HELP  
    Public Const HH_CLOSE_ALL = &H12  ' close all windows opened directly or indirectly by the caller  
    Public Const HH_ALINK_LOOKUP = &H13  ' ALink version of HH_KEYWORD_LOOKUP  
    Public Const HH_GET_LAST_ERROR = &H14  ' not currently implemented ' See HHERROR.h  
    Public Const HH_ENUM_CATEGORY = &H15    ' Get category name, call repeatedly to enumerate, -1 at end  
    Public Const HH_ENUM_CATEGORY_IT = &H16  ' Get category info type members, call repeatedly to enumerate, -1 at end  
    Public Const HH_RESET_IT_FILTER = &H17  ' Clear the info type filter of all info types.  
    Public Const HH_SET_INCLUSIVE_FILTER = &H18  ' set inclusive filtering method for untyped topics to be included in display  
    Public Const HH_SET_EXCLUSIVE_FILTER = &H19  ' set exclusive filtering method for untyped topics to be excluded from display  
    Public Const HH_INITIALIZE = &H1C  ' Initializes the help system.  
    Public Const HH_UNINITIALIZE = &H1D  ' Uninitializes the help system.  
    Public Const HH_SET_QUERYSERVICE = &H1E  ' Set the Host IQueryService interface  
    Public Const HH_PRETRANSLATEMESSAGE = &HFD  ' Pumps messages. (NULL, NULL, MSG*).   
    Public Const HH_SET_GLOBAL_PROPERTY = &HFC  ' Set a global property. (NULL, NULL, HH_GPROP)  
    Public Const HH_SAFE_DISPLAY_TOPIC = &H20  ' private addition to the interface for InternetExplorer.  
    

1 additional answer

Sort by: Most helpful
  1. Castorix31 86,986 Reputation points
    2022-07-01T18:45:27.81+00:00

    The problem's that if the help file is being shown and the time of app's shut down, can't delete on startup form's Closed/Finalized events!

    I cannot reproduce this (Windows 10 21H1)
    If I open a .chm, I can delete it on closing even if it is opened

    I tested with :

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing  
        Dim sFile As String = "E:\temp\SHELLCC.CHM"  
        If (My.Computer.FileSystem.FileExists(sFile)) Then  
            My.Computer.FileSystem.DeleteFile(sFile)  
        End If  
    End Sub  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.