?
Solved

Closing Applications from VB - Need an ans ASAP

Posted on 2000-01-20
9
Medium Priority
?
159 Views
Last Modified: 2010-05-02
I am creating a program in VB 6 that opens other applications like Word, Excel, IE, etc. I used ShellExecute to open the files/applications. Now I need a way to fully close the applications after I am done using them.

Things I thought baout were FindExecutable, TerminateProcess, but have not reallyhad much luck in determining if they will work  good or not. Need some help fast!!!!!!!!1
0
Comment
Question by:slimbx
  • 4
  • 4
9 Comments
 
LVL 6

Expert Comment

by:Jon_Raymond
ID: 2373182
What are you doing in the applications.  Can you do it under the application's VBA program control, or can you do it under program control from VB?
0
 

Author Comment

by:slimbx
ID: 2373196
Under program control from VB. I am using ShellExecte to open different files and application programs from with in my program.
0
 
LVL 2

Accepted Solution

by:
adityau earned 40 total points
ID: 2373198
Use the following code

Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) 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 Command2_Click()
    lngreturn = FindWindow(vbEmpty, Window Caption)
    SendMessage lngreturn, WM_CLOSE, 0, 0
End Sub
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:slimbx
ID: 2373278
In this statement,

lngreturn = FindWindow(vbEmpty, Window Caption)

I know that you dim a var as long (lngreturn)

.. vbEmpty would be a null handle?
, and Window Caption - would that be the title of the application window to close?

 Could you give me a example putting in some fake vars or something. I understand the code, but dont really have a way of telling what I cana nd need to put in there.
0
 
LVL 2

Expert Comment

by:adityau
ID: 2373285
Suppose you have opened Experts Exchange in Netscape communicator gold, the caption of the title window shows "Visual Basic Question - Netscape". Use this as the parameter as the window caption. If you open Word, the caption would be "Microsoft Word - Document1". Use this. The exact caption of the window should be used.

I tested the given code with the Notepad.

I used

lngReturn = FindWindow(vbEmpty,"Untitled - Notepad".

It worked with me.
0
 

Author Comment

by:slimbx
ID: 2374233
Okay, with that in mind that you need to use the exact caption of the window, my program opens ANY file(s) in almost any application. So how can I know what file is opened and what the caption reads for this to work properly? I cant.

Isnt there any other API calls that can close applications.

App.PrevInstance will tell me how many instances of an app are open, is there any other property like that that can close the applications down though?

0
 
LVL 2

Expert Comment

by:adityau
ID: 2374301
You have an array which will tell you what all windows are opened using your applications.

Use EnumWindows to get all the parent windows and loop through them to close the window which you want to close.

Redim the array
0
 

Author Comment

by:slimbx
ID: 2374351
Hate to ask, but do you happen to have any code examples of this. I have not reached this far into API calls for a while, and need a little help.
0
 
LVL 2

Expert Comment

by:adityau
ID: 2376669
Give me your e-mail id. Mine is aditya@cgs.cgsmith.soft.net

I will send you a sample project.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 Month5 days, 12 hours left to enroll

589 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