现在我已经取得了一个对话框的句柄,想使用EnumChildWindows遍历它的每个子窗体,取得每个子窗体的标题名称谁给个示列啊

解决方案 »

  1.   


        public delegate bool EnumWindowsProc(IntPtr p_Handle, int p_Param);
            [DllImport("user32.dll")]
            public static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
            [DllImport("User32.dll", CharSet = CharSet.Auto)]
            public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER text, int nMaxCount);        
            [DllImport("user32.dll")]
            public static extern bool IsWindowVisible(IntPtr hWnd);
            [DllImport("user32.dll")]
            public static extern IntPtr GetWindowThreadProcessId(IntPtr hwnd, ref int lpdwProcessId);
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
            public struct STRINGBUFFER
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)]
                public string szText;
            }        private void button1_Click(object sender, EventArgs e)
            {
                MessageWindwos(this.Handle);
            }        public void MessageWindwos(IntPtr p_MessIntPrt)
            {
                GetWindowThreadProcessId(p_MessIntPrt, ref m_Pid);  //消息进程            EnumWindowsProc _EunmWindows = new EnumWindowsProc(NetEnumWindows);
                EnumWindows(_EunmWindows, 0);        
            }
            private  int m_Pid = 0;
            private  bool NetEnumWindows(IntPtr p_Handle, int p_Param)
            {
                if (!IsWindowVisible(p_Handle))return true;            STRINGBUFFER _TitleString = new STRINGBUFFER();
                GetWindowText(p_Handle, out _TitleString, 256);            int _PID = -1;
                GetWindowThreadProcessId(p_Handle, ref _PID);  //获取进程PID            if (_PID == m_Pid)
                {
                    MessageBox.Show(_TitleString.szText);
                }
                return true;
            }
    不知道是不是这个意思...根据你获取的消息获取进程ID 然后比较进程ID 
      

  2.   

    Option ExplicitPrivate Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPrivate Sub Command1_Click()
        Dim tWnd    As Long, hWnd As Long
        tWnd = FindWindow(vbNullString, "QQ2008 查找/添加好友")    hWnd = FindWindowEx(tWnd, 0, vbNullString, vbNullString)
        If hWnd <> 0 Then GetName hWnd
        Do While hWnd <> 0
            hWnd = FindWindowEx(tWnd, hWnd, vbNullString, vbNullString)
            If hWnd <> 0 Then GetName hWnd
        Loop
    End Sub
    Private Function GetName(ByVal hWnd As Long) As String
        Dim lpClassName    As String
        Dim retval    As Long
        Dim mname    As String
        Dim i    As Integer    lpClassName = Space(256)
        retval = GetClassName(hWnd, lpClassName, 256)
        i = InStr(1, lpClassName, Chr(0))
        mname = Left(lpClassName, i - 1)
        Debug.Print hWnd & "      " & mname
    End Function