Solved

Problem Closing an Application

Posted on 2004-08-18
8
220 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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