Where it can help: Suppose you want to close a window without closing that particular application and you only know the caption of the window. You cannot use process methods as it will close the entire application along with the window. Use the close_window() method along with window caption.
Code:
Imports System.Runtime.InteropServices <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function FindWindow( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function PostMessage(ByVal hWnd As IntPtr, _ ByVal Msg As UInteger, _ ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean End Function Private Const WM_CLOSE = &H10 Private sub Close_window() Dim CloseIt As Long CloseIt = FindWindow(vbNullString, "Caption of the window to close") PostMessage(CloseIt, WM_CLOSE, CLng(0), CLng(0)) End Sub