Ryan's District
November 22, 2008, 03:42:23 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Ryan's District Lottery: Claim your ticket or check
Jackpot details  
 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: HOWTO: Close Applications from Visual Basic  (Read 4861 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 07, 2006, 03:58:57 PM »

PRODUCT :Microsoft Visual Basic for Windows
PROD/VER:WINDOWS:4.0
OPER/SYS:NT WINDOWS
KEYWORDS:VB4ALL VB4WIN

======================================================================
------------------------------------------------------------------------
The information in this article applies to:

 - Standard, Professional, and Enterprise Editions of Microsoft
   Visual Basic for Windows, 16-bit only, version 4.0
------------------------------------------------------------------------

SUMMARY
=======

Periodically it may be necessary for a programmer to close down another
application from Visual Basic code. For example, your application might
conflict with some other known utility, so you need to close the
conflicting utility so your application can work correctly. The step-by-
step example in this article shows how to do it using the Windows API.

MORE INFORMATION
================

Step-by-Step Example
--------------------

1. Start a new Visual Basic project. Form1 is created by default.

2. Add a command button (Command1) to Form1.

3. Add the following code to the General Declarations section of Form1:

   Option Explicit

   Private Declare Function FindWindow Lib "User" (ByVal lpClassName _
      As Any, ByVal lpWindowName As Any) As Integer
   Private Declare Function PostMessage Lib "User" (ByVal hWnd _
      As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
      lParam As Any) As Integer

   Private Const WM_QUIT = &H12

   Private Sub Command1_Click()
     Dim sTitle As String
     Dim iHwnd As Integer
     Dim ihTask As Integer
     Dim iReturn As Integer
     sTitle = "Notepad - (Untitled)"
     iHwnd = FindWindow(0&, sTitle)
     iReturn = PostMessage(iHwnd, WM_QUIT, 0, 0&)
     MsgBox "Notepad has been Closed Down"
   End Sub

4. Start Notepad by double-clicking the Notepad Icon.

5. Activate Visual Basic, and press F5 to start the project. Click the
   command button and the instance of Notepad you started should
   automatically close down. The message box will confirm this.

NOTE: For Visual Basic for Windows, 32-bit only, version 4.0 and Visual
Basic for Windows version 5.0, you need to use the following code:

1. Start a new Visual Basic project. Form1 is created by default.

2. Add a command button (Command1) to Form1.

3. Add the following code to the General Declarations section of Form1:

   Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Private Const WM_QUIT = &H12

Private Sub Command1_Click()
    Dim sTitle As String
     Dim iHwnd As Long
     Dim ihTask As Long
     Dim iReturn As Long
     sTitle = "Untitled - Notepad"
     iHwnd = FindWindow(0&, sTitle)
     iReturn = PostMessage(iHwnd, WM_QUIT, 0&, 0&)
     MsgBox "Notepad has been Closed Down"

End Sub

4. Start Notepad by double-clicking the Notepad Icon.

5. Activate Visual Basic, and press the F5 key to start the project.
   the command button and the instance of Notepad you started should
   automatically close down. The message box will confirm this.
======================================================================
Keywords          : VB4ALL VB4WIN
Version           : WINDOWS:4.0
Platform          : NT WINDOWS
Issue type        : kbhowto

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.  MICROSOFT DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO NOT ALLOW THE EXCLUSION
OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1997.
Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
« on: October 07, 2006, 03:58:57 PM »

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.209 seconds with 31 queries.

Google visited last this page Today at 08:18:19 AM