知道窗口的HWND,我如何阅读其中的内容?在任何人问我之前,我正在尝试获取在Communicator窗口中使用的文本。

以下是我在互联网上找到的代码。代码不是我的。

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.");
    }
}
}
有帮助吗?

解决方案

听起来您正在尝试从对话窗口中获取对话文本历史记录?如果是这样的话, 乔治·杜尔西 有一个很好的 博客文章 关于这个。

其他提示

由于此博客文章不可用,我使用以下方法检索对话历史:

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top