开发者

How to read the contents of a screen from another application [Office Communicator]

Knowing the hwnd of the window, how do I read the contents of this? Before anyone ask me, I'm trying to get the text that was used in the Communicator window.

Below is the code I found on the Internet. The code is not mine.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace EventFun
{
class EventHookUp
{
    CommunicatorAPI.Messenger mCommunicator = null;

    static void Main(string[] args)
    {
       开发者_如何转开发 EventHookUp hu = new EventHookUp();
        hu.InitializeEventHocks();
        Console.ReadKey();
    }

    public void InitializeEventHocks()
    {
        mCommunicator = new CommunicatorAPI.Messenger();
        mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
        mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);
    }

    void mCommunicator_OnIMWindowCreated(object pIMWindow)
    {
        CommunicatorAPI.IMessengerConversationWndAdvanced stpIMWindow = pIMWindow as CommunicatorAPI.IMessengerConversationWndAdvanced;
        //stpIMWindow.History;
        long Hwnd = (long)stpIMWindow.HWND;
        Console.WriteLine("New IM Window Created : {0}", Hwnd);

        CommunicatorAPI.IMessengerContacts contactList = (CommunicatorAPI.IMessengerContacts)stpIMWindow.Contacts;
        StringBuilder sb = new StringBuilder();
        foreach (CommunicatorAPI.IMessengerContact imc in contactList)
        {
            sb.Append(imc.FriendlyName);
            sb.Append(Environment.NewLine);
        }
        Console.WriteLine(sb.ToString());
    }

    void mCommunicator_OnIMWindowDestroyed(object pIMWindow)
    {
        Console.WriteLine("IM Window Destroyed.");
    }
}
}


It sounds like you are trying to get the conversation text history from the conversation window? If so, George Durzi has an excellent blog post on this.


As this blog post is not available, I used below method to retrieve the conversation history:

object obj = msgrAdv.StartConversation(
    CONVERSATION_TYPE.CONVERSATION_TYPE_IM, // Type of conversation
    sipUris, // object array of signin names for having multiple conversations or just a string
    null,
    "Test",
    "1",
    null);

 imWindowHandle = long.Parse(obj.ToString());

 if (imWindow == null) //If there is already an open window...
 {
     imWindow = (IMessengerConversationWndAdvanced)msgrAdv.InstantMessage(sipUris);
 }
 //else there was no open window, we have opened the window using "msgrAdv.StartConversation" so there is a imWindow associated which is implemented in communicator_OnIMWindowCreated.
 //and then...
string history = imWindow.History;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜