使用 NativeWindow 显示任务栏项目
我的应用程序旨在几乎完全通过使用缩略图和跳转列表的 Windows 7 任务栏项目来工作。我知道我可以轻松创建一个 Form
并简单地隐藏它,但这似乎有点矫枉过正。另外,我想尽可能多地使用 NativeWindow
,因为我以前从未使用过它。
本质上,我有一个名为 RootWindow
的类,它派生自 NativeWindow
,它将处理热键以及其他所有内容。我根本不需要可见的窗口,而只是需要处理窗口消息并提供一个可以附加缩略图和跳转列表的任务栏项目。
是否需要将某种特殊的 CreateParams 选项传递给 CreateHandle ?还是我运气不好?
编辑:嗯,这比我想象的要容易,尽管这并不完全是我想要的。当我将 NativeWindow
的句柄传递给 ShowWindow
API 后,任务栏项就会出现。但是,它还在屏幕的左上角显示一个窗口。有什么方法可以在仍然显示任务栏项目的同时摆脱该窗口吗?
public class RootWindow : NativeWindow {
public const int SW_SHOWNOACTIVATE = 4;
[DllImport("User32.dll")]
private static extern int ShowWindow(IntPtr hWnd, short cmdShow);
public RootWindow() {
CreateHandle(new CreateParams());
ShowWindow(this.Handle, SW_SHOWNOACTIVATE);
}
}
My application is intended to work almost entirely through a Windows 7 taskbar item with the use of thumbnails and jump lists. I know I can easily create a Form
and simply hide it, but this seems like overkill. Plus, I'd like to toy around with NativeWindow
as much as possible, because I've never used it before.
Essentially, I have a class called RootWindow
that derives from NativeWindow
that will handle hotkeys and hopefully everything else. I don't need a visible window at all, but simply something to process window messages and provide a taskbar item that I can attach thumbnails and jump lists to.
Is there some kind of special CreateParams
option I need to pass to CreateHandle
? Or am I out of luck?
EDIT: Well, it was easier than I thought it would be, although it's not exactly what I want. Once I passed the NativeWindow
's handle to the ShowWindow
API, the taskbar item appeared. However, it also shows a window in the upper left corner of the screen. Is there some way to get rid of that window while still showing the taskbar item?
public class RootWindow : NativeWindow {
public const int SW_SHOWNOACTIVATE = 4;
[DllImport("User32.dll")]
private static extern int ShowWindow(IntPtr hWnd, short cmdShow);
public RootWindow() {
CreateHandle(new CreateParams());
ShowWindow(this.Handle, SW_SHOWNOACTIVATE);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是将窗口的样式设置为 WS_POPUP。
我还禁用了窗口的 Aero Peek,因为它仅用于后台工作。
The trick was to set the window's style to WS_POPUP.
I also disabled Aero Peek for the window, since it's just for background work.