private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            richHandle = IntPtr.Zero;
            EnumWindows(EnumFunc, 0);
            if (richHandle == IntPtr.Zero)
                return;
            Console.WriteLine(Process_ReadRichEditText(richHandle));
        }        public bool EnumFunc(IntPtr hwnd, int lParam)
        {
            if (!IsWindowVisible(hwnd))
                return true; // 不可见             StringBuilder vBuffer = new StringBuilder(256);
            GetClassName(hwnd, vBuffer, vBuffer.Capacity);
            string name = vBuffer.ToString();
            if (vBuffer.ToString() == "TXGuiFoundation")
            {
                uint vProcessId;                GetWindowThreadProcessId(hwnd, out vProcessId);
                var nameid = GetProcessName(vProcessId).ToLower();
                if (GetProcessName(vProcessId).ToLower() == "qq.exe")
                {
                    GetWindowText(hwnd, vBuffer, vBuffer.Capacity);
                    // 标题中含"聊天中" 
                    if (vBuffer.ToString().IndexOf("杜老师") >= 0)
                    {
                        //在这里应该是要找这个窗体里面的控件才对啊?为什么这里是枚举他的子窗口?
                        //还有他这里不会进入@EnumChild方法,我想是因为他找不到这个子窗口的原因?
                        //那这里怎么来枚举这个窗体的所有控件呢? 
                        //谢谢                        
                        EnumChildWindows(hwnd, @EnumChild, lParam);
                        return false;
                    }
                }
            }
            return true;
        }
我上面用: EnumWindows(EnumFunc, 0); 方法来得到所有窗体
然后在EnumFunc中判断窗体类型是否为:TXGuiFoundation且进程为"qq.exe"
如果是的话判断QQ聊天窗体的标题是否为有:“杜老师”
如果有的话,我就要“枚举这个窗体的所有控件”,来找到聊天输入框
但是现在,我不知道旧城改造以来“枚举这个窗体的所有控件”谢谢 

解决方案 »

  1.   

    先在spy++中看看。如果spy++没有列出来,那么就是画出来的。
      

  2.   

    spy++有个树状视图的,可以分层显示子窗口相当于你的enumchildwindows如果列不出来,那就是没有了。如果列出来,看看你代码步入的“路径”是否正确。
      

  3.   

    QQ的不行,因为QQ的不是标准windows控件,你可以通过hook DrawText,TextOut之类的函数实现抓取文字的功能
      

  4.   

    我要读取到输入框,然后输入框输入数据,谢谢没有办法吗?
    我发现WPF写的程序WINAPI也得不到句柄
      

  5.   

    刚才试了下,发现微软的UIAutomation库果然强大,spy++抓不出来的,用这个能抓出来,我写了个函数,可以正常获取QQ发送框中的内容public string GetQQEditText()
            {
                AutomationElement desktop = AutomationElement.RootElement;
                AutomationElement QQwindow = desktop.FindFirst(TreeScope.Children, new AndCondition(
                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),
                        new PropertyCondition(AutomationElement.NameProperty, "对方昵称")));
                AutomationElement QQedit = QQwindow.FindFirst(TreeScope.Subtree, new AndCondition(
                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
                        new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "编辑")));
                return ((ValuePattern)QQedit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;
            }
      

  6.   


    试了下WPF的程序,也可以轻松获取
      

  7.   


    才知道有这个东东, 似乎很牛X的样子, 谢谢啊。
    他里面调的API都是公开的吗? 
      

  8.   


    是啊,这个.net自带的库,很好用,不过很多人不知道,还在用win32api获取窗体,该库不是一般的强大