你可以用两种方法来获取窗体的句柄,一种是遍历桌面上的所有窗口,用窗口标题来查找,这要求你起码知道窗口标题的一部分。另一种是用WindowFromPoint函数来获取,要求这个窗体必须在桌面上可见。

解决方案 »

  1.   

    参考<<windows核心编程>>
    得到窗口handle可以用FindWindow===========================================================
    我要学好C++啊 \(-o-)/
    ===========================================================
      

  2.   

    handle=FindeWindow("","your window title")
    'API
      

  3.   

    killer000777(抢分):   InstanceToWnd在winApi找不到呀!是我的api版本不够吗?,我是用vb6.0自带的api。
      

  4.   

    ItSeeker() 我说网页是未知的,因此"your window title"也是未知的,谢谢你的热心!
      

  5.   

    EnumProcesses   
    EnumProcessModules  
      

  6.   

    我明天给你查查,不是三大DLL里的
      

  7.   

    Azi03(微风轻扬) 的方法我试过,可以的,等 killer000777(抢分) 明天的结果
    就将分数发下去!
      

  8.   

    mm:
    greater than 32 if successful, or an error value that is less than or equal to 32 otherwise.
      

  9.   

    Option ExplicitPrivate Const WM_CLOSE = &H10
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub EndFun()
    On Error GoTo ErrTrap
        
        Dim hwnd                As Long
        Dim i                   As Long
        Dim WinNm               As String
        
        WinNm = "about:blank - Microsoft Internet Explorer"
        hwnd = FindWindow(vbNullString, WinNm)
        If hwnd <> 0 Then i = PostMessage(hwnd, WM_CLOSE, 0, 0)
        
        GoTo WayOut
    ErrTrap:
    WayOut:
    End SubPrivate Sub Form_Load()
        EndFun
    End Sub
      

  10.   

    Private Declare Function FindWindowLong Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wcmd As Long) As LongPrivate Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long
    Dim test_pid As Long
    Dim test_thread_id As Long
        ' Get the first window handle.
        test_hwnd = FindWindowLong(ByVal 0&, ByVal 0&)    ' Loop until we find the target or we run out
        ' of windows.
        Do While test_hwnd <> 0
            ' See if this window has a parent. If not,
            ' it is a top-level window.
            If GetParent(test_hwnd) = 0 Then
                ' This is a top-level window. See if
                ' it has the target instance handle.
                test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)            If test_pid = target_pid Then
                    ' This is the target.
                    InstanceToWnd = test_hwnd
                    Exit Do
                End If
            End If
            ' Examine the next window.
            test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
        Loop
    End Function