|
-
May 24th, 2000, 11:21 PM
#2
_______
This might help...
Part of title:
This code uses EnumWindows to retrieve the title of all
windows in the system, compares it with the partial name,
and stops when a match is made. Code modified from a sample
available at http://www.thescarms.com
Code taken from a Q&A On Experts Exchange Posted By: Erick37
'~~~~~~~MODULE CODE~~~~~~~~~~~~
Option Explicit
Public Const WM_CLOSE = &H10
Public Const MAX_PATH = 260
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private sAppTitle As String
Public glHwnd As Long
Public Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As Long
Dim lResult As Long
Dim sWndName As String
fEnumWindowsCallBack = 1
sWndName = Space$(MAX_PATH)
lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
sWndName = Left$(sWndName, lResult)
'Search Title for our string
If (InStr(1, sWndName, sAppTitle, vbTextCompare) > 0) Then
Debug.Print sWndName
glHwnd = hwnd
fEnumWindowsCallBack = 0
End If
End Function
Public Function SearchWindows(sApp As String, hwnd As Long) As Long
sAppTitle = sApp
glHwnd = 0
Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
SearchWindows = glHwnd
End Function
'~~~~~~~FORM CODE~~~~~~~~~~~~~~
Option Explicit
Private Sub Command1_Click()
Dim sApp As String
'Find notepad with partial name
sApp = "notepa"
glHwnd = SearchWindows(sApp, Me.hwnd)
'End application if found
If glHwnd > 0 Then
PostMessage glHwnd, WM_CLOSE, 0&, 0&
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|