我想在 Win7 中通过 C# 或 F# 使用这个菜单。我什至找不到如何称呼它。
问问题
216 次
1 回答
2
在MSDN 杂志上的任务栏 API 简介中,它描述了如何使用缩略图工具栏。
托管等效项当前未出现在 Windows API 代码包中,但计划出现在未来版本中。同时,您可以使用 Windows 7 任务栏互操作示例库。它包含 ThumbButtonManager 类以及用于控制缩略图工具栏的相应 CreateThumbButton 和 AddThumbButtons 方法,以及用于在运行时修改缩略图按钮状态的 ThumbButton 类。要接收通知,您注册 ThumbButton.Clicked 事件并覆盖您的窗口过程以将消息分派到 ThumbButtonManager 类,该类为您执行分派魔法。(有关详细信息,请参阅博客文章Windows 7 任务栏:缩略图工具栏。)
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);
于 2013-06-23T23:10:19.997 回答