«  屏蔽掉Alt+F4组合键!   |   Blog首页   |   visual studio 2005... »

2006/08/19

获得句柄!

有这样一个函数,它的作用是将进程的ID转换成它的句柄!(差不多是把小名换成大名的!)

Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    'Find the first window
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    Debug.Print "hwnd="; test_hwnd
    Do While test_hwnd <> 0
        'Check if the window isn't a child
        If GetParent(test_hwnd) = 0 Then
            'Get the window's thread
            Debug.Print "run here"
            test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
            If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Debug.Print "result="; InstanceToWnd
                Exit Do
            End If
        End If
        'retrieve the next window
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function

我现在在这边碰到一个问题:如果我调用记事本(C:\winnt\notepad.exe),程序就运行正常。如果调用命令行(C:\winnt\system32\cmd.exe)的话,就得不多进程的句柄?

为什么呢?

 

blown 发表于 2006-08-19 15:54  阅读(245) 评论( 0) 引用( 0) 逻辑
所有人可见

  • 收藏文章:
  • save at del.icio.us
  • save at digg
  • save at my yahoo
  • save at blinklist
  • save at furl
  • save at simpy
  • save at blogmarks
  • submit at reddit
  • save at spurl
  • save at shadows
  • save at rawsugar
  • save at bloglines

引用

http://www.uuzone.com/app/trackBack.do?type=blog&trackBackID=128528

相关内容
更多..

回复列表每两分钟自动刷新一次,想立即刷新吗?点击这里

您的浏览器可能不支持Frame, 优友地带需要使用Frame才能显示正常页面!