【问题标题】:Taskbar window minimenu Win7任务栏窗口小菜单 Win7
【发布时间】:2013-06-23 23:00:55
【问题描述】:

我想在 Win7 中通过 C# 或 F# 使用这个菜单。我什至找不到如何调用它。

【问题讨论】:

    标签: c# windows-7 f#


    【解决方案1】:

    在 MSDN 杂志的Introducing The Taskbar APIs 中,它描述了如何使用缩略图工具栏。

    托管等效项当前未出现在 Windows API 中 Code Pack,但计划在未来的版本中出现。在里面 同时,您可以使用 Windows 7 任务栏互操作示例库。它 包含带有相应的 ThumbButtonManager 类 CreateThumbButton 和 AddThumbButtons 方法用于控制 缩略图工具栏,以及用于修改的 ThumbButton 类 运行时的缩略图按钮状态。要接收通知,您 注册 ThumbButton.Clicked 事件并覆盖您的窗口 将消息发送到 ThumbButtonManager 类的过程, 它为你做了调度魔法。 (有关详细信息,请参阅 博客文章Windows 7 Taskbar: Thumbnail Toolbars.)

    ITaskbarList3* ptl;//Created earlier //In your window procedure:
    switch (msg) { 
        case g_wmTBC://TaskbarButtonCreated
        THUMBBUTTON buttons[2]; buttons[0].dwMask = THB_ICON|THB_TOOLTIP|THB_FLAGS; buttons[0].iId = 0;
        buttons[0].hIcon = GetIconForButton(0); wcscpy(buttons[0].szTip, L"Tooltip 1"); buttons[0].dwFlags = THBF_ENABLED;
        buttons[1].dwMask = THB_ICON|THB_TOOLTIP|THB_FLAGS;
        buttons[1].iId = 1; buttons[1].hIcon = GetIconForButton(1);
        wcscpy(buttons[0].szTip, L"Tooltip 2"); buttons[1].dwFlags = THBF_ENABLED; VERIFY(ptl->ThumbBarAddButtons(hWnd, 2,buttons)); 
        break; 
        case WM_COMMAND: 
            if (HIWORD(wParam) == THBN_CLICKED) { 
                if (LOWORD(wParam) == 0)
                    MessageBox(L"Button 0 clicked", ...); 
                    if (LOWORD(wParam) == 1) MessageBox(L"Button 1 clicked", ...); 
            } 
        break;
        .
        .
    

    在第二个链接中,它显示了一个使用包装库的 C# 示例:

    与往常一样,托管包装器会提供帮助。这 ThumbButtonManager 类(在 Windows7.DesktopIntegration 项目中)

    _thumbButtonManager = this.CreateThumbButtonManager();
    ThumbButton button2 = _thumbButtonManager.CreateThumbButton(102, SystemIcons.Exclamation, "Beware of me!");
    button2.Clicked += delegate
    {
        statusLabel.Text = "Second button clicked";
        button2.Enabled = false;
    };
    ThumbButton button = _thumbButtonManager.CreateThumbButton(101, SystemIcons.Information, "Click me");
    button.Clicked += delegate
    {
        statusLabel.Text = "First button clicked";
        button2.Enabled = true;
    };
    _thumbButtonManager.AddThumbButtons(button, button2);
    Note that you have tooltips and icons at your disposal to personalize the thumbnail toolbar to your application’s needs.  All you need to do now is override your windows’ window procedure and call the DispatchMessage method of the ThumbButtonManager, so that it can correctly route the event to your registered event handlers (and of course, don’t forget to call the default window procedure when you’re done!):
    
    if (_thumbButtonManager != null)
        _thumbButtonManager.DispatchMessage(ref m);
    
    base.WndProc(ref m);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      相关资源
      最近更新 更多