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