首页 | 麦客学吧 | 视频教程 | FLASH小游戏 | 素材下载 | 常用工具
您当前的位置:首页 > 程序开发 > C# > 正文

C#控制Windows Messenger和Windows Live Messenger窗口发送消息

出处:麦客学吧 [2007-6-28 17:22:39] 作者:佚名 点击数:167

讨论交流:http://x8.maicoo.com/team/8659.html

前端时间做了Messenger助手,后来发现只支持Windows Messenger,不支持Windows Live Messenger,最近改了一下,用到了Active Accessibility编程,代码如下:
using System;
using Accessibility;

namespace MessengerHelper
{
    /**//// <summary>
    /// 对Messenger窗口进行操作
    /// </summary>
    public class MessengerWindowHelper
    {
        IntPtr _messengerWindowHandle ;
        IntPtr _inputBoxHandle ;
        IntPtr _submitButtonHandle ;
        IAccessible _inputBox ;
        IAccessible _submitButton ;

        private MessengerWindowHelper(){}
        public MessengerWindowHelper(IntPtr windowHandle)
        {
            _messengerWindowHandle = windowHandle ;
            _inputBoxHandle = GetInputBoxHandle() ;
            _submitButtonHandle = GetSubmitButton() ;

            if (_inputBoxHandle == IntPtr.Zero && _submitButtonHandle == IntPtr.Zero)
            {
                GetAccessibleObjects(_messengerWindowHandle, out _inputBox, out _submitButton);
            }
        }

        /**//// <summary>
        /// 输入消息
        /// </summary>
        /// <param name="message"></param>
        public void InputMessage(string message)
        {
            if (_inputBox == null)
            {
                Win32.SendMessageString(_inputBoxHandle, Win32.WM_SETTEXT, IntPtr.Zero, message);           
            }
            else
            {
                _inputBox.set_accValue(Win32.CHILDID_SELF, message) ;
            }
        }

        /**//// <summary>
        /// 发送消息
        /// </summary>
        public void SendMessage()
        {
            if (_submitButton == null)
            {
                Win32.SendMessageInt(_submitButtonHandle, Win32.WM_CLICK, IntPtr.Zero, 0);            
        &

【责任编辑: lanier

素材中心
麦客酷站赏析频道

精彩图文推荐

关于本站 - 联系站长 - 广告服务 - 合作伙伴 - 网站地图 - 版权声明 - 报告错误 - 收藏本站 | Http://www.MaiCoo.com

Copyright © 2005 - 2008 MaiCoo.com All Rights Reserved

违法和不良信息举报中心 本站服务器空间和带宽由雷克斯网络提供赞助
浙ICP备06017818号