如何通过进程得到窗体句柄?

用findwindow我会,我想知道怎么用指定的进程名,获得窗体句柄,如进程名为“test.exe”先上100分,解决再加分。。。。... 用findwindow我会,我想知道怎么用指定的进程名,获得窗体句柄,如进程名为“test.exe” 先上100分,解决再加分。。。。 展开
 我来答
匿名用户
2013-08-24
展开全部
这段代码你看下 希望对你有帮助 Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'查找进程的函数
Private Function fun_FindProcess(ByVal ProcessName As String) As Long
Dim strdata As String
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim mName As String
Dim i As Integer, pid As Long
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then
Do
i = InStr(1, my.szExeFile, Chr(0))
mName = LCase(Left(my.szExeFile, i - 1))
If mName = LCase(ProcessName) Then
pid = my.th32ProcessID
fun_FindProcess = pid
Exit Function
End If
Loop Until (Process32Next(l, my) < 1)
End If
l1 = CloseHandle(l)
End If
fun_FindProcess = 0
End Function

Private Sub Form_Load()
if fun_FindProcess("123.exe") <> 0 then
Text1.Text="123.exe程序已启动"
Else
Text1.Text = ""
End If
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-08-24
展开全部
http://blog.csdn.net/xykwgjyygy/archive/2008/03/12/2172900.aspx有你需要的,太多了,不解释和粘贴出来了,自己去看!!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式