Private Declare Function GetWindowModuleFileName Lib "user32" (ByVal hwnd As Long, lpszFileName As String, ByVal nBufferSize As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const MAX_PATH = 260
Private Sub Command1_Click()
' 获得鼠标坐标
Dim stPos As POINTAPI
GetCursorPos stPos
' 获得进程全路径及文件名
Dim strFileName As String
Dim nBufferSize As Long
nBufferSize = MAX_PATH
strFileName = String(nBufferSize, Chr(0))
Dim nFileNameLen As Long
nFileNameLen = GetWindowModuleFileName(WindowFromPoint(ByVal stPos.x, ByVal stPos.y), ByVal strFileName, ByVal nBufferSize)
strFileName = Left(strFileName, nFileNameLen)
' 获得进程名
Dim strProcessName As String
strProcessName = Mid(strFileName, InStrRev(strFileName, "\") + 1)
MsgBox strProcessName