|
-
Jan 3rd, 2002, 05:11 AM
#1
Thread Starter
New Member
how do i close a file using Api
closing a file using Api ?
Pls help me
Thank you
-
Jan 3rd, 2002, 05:30 AM
#2
Thread Starter
New Member
i mean ending the program like doing a (end task from a Ctrl_Alt_Del command)
-
Jan 3rd, 2002, 05:42 AM
#3
Thread Starter
New Member
-
Jan 3rd, 2002, 07:04 AM
#4
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 cmdCloseApp_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "Caption Of Window To Be Closed")
PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
End Sub
-
Jan 3rd, 2002, 09:05 AM
#5
Thread Starter
New Member
if i wanna close c:\windows\notepad.exe
how should i do it ?
-
Jan 3rd, 2002, 09:56 AM
#6
Thread Starter
New Member
can anyone show me a example on
using api to close C:\windows\notepad.exe ??
pls
thank you
-
Jan 3rd, 2002, 10:28 AM
#7
Hack showed you one way. This works for Notepad open with an untitled document.
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 cmdCloseApp_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "Untitled - Notepad")
PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
End Sub
The other alternative is use EnumWindows with a callback routine to find the process that notepad has. Unless you really need an all-purpose Notepad killer, stick with the simple code above.
using enumwindows:
Code:
'Add this code to a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'Set the form's graphics mode to persistent
Me.AutoRedraw = True
'call the Enumwindows-function
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
'Add this code to a module
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
Form1.Print Str$(hwnd) + " " + sSave
'continue enumeration
EnumWindowsProc = True
End Function
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
|