·您的位置: 首页 » 资源教程 » 编程开发 » ASP.NET » .net下基于API封装的DirectUIHWND窗体访问

.net下基于API封装的DirectUIHWND窗体访问

类别: ASP.NET教程  评论数:0 总得分:0
 

直接切入正题:

1.添加引用. 项目->添加引用->C:/Progmme~1/MSN Messenger/msnmsgr.exe

2. using MessengerAPI;

声明:

private MessengerAPI.MessengerClass msn;
private MessengerAPI.IMessengerConversationWnd msnMsgWnd;

3.Init里添加:

msn = new MessengerClass();
   msn.OnIMWindowCreated +=new DMessengerEvents_OnIMWindowCreatedEventHandler(msn_OnIMWindowCreated);
   msn.OnIMWindowDestroyed +=new DMessengerEvents_OnIMWindowDestroyedEventHandler(msn_OnIMWindowDestroyed);

4.

private void msn_OnIMWindowCreated(object pIMWindow)
  {
   msnMsgWnd = (IMessengerConversationWnd) pIMWindow; //取得IM窗口句柄

  

   #region Get IM Message
   System.IntPtr ptrUIHWND = NativeWIN32.FindWindowEx(msnMsgWnd.HWND, 0, \"DirectUIHWND\", 0);  //取得窗口内DirectUIHWND句柄
   Guid guidCOM= new Guid(0x618736E0,0x3C3D,0x11CF,0x81,0xC,0x0,0xAA,0x0,0x38,0x9B,0x71);  //COM的GUID
   IAccessible IACurrent=null;            //IAccessible集
   try
   {
   
    NativeWIN32.AccessibleObjectFromWindow(ptrUIHWND,(int)NativeMsg.OBJID_CLIENT,ref guidCOM,ref IACurrent); //取得ptrUIHWND中IAccessible集

    IACurrent = (IAccessible)IACurrent.accParent;  //其父,才是IAccessible集真正的容器
    int _ChildCount = IACurrent.accChildCount;
    object[] _Children = new object[_ChildCount];
    int _out;
    NativeWIN32.AccessibleChildren(IACurrent,0,_ChildCount-1,_Children,out _out); //从IACurrent中,将所有子IAccessible加入_Children数组中
    foreach(IAccessible _child in _Children)
    {
     string _accName = _child.get_accName((int)NativeMsg.CHILDID_SELF);
    
    }

   }
   catch(Exception ex)
   {
    throw ex;
   }
   #endregion
  }

  private void msn_OnIMWindowDestroyed(object pIMWindow)
  {
   msnMsgWnd = null;
  }

5.直接查找消息窗体的方法

Private void FindIMwindow()

{System.IntPtr hWndStart;
   int _next = 0;
   do
   {
    hWndStart = NativeWIN32.FindWindowEx(0, _next, \"IMWindowClass\", 0);
    _next =  hWndStart.ToInt32();
   }while(_next != 0);

}

6.最后是API声明

 #region API wrapper
 public class NativeWIN32
 {
  [DllImport(\"user32.dll\", CharSet=CharSet.Auto)]
  public static extern IntPtr FindWindowEx(
   int parent /*HWND*/,
   int next /*HWND*/,
   string lpszClass,
   string sWindowTitle);

  [DllImport(\"Oleacc.dll\")]
  public static extern int AccessibleObjectFromWindow(
   IntPtr hwnd,
   int dwObjectID, 
   Guid refID,
   ref IAccessible ppvObject);

  [DllImport(\"Oleacc.dll\")]
  public static extern int AccessibleChildren(
   Accessibility.IAccessible paccContainer,
   int iChildStart,
   int cChildren,
   [Out] object[] rgvarChildren,
   out int pcObtained);

 }
 public enum NativeMsg:long {
  CHILDID_SELF  = 0,
  CHILDID_1   = 1,
  OBJID_CLIENT  = 0xFFFFFFC
 }
 #endregion




-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1