Directuihwnd form access under. NET based on API encapsulation

Source: Internet
Author: User
Tags reference
Access | encapsulation

Direct cut to the chase:

1. Add a reference. Project-> Add Reference->c:\progmme~1\msn Messenger\msnmsgr.exe

2. Using Messengerapi;

Statement:

Private Messengerapi.messengerclass MSN;
Private Messengerapi.imessengerconversationwnd Msnmsgwnd;

3.Init Add:

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; Get the IM window handle

   #region Get IM message
   system.intptr Ptruihwnd = Nativewin32.findwindowex ( Msnmsgwnd.hwnd, 0, "Directuihwnd", 0); //Get window inside Directuihwnd handle
   Guid guidcom= new GUID (0X618736E0, 0x3c3d,0x11cf,0x81,0xc,0x0,0xaa,0x0,0x38,0x9b,0x71); //com GUID
   iaccessible iacurrent=null;            //iaccessible Set
   try
    {
   
    Nativewin32.accessibleobjectfromwindow (Ptruihwnd, (int) Nativemsg.objid_client,ref guidcom,ref iacurrent); Gets the IAccessible set in Ptruihwnd

Iacurrent = (iaccessible) iacurrent.accparent; The father is the true container of the IAccessible set.
int _childcount = Iacurrent.accchildcount;
object[] _children = new Object[_childcount];
int _out;
Nativewin32.accessiblechildren (Iacurrent,0,_childcount-1,_children,out _out); From Iacurrent, add all the child iaccessible to the _children array
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. How to find a message form directly

Private void Findimwindow ()

{System.IntPtr Hwndstart;
int _next = 0;
Todo
{
Hwndstart = Nativewin32.findwindowex (0, _next, "Imwindowclass", 0);
_next = Hwndstart.toint32 ();
}while (_next!= 0);

}

6. Finally, the API declaration

#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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.