Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem Closing an Application

Posted on 2004-08-18
8
Medium Priority
?
225 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
Technology Partners: 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 500 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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

963 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