(以下都是windows下线程的相关函数)
得到当前线程句柄: GetCurrentThread(void)
得到当前线程ID: GetCurrentThreadId(void)
根据句柄得到线程ID: GetThreadId
根据窗口句柄得到此窗口所在线程的ID(同时得到进程的ID): GetWindowThreadProcessId
根据ID得到线程句柄: OpenThread(unsigned long)
挂起用SuspendThread
唤醒用ResumeThread
(强制)结束TerminateThread
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () 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 Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Sub Command1_Click()
Call List1_Click
End Sub
Private Sub Command2_Click()
Dim hwnd As Long
Dim s As String, t As String
List1Clear
hwnd = GetDesktopWindow()
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1AddItem "桌面:" & hwnd & " 类名:" & s & " 标题:" & t & vbCrLf
hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1AddItem "窗口:" & hwnd & " 类名:" & s & " 标题:" & t & vbCrLf
While hwnd <> 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1AddItem "窗口:" & hwnd & " 类名:" & s & "标题:" & t & vbCrLf
Wend
End Sub
Private Sub Form_Load()
Command1Caption = "获取所有控件"
Command2Caption = "遍历所有窗体"
End Sub
Private Sub EnumAllHandles(ByVal hwnd As Long)
Dim hn As Long
Dim firsthd As Long
Dim s As String, t As String
firsthd = GetWindow(hwnd, GW_CHILD)
firsthd = GetWindow(firsthd, GW_HWNDFIRST)
hn = firsthd
Do While hn <> 0
s = String(256, Chr(0))
GetClassName hn, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hn, t, 255
t = Replace(t, Chr(0), "")
Text1Text = Text1Text & "句柄:" & hn & " 父句柄:" & hwnd & " 类名:" & s & "标题:" & t & vbCrLf
TreeView1NodesAdd "k" & hwnd, tvwChild, "k" & hn, "句柄:" & hn & " 类名:" & s & "标题:" & t
EnumAllHandles hn
hn = GetWindow(hn, GW_HWNDNEXT)
If hn = firsthd Then Exit Do
Loop
End Sub
Private Sub List1_Click()
If List1ListIndex = -1 Then Exit Sub
TreeView1NodesClear
TreeView1NodesAdd , , "k" & Trim(Str(Val(Mid(List1Text, 4)))), List1Text
Text1Text = ""
EnumAllHandles Val(Mid(List1Text, 4))
TreeView1Nodes("k" & Trim(Str(Val(Mid(List1Text, 4)))))Expanded = True
End Sub
'添加两个按钮一个文本框一个列表框和一个树形图
试试下面的方法:
using SystemDiagnostics;
Process[] proes = ProcessGetProcesses();
foreach (Process pro in proes)
{
// 关联进程句柄
IntPtr proHandle = proHandle;
// 获得关联进程的主窗口句柄
IntPtr mainWindowsHandle = proMainWindowHandle;
}
调用格式: 〈整数型〉 对象.取窗口句柄 () - 系统核心支持库->窗口
英文名称:GetHWnd
取出本窗口或窗口组件的窗口句柄(即HWND)。本命令为高级对象成员命令。
*** 作系统需求: Windows
调用格式: 〈整数型〉 取鼠标所在窗口句柄 () - 应用接口支持库->窗口 *** 作
英文名称:GetHwndFromPoint
取鼠标所在窗口句柄。本命令为初级命令。
*** 作系统需求: Windows
使用EnumWindows和EnumChildWindows函数以及相对的回调函数EnumWindowsProc和EnumChildWindowsProc获取所有顶层窗口以及它们的子窗口(有些窗口做了特殊处理,比如QQ是不能通过这个方法获得的)!
易语言如何取指定窗口句柄。
如下参考:
1.首先,创建一个新程序,如下图所示。
2.在程序中绘制一个“按钮”,两个编辑框,两个标签,然后改变相应的名称来识别。
3.左击以下:剪辑(只有在没有点击的情况下才点击),程序,模块应用回,如下图。
4.在浏览窗口找到下载的超级模块位置,点击“超级模块”打开。
5.在模块下面会有一个额外的“超级模块”。
6.双击button1,在子例程“_button1_isclicked”下新建一个名为“I”的整数变量,然后编写如下代码:I=takehandle2(“记事本”)。编辑框1。Content=对文本的回答(I)。
7.写完以上代码,就可以得到“记事本”了。Exe”窗口句柄,然后,获取窗口标题!继续编码如下:编辑框2。内容=取窗口标题(取句柄2)(“记事本”)。Exe”))。
8.最后,调试并运行程序,就完成了。
以上就是关于如何取得当前线程的句柄全部的内容,包括:如何取得当前线程的句柄、如何获取窗体中组件的句柄、C#获取句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)