borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (ShellExecuteEx)Next Topic (A very stupid Question!) New Topic New Poll Post Reply
AndreaVB Forum : API : Close an API
Poster Message
lao
Level: Protégé

Registered: 27-07-2005
Posts: 4

icon Close an API

How can I close a file from VB6?

I need to close a file opened  with ShellExecute, but I can't close it by code.

somebody can help me?

Thanks a looot !

____________________________
Lao  :o)

27-07-2005 at 02:14 AM
View Profile Send Email to User Show All Posts | Quote Reply
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151
icon Re: Close an API

hi,
u can use the following API , if u have the handle of the file opened....


Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


____________________________
lOsT...

27-07-2005 at 03:40 PM
View Profile Send Email to User Show All Posts | Quote Reply
Asim-GDI GURU
Level: Sage

Registered: 29-07-2005
Posts: 54
icon Re: Close an API

Hey bro,
I found a solution to your problem.Its a case study which will help you alot.Its just for your problem...

http://www.freevbcode.com/ShowCode.asp?ID=670

Hope it helps you...

Regards,
Asim Siddiqui...

29-07-2005 at 02:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
lao
Level: Protégé

Registered: 27-07-2005
Posts: 4
icon Re: Close an API

I still can't close the file.... could somebody help me please??

____________________________
Lao  :o)

03-10-2005 at 06:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
lao
Level: Protégé

Registered: 27-07-2005
Posts: 4
icon Re: Close an API

I've tried but i can't.... i'm not an API's expert.. do you?

could you help me?

____________________________
Lao  :o)

03-10-2005 at 06:35 PM
View Profile Send Email to User Show All Posts | Quote Reply
Asim-GDI GURU
Level: Sage

Registered: 29-07-2005
Posts: 54
icon Re: Close an API

send your program..
we'll try what we can do...

03-10-2005 at 09:19 PM
View Profile Send Email to User Show All Posts | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: Close an API

Would this code helps. It close other external window application.

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, lParam As Any) As Long

Public Const WM_CLOSE = &H10

Private Sub cmdClose_Click()

Dim winHwnd As Long
Dim RetVal As Long

winHwnd = FindWindow(vbNullString, Text1.Text)

Debug.Print winHwnd

If winHwnd <> 0 Then
  RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
  If RetVal = 0 Then
    MsgBox "Error posting message."
  End If
Else
  MsgBox Text1.Text + " is not open."
End If

End Sub




____________________________
Im JAMES  

04-10-2005 at 01:06 AM
View Profile Send Email to User Show All Posts | Quote Reply
Asim-GDI GURU
Level: Sage

Registered: 29-07-2005
Posts: 54
icon Re: Close an API

I dont think there's any problem in your code.I think that the code is not getting the correct Window title, and so wrong window handle.See the following example from ALLAPI:


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, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    'Ask for a Window title
    Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
    'Search the window
    WinWnd = FindWindow(vbNullString, Ret)
    If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    'Show the window
    ShowWindow WinWnd, SW_SHOWNORMAL
    'Post a message to the window to close itself
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub

THIS IS AN EDITED VERSION OF THE ORIGINAL CODE.


[Edited by Asim-GDI GURU on 04-10-2005 at 07:23 AM GMT]

04-10-2005 at 02:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : Close an API
Previous Topic (ShellExecuteEx)Next Topic (A very stupid Question!) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder