开发者

Show a taskbar item with a NativeWindow

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 task开发者_Go百科bar 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);
    }
}


The trick was to set the window's style to WS_POPUP.

const int WS_POPUP = unchecked((int)0x80000000);
const int SW_SHOWNOACTIVATE = 4;

CreateHandle(new CreateParams() {
    Style = WS_POPUP
});

ShowWindow(Handle, SW_SHOWNOACTIVATE);

I also disabled Aero Peek for the window, since it's just for background work.

const int DWMNCRP_ENABLED = 2;
const int DWMWA_DISALLOW_PEEK = 11;

int policy = DWMNCRP_ENABLED;
DwmSetWindowAttribute(Handle, DWMWA_DISALLOW_PEEK, ref policy, sizeof(int));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜