473,722 Members | 2,295 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(P arent:=Me, url:=Me.HELP_UR L_PRE & Me.myWorker.Hel pFile)
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 1976
In your form:

Option Strict Off
Option Explicit On
'
'
*************** *************** *************** *************** *************** *
*************** ***********
' Created by Julian Milano
' JDMils Software Development Pty Ltd
' jd****@datafast .net.au
' ju****@jdmils.c om
'
' 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....Enumeratin g 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 frmAskWinCaptio n
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.
InitializeCompo nent()
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.Disp ose()
End If
End If
MyBase.Dispose( Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(frmA skWinCaption))
Me.ToolTip1 = New System.Windows. Forms.ToolTip(M e.components)
Me.Command1 = New System.Windows. Forms.Button
Me.tbWindowText = New System.Windows. Forms.TextBox
Me.Label1 = New System.Windows. Forms.Label
Me.cbCaseSensit ive = New System.Windows. Forms.CheckBox
Me.SuspendLayou t()
'
'Command1
'
Me.Command1.Bac kColor = System.Drawing. SystemColors.Co ntrol
Me.Command1.Cur sor = System.Windows. Forms.Cursors.D efault
Me.Command1.Fon t = New System.Drawing. Font("Arial", 8.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Command1.For eColor = System.Drawing. SystemColors.Co ntrolText
Me.Command1.Loc ation = New System.Drawing. Point(8, 56)
Me.Command1.Nam e = "Command1"
Me.Command1.Rig htToLeft = System.Windows. Forms.RightToLe ft.No
Me.Command1.Siz e = New System.Drawing. Size(120, 33)
Me.Command1.Tab Index = 1
Me.Command1.Tex t = "Kill It"
'
'tbWindowText
'
Me.tbWindowText .AcceptsReturn = True
Me.tbWindowText .AutoSize = False
Me.tbWindowText .BackColor = System.Drawing. SystemColors.Wi ndow
Me.tbWindowText .Cursor = System.Windows. Forms.Cursors.I Beam
Me.tbWindowText .Font = New System.Drawing. Font("Arial", 8.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.tbWindowText .ForeColor = System.Drawing. SystemColors.Wi ndowText
Me.tbWindowText .Location = New System.Drawing. Point(8, 24)
Me.tbWindowText .MaxLength = 0
Me.tbWindowText .Name = "tbWindowTe xt"
Me.tbWindowText .RightToLeft = System.Windows. Forms.RightToLe ft.No
Me.tbWindowText .Size = New System.Drawing. Size(264, 25)
Me.tbWindowText .TabIndex = 0
Me.tbWindowText .Text = "Enter Window Session Name"
'
'Label1
'
Me.Label1.BackC olor = System.Drawing. SystemColors.Co ntrol
Me.Label1.Curso r = System.Windows. Forms.Cursors.D efault
Me.Label1.Font = New System.Drawing. Font("Arial", 8.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.ForeC olor = System.Drawing. SystemColors.Co ntrolText
Me.Label1.Locat ion = New System.Drawing. Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Right ToLeft = System.Windows. Forms.RightToLe ft.No
Me.Label1.Size = New System.Drawing. Size(233, 17)
Me.Label1.TabIn dex = 2
Me.Label1.Text = "Enter the partial name of the window to close:"
'
'cbCaseSensitiv e
'
Me.cbCaseSensit ive.Checked = True
Me.cbCaseSensit ive.CheckState =
System.Windows. Forms.CheckStat e.Checked
Me.cbCaseSensit ive.Location = New System.Drawing. Point(136, 64)
Me.cbCaseSensit ive.Name = "cbCaseSensitiv e"
Me.cbCaseSensit ive.Size = New System.Drawing. Size(136, 16)
Me.cbCaseSensit ive.TabIndex = 3
Me.cbCaseSensit ive.Text = "Case Sensitive Search"
'
'frmAskWinCapti on
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.BackColor = System.Drawing. SystemColors.Co ntrol
Me.ClientSize = New System.Drawing. Size(280, 95)
Me.Controls.Add (Me.cbCaseSensi tive)
Me.Controls.Add (Me.Command1)
Me.Controls.Add (Me.tbWindowTex t)
Me.Controls.Add (Me.Label1)
Me.Cursor = System.Windows. Forms.Cursors.D efault
Me.Font = New System.Drawing. Font("Arial", 8.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Icon = CType(resources .GetObject("$th is.Icon"),
System.Drawing. Icon)
Me.Location = New System.Drawing. Point(4, 22)
Me.Name = "frmAskWinCapti on"
Me.RightToLeft = System.Windows. Forms.RightToLe ft.No
Me.StartPositio n =
System.Windows. Forms.FormStart Position.Center Screen
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.EventArg s) Handles Command1.Click
Dim KillWindow As Object

KillWindow = FindWindowWild( "*" & tbWindowText.Te xt & "*",
cbCaseSensitive .Checked)
If KillWindow = 0 Then
tbWindowText.Te xt = "Sorry. [" & tbWindowText.Te xt & "] was not
found."
Else
SendMessage(Kil lWindow, WM_CLOSE, 0, 0)
tbWindowText.Te xt = "[" & tbWindowText.Te xt & "] 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 "PostMessag eA"
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,
ByVal lParam As Integer) As Integer

Declare Function SendMessage Lib "user32" Alias "SendMessag eA" (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(h wnd, 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 CloseWindowByhW nd(ByRef hwnd As Integer) As Integer
On Error GoTo ErrorCloseWindo wByhWnd
CloseWindowByhW nd = PostMessage(hwn d, WM_CLOSE, 0, 0)
Exit Function

ErrorCloseWindo wByhWnd:
MessageBox.Show (Err.Number & ":Error in CloseWindowByhW nd. Error
Message: " & _
Err.Description , MsgBoxStyle.Cri tical, "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(Add ressOf 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******@onlin e.nospam> wrote in message
news:9B******** *************** ***********@mic rosoft.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(P arent:=Me, url:=Me.HELP_UR L_PRE & Me.myWorker.Hel pFile)
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
1552
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 python from doing so? Thanks!
4
9017
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, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D
1
2602
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 analyzing the core in gdb, I see that the SIGILL seems to occur after _fini of a sharedlibrary... Also, from the backtrace I can see that some static data is getting deallocated and somehow the code seems to get into the .plt section..
29
4402
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 process. Is it correct?
1
1283
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 the actual file through bytes. using System; using System.Net.Sockets; using System.IO;
26
2200
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 total calories that the user input together. determine which food has the largest calories. how do i start to modifiy the program inorder to do the things i listed above. thanks #include <stdio.h> #include <stdlib.h>
4
1451
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 update this same field to indicate they are offline. However, how do I handle this when a user just X's out of the browser without logging off? I've set break points in the global.asax.cs file but the Session_End and Application_End functions...
2
1812
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 called the function wordcount, and then the function did everything including printing out the results. That worked. Now I want to make the function return an array of pointers to struct palabra so the calling function can manage the data as it...
3
2026
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 by running the following code when the program closes Dim proc, procs() As Process
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.