永发信息网

关于VB,取句柄

答案:3  悬赏:0  手机版
解决时间 2021-04-29 10:26
  • 提问者网友:那叫心脏的地方装的都是你
  • 2021-04-28 22:43

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Function GetPath(ByVal hwnd As Long) As String
Dim PID As Long, hPss As Long
Dim FileName As String * 1024
Call GetWindowThreadProcessId(hwnd, PID)
hPss = OpenProcess(&HF0000 Or &H100000 Or &HFFF, False, PID)
Call GetModuleFileNameExA(hPss, 0, FileName, 1024)
GetPath = Trim(FileName)
CloseHandle hPss
End Function

Private Sub Command1_Click()
MsgBox GetPath(Val())
End Sub

单击 按钮后 出现? 怎么回事呢?

我想点击按钮后 把取到的 句柄发送到Text1

最佳答案
  • 五星知识达人网友:青灯有味
  • 2021-04-29 00:07
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
获取指定窗口名的窗口句柄
全部回答
  • 1楼网友:走死在岁月里
  • 2021-04-29 01:36
Private Function GetPath(ByVal hwnd As Long) As String MsgBox GetPath(Val())
  • 2楼网友:行雁书
  • 2021-04-29 00:45

查找窗口句柄,小示例程序如下:

Option Explicit

'查找窗口句柄 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Command1_Click() Dim h As Long h = FindWindow(vbNullString, "计算器") If h <> 0 Then MsgBox "您已打开计算器程序" Text1.Text = h Else MsgBox "你未打开计算器程序" End If End Sub

FindWindow函数的详细功能,楼主可以百度一下,记得加分哦

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯