Solved

Problem Closing an Application

Posted on 2004-08-18
8
217 Views
Last Modified: 2010-05-18
Hello all, I am having a small problem trying to close an application through a program.  The application I am trying to close is called ColdBuild.exe.  Here is my code:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10

Private Sub cmdCloseApp_Click()
Dim m As Long
m = FindWindow(vbNullString, "ColdBuild")
SendMessage m, WM_CLOSE, 0, 0
End
End Sub

The problem is, this button ends up closing _my_ application and leaves the ColdBuild application open.  Any suggestions on how to remedy this?
0
Comment
Question by:gwosgood
  • 4
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11835197
Try sending a WM_QUIT message instead.
0
 
LVL 2

Author Comment

by:gwosgood
ID: 11835209
how do i declare that?
i.e. to declare WM_CLOSE,
Private Const WM_CLOSE = &H10
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 11835212
Is "ColdBuild" the window caption on the ColdBuild.exe app? It's not the caption on your form is it?
0
 
LVL 2

Author Comment

by:gwosgood
ID: 11835228
no, coldbuild is the title of the coldbuild application.  MY application caption is PSWFIX
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11835252
Private Const WM_QUIT = &H12
0
 
LVL 2

Author Comment

by:gwosgood
ID: 11835279
ok carl tawn, i used your new WM_QUIT suggestion and believe it or not, my application still closes instead of the intended ColdBuild
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 125 total points
ID: 11835310
Your app is exiting because of the "End" statement after your call to SendMessage, rather than because of the SendMessage
0
 
LVL 2

Author Comment

by:gwosgood
ID: 11835343
d@mn, your right carl tawn ;)
appreciate the help
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now