Private Declare Function FindWindow% Lib "user32" Alias "FindWindowA" (ByVal lpclassname As Any, ByVal lpCaption As Any) hwnd% = FindWindow%("wndclass_desked_gsk", 0&) If hwnd% = 0 Then '非VB环境 Msgbox "VB没有已经打开!" End Ifwndclass_desked_gsk是VB6的类名,你可以换成你的程序的类名,如果不知道可以做一个小程序来查看: Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) 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) Dim wnd Private Sub Form_Load() rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3) End SubPrivate Sub Timer1_Timer() Dim sClassName As String * 100 Dim pt32 As POINTAPI Dim ptx As Long Dim pty As Long Dim hWndOver As Long Static hWndLast As Long Call GetCursorPos(pt32) ' Get cursor position ptx = pt32.X pty = pt32.Y hWndOver = WindowFromPointXY(ptx, pty) ' Get window cursor is over r = GetClassName(hWndOver, sClassName, 100) ' Window Class If hWndOver <> hWndLast Then ' If changed update display hWndLast = hWndOver ' Save change Cls ' Clear the form Print "类名: "; Left(sClassName, r) End If End Sub
hwnd% = FindWindow%("wndclass_desked_gsk", 0&)
If hwnd% = 0 Then '非VB环境
Msgbox "VB没有已经打开!"
End Ifwndclass_desked_gsk是VB6的类名,你可以换成你的程序的类名,如果不知道可以做一个小程序来查看:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) 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)
Dim wnd
Private Sub Form_Load()
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
End SubPrivate Sub Timer1_Timer()
Dim sClassName As String * 100
Dim pt32 As POINTAPI
Dim ptx As Long
Dim pty As Long
Dim hWndOver As Long
Static hWndLast As Long
Call GetCursorPos(pt32) ' Get cursor position
ptx = pt32.X
pty = pt32.Y
hWndOver = WindowFromPointXY(ptx, pty) ' Get window cursor is over
r = GetClassName(hWndOver, sClassName, 100) ' Window Class
If hWndOver <> hWndLast Then ' If changed update display
hWndLast = hWndOver ' Save change
Cls ' Clear the form
Print "类名: "; Left(sClassName, r)
End If
End Sub