|
-
Aug 10th, 2000, 01:29 PM
#1
Thread Starter
Hyperactive Member
Hi,
Does anybody know how I can detect if there is a window open with the name “window” and then close that window if it is open? I’m quite sure this can be done with the windows APIs but I don’t have a clue how? Thanks
-
Aug 10th, 2000, 01:42 PM
#2
Try this:
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
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Sub Command1_Click()
'Get the hWnd of the Window named Calculator
MyHwnd = FindWindow(vbNullString, "Calculator")
'If it's found then close it
If MyHwnd <> 0 Then
SendMessage MyHwnd, WM_CLOSE, 0&, 0&
SendMessage MyHwnd, WM_DESTROY, 0&, 0&
End If
End Sub
-
Aug 10th, 2000, 02:17 PM
#3
Thread Starter
Hyperactive Member
Thanks!
Thanks for the help Megatron!
-
Aug 10th, 2000, 03:03 PM
#4
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
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Sub Command1_Click()
'Get the hWnd of the Window named Calculator
MyHwnd = FindWindow(vbNullString, "Calculator")
'If it's found then close it
If MyHwnd <> 0 Then
SendMessage MyHwnd, WM_CLOSE, 0&, 0&
SendMessage MyHwnd, WM_DESTROY, 0&, 0&
End If
End Sub
a few days ago I tried this with IE,
I used the class IEFrame, and all it did was disable IE, and it wouldnt allow me to close it normally i had to end-task it.
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
|