任务栏窗口minimenu Win7

时间:2013-06-23 23:00:55

标签: c# windows-7 f#

Screenshot

我想在Win7中通过C#或F#使用此菜单。我甚至找不到怎么称呼它。

1 个答案:

答案 0 :(得分:2)

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

  

托管等效文件当前未出现在Windows API中   Code Pack,但计划在将来的版本中出现。在里面   同时,您可以使用Windows 7任务栏Interop示例库。它   包含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);