如何得知某視窗的路徑?

這是一個從留言板得出的一個問題,如何得知某視窗的路徑?

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowModuleFileName Lib "user32" Alias "GetWindowModuleFileNameA" (ByVal hwnd As Long, ByVal lpszFileName As String, ByVal cchFileNameMax As Long) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Private Sub Form_Activate()
Dim TextLength As Integer
Dim Word As String * 255
Dim PathName As String * 255
Dim PathLength As Long
Dim ModuleName As Long
Dim tmpstr As String
Dim tmphwnd As Long
 Do
  DoEvents
  TextLength = GetWindowText(GetForegroundWindow, Word, 255)
  Text1.Text = Left(Word, TextLength)
  PathLength = GetWindowModuleFileName(GetForegroundWindow, PathName, 255)
  Text2.Text = Left(PathName, PathLength)
 Loop
End Sub


上一頁