2013-06-23 45 views

回答

2

在MSDN雜誌上的Introducing The Taskbar APIs中,它介紹瞭如何使用縮略圖工具欄。

受管理的等效代碼當前未出現在Windows API 代碼包中,但計劃在未來版本中出現。同時在 中,您可以使用Windows 7任務欄Interop Sample Library。它 包含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);