473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get help to go away when a program exits?

I am using the help class to display a simple help file. I generated the
help file using Word and saving it as a single page Web page (.mht
extension). I show the help file with the following statement.
Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile)
How do I get it to go away when the program exits? Now when I quit the
program that I called it form the help file is sill displayed. Is there a
way to get a handle to the instance of the IE browser that the help file is
in and then using this handle to kill it?

--
Mike Reed
Nov 21 '05 #1
1 1949
In your form:

Option Strict Off
Option Explicit On
'
'
************************************************** **************************
**************************
' Created by Julian Milano
' JDMils Software Development Pty Ltd
' jd****@datafast.net.au
' ju****@jdmils.com
'
' Date: 19 Jul 2005
'
' This application cycles thru all active Windows sessions looking for a
' particular window which it will then attempt to kill (close).
'
' The application code demonstrates the use of:
' 1....Enumerating Windows sessions by API
' 2....Kill (Close) Windows sessions by API
' 3....Get a window session's title-bar text by API
' 4....Call back functions
' 5....Raising events
'
' The code in this application is copywrite, but you can use it simply by
emailing me.
'
************************************************** **************************
**************************
'

Friend Class frmAskWinCaption
Inherits System.Windows.Forms.Form

#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents Command1 As System.Windows.Forms.Button
Public WithEvents Label1 As System.Windows.Forms.Label
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cbCaseSensitive As System.Windows.Forms.CheckBox
Public WithEvents tbWindowText As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmAskWin Caption))
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.Command1 = New System.Windows.Forms.Button
Me.tbWindowText = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.cbCaseSensitive = New System.Windows.Forms.CheckBox
Me.SuspendLayout()
'
'Command1
'
Me.Command1.BackColor = System.Drawing.SystemColors.Control
Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
Me.Command1.Font = New System.Drawing.Font("Arial", 8.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Command1.Location = New System.Drawing.Point(8, 56)
Me.Command1.Name = "Command1"
Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command1.Size = New System.Drawing.Size(120, 33)
Me.Command1.TabIndex = 1
Me.Command1.Text = "Kill It"
'
'tbWindowText
'
Me.tbWindowText.AcceptsReturn = True
Me.tbWindowText.AutoSize = False
Me.tbWindowText.BackColor = System.Drawing.SystemColors.Window
Me.tbWindowText.Cursor = System.Windows.Forms.Cursors.IBeam
Me.tbWindowText.Font = New System.Drawing.Font("Arial", 8.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.tbWindowText.ForeColor = System.Drawing.SystemColors.WindowText
Me.tbWindowText.Location = New System.Drawing.Point(8, 24)
Me.tbWindowText.MaxLength = 0
Me.tbWindowText.Name = "tbWindowText"
Me.tbWindowText.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.tbWindowText.Size = New System.Drawing.Size(264, 25)
Me.tbWindowText.TabIndex = 0
Me.tbWindowText.Text = "Enter Window Session Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
Me.Label1.Font = New System.Drawing.Font("Arial", 8.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(233, 17)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Enter the partial name of the window to close:"
'
'cbCaseSensitive
'
Me.cbCaseSensitive.Checked = True
Me.cbCaseSensitive.CheckState =
System.Windows.Forms.CheckState.Checked
Me.cbCaseSensitive.Location = New System.Drawing.Point(136, 64)
Me.cbCaseSensitive.Name = "cbCaseSensitive"
Me.cbCaseSensitive.Size = New System.Drawing.Size(136, 16)
Me.cbCaseSensitive.TabIndex = 3
Me.cbCaseSensitive.Text = "Case Sensitive Search"
'
'frmAskWinCaption
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(280, 95)
Me.Controls.Add(Me.cbCaseSensitive)
Me.Controls.Add(Me.Command1)
Me.Controls.Add(Me.tbWindowText)
Me.Controls.Add(Me.Label1)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Icon = CType(resources.GetObject("$this.Icon"),
System.Drawing.Icon)
Me.Location = New System.Drawing.Point(4, 22)
Me.Name = "frmAskWinCaption"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Find & Kill Window Sessions"
Me.ResumeLayout(False)

End Sub
#End Region

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim KillWindow As Object

KillWindow = FindWindowWild("*" & tbWindowText.Text & "*",
cbCaseSensitive.Checked)
If KillWindow = 0 Then
tbWindowText.Text = "Sorry. [" & tbWindowText.Text & "] was not
found."
Else
SendMessage(KillWindow, WM_CLOSE, 0, 0)
tbWindowText.Text = "[" & tbWindowText.Text & "] was killed."
End If
End Sub

End Class

In a module:

Option Strict Off
Option Explicit On

Module mAPICode

#Region "API Declares"

Private Delegate Function CallBack(ByVal hwnd As Integer, ByVal lParam
As Integer) As Boolean
Private Declare Function EnumWindows Lib "User32" (ByVal lpEnumFunc As
CallBack, ByVal lParam As Integer) As Integer
Private Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch
As Integer) As Integer
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As
Integer) As Boolean
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Integer)
As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,
ByVal lParam As Integer) As Integer

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef
lParam As Integer) As Integer
Public Const WM_CLOSE As Short = &H10S

#End Region

#Region "Events"
'
'
************************************************** **************************
**************************
' Raise an event to signify a window was found- any window.
'
************************************************** **************************
**************************
'
Public Event WndH(ByVal hWnd As Integer)

#End Region

#Region "Called Back Function"
'
'
************************************************** **************************
**************************
' This is the called function. hwnd will be the window being queried.
'
************************************************** **************************
**************************
'
Private Function retHndW(ByVal hwnd As Integer, ByVal lParam As Integer)
As Boolean
' Raise an event signifying a window session was found.
RaiseEvent WndH(hwnd)
Dim k As Long, sName As String
' Check if the window session is visible- Windows has hidden window
sessions
' running all the time.
If IsWindowVisible(hwnd) Then
' Prepare the string in which the window's title-bar caption
will be returned.
sName = Space$(128)
' Get the title-bar text of this window.
k = GetWindowText(hwnd, sName, 128)
' Check length of title-bar text.
If k > 0 Then
sName = Left$(sName, k)
' If Case is not sensitive, then convert title-bar text to
upper-case.
If Not mMatchCase Then sName = sName.ToUpper()
' Match it to the serach string
If sName Like sPattern Then
' Match found.
hFind = hwnd
Return False
Exit Function
End If
End If
End If
' Return True so that this call is passed onto the next Windows
process.
Return True
End Function

#End Region

#Region "Module Level Variables"

Dim sPattern As String
Dim hFind As Integer
Dim mMatchCase As Boolean = True

#End Region

#Region "Window Session Functions"
'
'
************************************************** **************************
**************************
' This function closes the selected window session.
'
************************************************** **************************
**************************
'
Public Function CloseWindowByhWnd(ByRef hwnd As Integer) As Integer
On Error GoTo ErrorCloseWindowByhWnd
CloseWindowByhWnd = PostMessage(hwnd, WM_CLOSE, 0, 0)
Exit Function

ErrorCloseWindowByhWnd:
MessageBox.Show(Err.Number & ":Error in CloseWindowByhWnd. Error
Message: " & _
Err.Description, MsgBoxStyle.Critical, "Warning")
End Function
'
'
************************************************** **************************
**************************
' This sub sets up the call back function. Windows will call retHndW
when a window is found.
'
************************************************** **************************
**************************
'
Public Sub GetWindows()
Call EnumWindows(AddressOf retHndW, 0)
End Sub

#End Region

#Region "API Interface Function"
'
'
************************************************** **************************
**************************
' This function is the interface to the outside world.
'
************************************************** **************************
**************************
'
Public Function FindWindowWild(ByVal sWild As String, Optional ByVal
bMatchCase As Boolean = True) As Long
mMatchCase = bMatchCase
On Error Resume Next
sPattern = sWild
hFind = 0
' If Case is not sensitive, then convert title-bar text to
upper-case.
If Not bMatchCase Then sPattern = UCase(sPattern)
' Cycle thru all windows.
Call GetWindows()
' Return the hwnd of the window session being sought.
Return hFind
End Function

#End Region

End Module

You need to search for the window with the particular text in the title and
kill it when your app is closing down.

--
|
+-- Thief_
|

"Michael D. Reed" <ch******@online.nospam> wrote in message
news:9B**********************************@microsof t.com...
I am using the help class to display a simple help file. I generated the
help file using Word and saving it as a single page Web page (.mht
extension). I show the help file with the following statement.
Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile)
How do I get it to go away when the program exits? Now when I quit the
program that I called it form the help file is sill displayed. Is there a
way to get a handle to the instance of the IE browser that the help file is in and then using this handle to kill it?

--
Mike Reed

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1540
by: xegfault | last post by:
Here is a simple script: #!/usr/bin/python print "No newline, please.", # End of script When the program runs, python is still printing a newline when the program exits. How does one keep...
4
9002
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
1
2589
by: anismo | last post by:
Hi, I have an application that uses a couple of shared libraries and this application forks to become a daemon. But when the parent after the fork calls exit(0), I am getting a coredump . Upon...
29
4355
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
1
1272
by: Gohar | last post by:
i have written the code to transfer image file through sockets. Below is the code for client. It just runs and exit nothing happens. Can anybody help? In this code first i get the file size then...
26
2174
by: Bail | last post by:
I will have a exam on the oncoming friday, my professor told us that it will base upon this program. i am having troubles understanding this program, for example what if i want to add all the...
4
1445
by: tperri | last post by:
I've got a user table with a field called Online, and when a user logs in, I set a value in this column to indicate they are online. And in the same fashion, when they click the logout button, I...
2
1795
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
3
2016
by: ray well | last post by:
hi, i have a app which has a help file, *.hlp, which the user can launch within the program. i want the help file if it is open to close when the program exists. the way i did it till now is...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.