永发信息网

VB6中如何获得指定进程名称

答案:2  悬赏:30  手机版
解决时间 2021-05-22 21:27
  • 提问者网友:戎马万世
  • 2021-05-22 07:13
比如我启动VB6之后,那么在进程里面就会有个VB6.exe.进程,如何对这个进程进行时时监控
最佳答案
  • 五星知识达人网友:拾荒鲤
  • 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
要用api 貌似是getcurrentporcess
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯