Trả lời mọi thắc mắc của bạn


Liệt kê những bài viết mới nhất

Bài viết mớiNgười viếtVào lúc
paltalk code HdAd
Sun Mar 06, 2016 1:28 am
vb ListView HdAd
Sun Mar 06, 2016 1:00 am
Find occurent of character in string nth HdAd
Sat Jan 16, 2016 10:48 pm
Send listbox items to textbox HdAd
Wed Jan 13, 2016 9:55 pm
[VB] Find word in listbox items HdAd
Wed Jan 13, 2016 7:55 pm
code cho hint2 HdAd
Wed Jan 13, 2016 3:22 pm
[vb] Font RTB HdAd
Tue Dec 29, 2015 10:29 am
[vb] selected text RTB HdAd
Tue Dec 29, 2015 9:06 am
[vb] send unicode text HdAd
Tue Dec 29, 2015 9:03 am
[vb] format multi richtextbox HdAd
Tue Dec 29, 2015 9:01 am
Trang web tai cac bang sang che HdAd
Mon Dec 28, 2015 1:28 pm
[VB] Sử dụng resource của chính chương trình HdAd
Sat Dec 26, 2015 8:56 pm
[vb] Phân biệt class và Module HdAd
Thu Dec 24, 2015 2:39 pm
[VB] MY API and Functions declaration HdAd
Mon Dec 21, 2015 1:45 pm
[vb] Khai báo và sử dụng hàm Setforeground HdAd
Mon Dec 21, 2015 1:29 pm
[VB] Sử dụng hàm Sendmessage để gửi tiếng việt, và format richtextbox HdAd
Mon Dec 21, 2015 1:26 pm
[VB] Find menu context handle/ID by SPY++ HdAd
Fri Dec 18, 2015 1:20 pm
[VB] Find menu context handle/ID - Vu Hai Ninh HdAd
Fri Dec 18, 2015 1:00 pm
[VB] Find menu context handle/ID HdAd
Fri Dec 18, 2015 12:54 pm
[VB] Sleep in VB program HdAd
Thu Dec 17, 2015 7:48 pm
[VB] CLose window if found HdAd
Wed Dec 16, 2015 7:07 pm
[VB] Không cho thay đổi kích cỡ form khi chạy HdAd
Wed Dec 16, 2015 3:28 pm
[VB] Không cho thay đổi text box khi chạy HdAd
Wed Dec 16, 2015 3:22 pm
[VB] Tìm cửa sổ và Button bằng FindWindow & FindWindowsEx HdAd
Wed Dec 16, 2015 3:16 pm
[VB] Xóa text mặc định của text box khi click HdAd
Wed Dec 16, 2015 3:12 pm


You are not connected. Please login or register

[VB] CLose window if found

View previous topic View next topic Go down  Message [Page 1 of 1]

1 [VB] CLose window if found on Wed Dec 16, 2015 7:07 pm

HdAd

avatar
Admin
Try using something like this. using 
Code:
Process.MainWindowTitle
[size]
 to get the Title Text and 
[/size]
Code:
Process.CloseMainWindow
[size]
 to close down the UI, its a little more graceful than killing the Process.[/size]
Note: Contains does a case-sensitive search
Code:
Imports System.Diagnostics
Module Module1

    Sub Main()
        Dim myProcesses() As Process = Process.GetProcesses

        For Each p As Process In myProcesses
            If p.MainWindowTitle.Contains("Notepad") Then
                p.CloseMainWindow()
            End If
        Next

    End Sub

End Module


As far as Win API functions try something like this. Be aware if you close the parent window youwill close the children also.
Code:
Module Module1
    Private Declare Auto Function FindWindowEx Lib "user32" (ByVal parentHandle As Integer, _
                                              ByVal childAfter As Integer, _
                                              ByVal lclassName As String, _
                                              ByVal windowTitle As String) As Integer

    Private Declare Auto Function PostMessage Lib "user32" (ByVal hwnd As Integer, _
                                                            ByVal message As UInteger, _
                                                            ByVal wParam As Integer, _
                                                            ByVal lParam As Integer) As Boolean

    Dim WM_QUIT As UInteger = &H12
    Dim WM_CLOSE As UInteger = &H10


    Sub Main()
        Dim handle As Integer = FindWindowEx(0, 0, Nothing, "YourFormsTitle")
        PostMessage(handle, WM_CLOSE, 0, 0)
    End Sub

End Module

View user profile http://hoidap.probb.org

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum