Solved

Problem Closing an Application

Posted on 2004-08-18
8
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:gwosgood
ID: 11835228
no, coldbuild is the title of the coldbuild application.  MY application caption is PSWFIX
0
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

623 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