已运行一个clarify.exe的程序(是MDI窗体)。在任务管理器中看到了clarify.exe的进程。如何通过进程得到主窗体的句柄。

解决方案 »

  1.   

    用findwindow根据类名获得窗口句柄,然后用showwindow和SetForegroundWindow将程序激活
      

  2.   

    是不是MDI主窗口?
    Public Function GetMDIFrame() As Long
        Dim hwnd As Long
        Dim ProcessID As Long
        'must be child from the desktop window
        hwnd = GetWindow(GetDesktopWindow, GW_CHILD)
        'while theres a window...
        While hwnd <> 0
            ProcessID = GetWindowThreadProcessId(hwnd, ProcessID)
            If ProcessID = App.ThreadID Then 'same thread?
                'same thread --> test window class
                If Right(LCase(WindowClass(hwnd)), 7) = "mdiform" Then
                    GetMDIFrame = hwnd
                    Exit Function
                End If
            End If
            'next window
            hwnd = GetWindow(hwnd, GW_HWNDNEXT)
        Wend
        'no MDWindow
        GetMDIFrame = 0End Function
      

  3.   

    这段代码是寻找当前进程中的MDI主窗口句柄
    作用是可以把DLL中的窗口设到该进程中唯一的mdi主窗口中座位child
      

  4.   

    激活!!
    SendMessage hParent, WM_NCACTIVATE, 1, ByVal 0& 'activate form
      

  5.   

    假设你窗口的类名为mytest(可用spy++查看),则代码如下:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_RESTORE = 9
    Private Const SW_SHOW = 5Private Sub Command1_Click()
        Dim mhwnd As Long
        mhwnd = FindWindow("mytest", vbNullString)
        ShowWindow mhwnd, SW_RESTORE
        SetForegroundWindow mhwnd
    End Sub
      

  6.   

    我用spy++的find window得到的类名是:AFT:100000:8:10011:0:12345
    后面的12345是会变的,每次启动都不一样.这怎么通过Class得到窗口句柄?