VB6中如何获得指定进程名称
- 提问者网友:戎马万世
- 2021-05-22 07:13
- 五星知识达人网友:拾荒鲤
- 2021-05-22 08:22
楼主您好 VB技术部 为您解答
在窗体上放置两个按钮 Command1 名字为开始获取 Command2 名字为停止获取 一个list 一个timer然后把timer 的属性 Enabled 设置为False Interval填写为1000 加入以下代码
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 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch 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) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const SWP_NOMOVE = &H2
Dim s As String
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Command1_Click()
List1.Clear
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim lpPoint As POINTAPI
Dim QQhwnd As Long
Dim sBuffer As String
sBuffer = Space(255)
GetCursorPos lpPoint
QQhwnd = WindowFromPoint(lpPoint.X, lpPoint.Y)
GetWindowText QQhwnd, sBuffer, 255
List1.AddItem sBuffer
End Sub
运行后点下按钮 然后鼠标按下你要获取的窗口 1秒自动获得进程名称
效果图
- 1楼网友:山河有幸埋战骨
- 2021-05-22 09:30