For i = 0 To MyWin.Count - 1
If WndToProcId(MyWin(i).hwnd) = WndToProcId(MouseDC.MDC) Then
Dim Str As String
Str = Right(MyWin(i).LocationURL, Len(MyWin(i).LocationURL) - 8)
Text1.Text = Replace(Str, "/", "\")
End If
Next
--------------
我这句怎么就行呢,楼主没有看吗?
Private Sub Form_Load()
Set MyWin = New ShellWindows
Timer1.Interval = 1000
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set MyWin = Nothing
End Sub
Private Sub Timer1_Timer()
If MyWin.Count = 0 Then Exit Sub
Dim i As Long
For i = 0 To MyWin.Count - 1
If WndToProcId(MyWin(i).hwnd) = WndToProcId(MouseDC.MDC) Then
Dim Str As String
Str = Right(MyWin(i).LocationURL, Len(MyWin(i).LocationURL) - 8)
Text1.Text = Replace(Str, "/", "\")
End If
Next
End Sub
------------------------------
Option Explicit
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type DGfor3
ponX As Long
ponY As Long
MDC As Long
End Type
Public Function MouseDC() As DGfor3
On Error Resume Next
Dim Cur As POINTAPI
GetCursorPos Cur
MouseDC.MDC = WindowFromPoint(Cur.x, Cur.y)
MouseDC.ponX = Cur.x
MouseDC.ponY = Cur.y
End Function
Public Function TitleToWnd(ByVal strTitle As String, Optional strClassName As String = vbNullString) As Long
TitleToWnd = FindWindow(strClassName, strTitle)
End Function
Public Function WndToProcId(ByVal hwnd As Long) As Long
GetWindowThreadProcessId hwnd, WndToProcId
End Function
---------------
FORM1中有一个TEXT、TIMER。
Private Sub Command1_Click() '向上用
Dim Arr() As String
Dim i As Long
Dim sRet As String
Dim Str As String
Str = Text1.Text
If Right(Str, 1) = "\" Then Str = Left(Str, Len(Str) - 1)
Arr = Split(Str, "\")
For i = LBound(Arr) To UBound(Arr) - 1
If Len(Arr(i)) > 0 Then
sRet = sRet & Arr(i) & "\"
End If
Next
MsgBox sRet
End Sub
Private Sub Timer1_Timer() 'timer1.Interval=3000,后退用
SendKeys Chr(8)
End Sub
Public Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type DGfor3
ponX As Long
ponY As Long
MDC As Long
End Type
Public Function MouseDC() As DGfor3
On Error Resume Next
Dim Cur As POINTAPI
GetCursorPos Cur
MouseDC.MDC = WindowFromPoint(Cur.x, Cur.y)
MouseDC.ponX = Cur.x
MouseDC.ponY = Cur.y
End Function