2010-09-21 50 views
2

了解窗口的hwnd,如何读取此内容?在任何人问我之前,我正在尝试获取Communicator窗口中使用的文本。如何从另一个应用程序读取屏幕的内容[Office 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."); 
    } 
} 
} 
+1

在谷歌第一击导致API文档:http://msdn.microsoft.com/en -us/library/bb758727(v = office.12).aspx通过查询API,您可能可以获得所需的信息,而不是尝试查找从其他窗口读取文本的一般方法。 – 2010-09-21 20:34:10

+0

@Albin Sunnanbo我可以再次搜索,但以前没有找到多少研究。没有首先寻求答案肯定不会发布问题。事实上,与这个问题类似,我继续研究。谢谢 – 2010-09-21 20:50:30

回答

3

这听起来像你试图从谈话窗口中获取对话文本历史?如果是这样,George Durzi对此有很好的blog post

+0

朋友,这正是我想要的,没有人回答我。不过,我会检查我是否有我的项目的来源,我会尝试实施该帖子中描述的代码。任何祝贺你的帮助。成功 – 2010-10-26 10:45:38

1

正如这篇博客是不可用的,我用下面的方法来检索对话历史记录:

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; 
相关问题