1

我正在尝试开发一个有按钮的winform应用程序。单击按钮时,当我们将鼠标悬停在系统任务栏中的 lync 图标上时,应显示 lync 窗口列表,如下所示。

涂黑的部分包含聊天参与者的姓名

如何在我的 winform 上单击按钮获得相同的功能。

我正在使用 Lync SDK 2013,但也可以使用 2010。

因此,总而言之,当我们将鼠标悬停在表单上按钮的任务栏中的 lync 图标上时,我想模拟该功能。单击该按钮时,将显示对话列表,其中突出显示活动/最近的一个,单击该按钮将进入该特定对话窗口。 有任何想法吗?

谢谢

4

2 回答 2

2

If you're looking for all Lync conversations, use the ConversationManager.Conversations property in the SDK. There are also ConversationAdded and ConversationRemoved events on the ConversationManger, so you can keep your list updated in real-time.

于 2014-06-03T09:56:39.823 回答
1

这有点难看,但是当我尝试检测对话窗口时,我别无选择,只能使用 Windows API 函数枚举所有窗口EnumWindows,然后检查窗口类"LyncConversationWindowClass"。但这是一年多前使用 Lync 2010 - 不知道它是否适用于 Lync 2013,或者是否有更好的解决方案。

至少,此代码不需要 Lync SDK。;-)

这是我的代码片段,希望对您有所帮助:

void Test()
{
    int conversationWindowCount = WindowDetector.Count("LyncConversationWindowClass");
}

static class WindowDetector
{
    private delegate bool CallBackPtr(int hwnd, int lParam);

    [DllImport("user32.dll")]
    private static extern int EnumWindows(CallBackPtr callPtr, int lPar);

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

    private static readonly object Lock = new object();

    private static int _count;
    private static string _className;

    private static bool EnumWindowsCallback(int hwnd, int lparam)
    {
        var sb = new StringBuilder(255);
        GetClassName(new IntPtr(hwnd), sb, sb.Capacity);
        string className = sb.ToString();

        if (className == _className)
        {
            _count++;
        }

        // return true to continue enumerating or false to stop
        return true;
    }

    /// <summary>
    ///     Returns the count of windows which have the specified class name.
    /// </summary>
    /// <param name="className">The window class name to look for (case-sensitive).</param>
    public static int Count(string className)
    {
        lock (Lock)
        {
            _count = 0;
            _className = className;

            EnumWindows(EnumWindowsCallback, 0);

            return _count;
        }
    }
}
于 2014-06-03T07:16:59.083 回答