Pid=shell("XXXX")获取句柄

yaokai0405 2009-11-05 03:21:56
Pid=shell("XXXX")获取句柄

Pid = Shell(mFileName)

Hnd = OpenProcess(PROCESS_TERMINATE, 0&, Pid)

LenName = GetWindowTextLength(Hnd) 'Hnd取不到窗口名的长度

GetWindowText Hnd, strName, LenName + 1 'Hnd取不到窗口名
Hnd = FindWindow(vbNullString, strName)

SetParent Hnd, Me.hwnd


求教~~~~~
...全文
188 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2009-11-05
  • 打赏
  • 举报
回复

说错了,不是窗体句柄。
贝隆 2009-11-05
  • 打赏
  • 举报
回复
这个得到的是进程PID,而非进程句柄
zzhgb 2009-11-05
  • 打赏
  • 举报
回复
随便搜了下,你去验证吧
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId 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
Dim IfPid As Long

Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim Pid1 As Long
Dim wText As String * 255
GetWindowThreadProcessId hwnd, Pid1
If IfPid = Pid1 Then
GetWindowText hwnd, wText, 100
Form1.List1.AddItem "句柄:" & hwnd & " 标题:" & wText
End If
EnumWindowsProc = True
End Function
Public Sub Find_Window(ByVal Pid As Long)
IfPid = Pid
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 chenhui530 的回复:]
不会用google就是两api而已
[/Quote]
用陈辉的上个的两个关键词,Google下,大把simple code。
要学会搜索,朋友。
嗷嗷叫的老马 2009-11-05
  • 打赏
  • 举报
回复
Hnd = OpenProcess(PROCESS_TERMINATE, 0&, Pid)

LenName = GetWindowTextLength(Hnd)

我晕,进程句柄拿去取文本..............
chenhui530 2009-11-05
  • 打赏
  • 举报
回复
不会用google就是两api而已
yaokai0405 2009-11-05
  • 打赏
  • 举报
回复
那俩个东西没用过~
chenhui530 2009-11-05
  • 打赏
  • 举报
回复
你是要代码还是思路,给你提示了就应该自己动手了
yaokai0405 2009-11-05
  • 打赏
  • 举报
回复
EnumWindows和GetWindowThreadProcessId是怎么配合使用的,最好用代码说明一下,谢谢
chenhui530 2009-11-05
  • 打赏
  • 举报
回复
EnumWindows GetWindowThreadProcessId
yaokai0405 2009-11-05
  • 打赏
  • 举报
回复
ding~顶~
求教啊~

yaokai0405 2009-11-05
  • 打赏
  • 举报
回复
ding~顶~
求教啊~
yaokai0405 2009-11-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chenhui530 的回复:]
我晕Hnd 这个是进程句柄不是窗体句柄,楼上的也不要乱说误导新手
[/Quote]
如何去实现啊
chenhui530 2009-11-05
  • 打赏
  • 举报
回复
我晕Hnd 这个是进程句柄不是窗体句柄,楼上的也不要乱说误导新手
lorl2 2009-11-05
  • 打赏
  • 举报
回复
shell是异步的,再说,就算进程创建成功,窗口也不一定马上就有.
你要等一会再利用GetWindowTextLength
应该用个时钟或循环要检测

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧