|
-
Feb 23rd, 2002, 01:04 AM
#1
Thread Starter
New Member
Closing Widows, Closing an app
How does one detect if a certian application is opened, and how do you close it from VB?
I have an ExitWindowsEx procedure that shuts the computer down at a certian time (closing time ). When the computer is rebooted, the "Windows was shut down improperly" comes up, and scandisk runs. How do I "shut down properly" to prevent this?
-
Feb 23rd, 2002, 07:39 AM
#2
Conquistador
u can use findwindow to detect if an application is open, then SendMessage with wm_close as the message to close it
-
Feb 23rd, 2002, 09:36 AM
#3
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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_CLOSE = &H10
Private Sub Command1_Click()
Dim WinWnd As Long
WinWnd = FindWindow(vbNullString, "Caption Of Open Application")
If WinWnd > 0 Then 'it is running, so close it
PostMessage WinWnd, WM_CLOSE, CLng(0), CLng(0)
End If
End Sub
-
Feb 23rd, 2002, 06:47 PM
#4
Conquistador
yeah, that's the one
-
Mar 2nd, 2002, 11:06 AM
#5
Fanatic Member
I'm interested in this too. But does this work for app/windows that normally throw up modal dialogs like "Do you want to save..." before closing?
VB 6.0, Access, Sql server, Asp
-
Mar 2nd, 2002, 06:50 PM
#6
Conquistador
yes, but that is a child window, you need to use FindWindowEx to get the handle of 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
|