【问题标题】:Showing list of lync windows on click of a button单击按钮显示 lync 窗口列表
【发布时间】:2014-06-03 06:32:44
【问题描述】:

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

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

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

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

谢谢

【问题讨论】:

    标签: c# winforms visual-studio winapi lync-client-sdk


    【解决方案1】:

    如果您要查找所有 Lync 对话,请使用 SDK 中的 ConversationManager.Conversations 属性。 ConversationManger 上还有 ConversationAdded 和 ConversationRemoved 事件,因此您可以实时更新您的列表。

    【讨论】:

      【解决方案2】:

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

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

      这是我的代码sn-p,希望对你有帮助:

      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;
              }
          }
      }
      

      【讨论】:

      • 感谢您的回复...即使我担心我们将不得不使用 Win API。
      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 2021-12-18
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多