Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

c# - Keeping window visible through "Show Desktop"/Win+D

I'm creating a desktop gadget, and am running into problems. The window will be hidden by the "Show Desktop" command - STOP, I know what you're thinking and don't need "you shouldn't do this" comments - and I want to stop it. The whole point of a desktop gadget is, after all, that it sticks to the desktop.

Just to clarify - I don't want a TopMost window. I don't want to actually STOP the "Show Desktop" command, just ignore it. All I want is for my desktop gadget to stay visible on the desktop, disrupting as little normal functionality as usual.

Any ideas? My current method is a P/Invoke snippet I found on Google, setting the form's parent to Progman or something. Problem is that this seems to force the window showing in the taskbar, which I don't want.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe a bit late for an answer to your question, but nevertheless here the answer, which I seem to have found:

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hP, IntPtr hC, string sC, string sW);

    void MakeWin()
    {
        IntPtr nWinHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
        nWinHandle = FindWindowEx(nWinHandle, IntPtr.Zero, "SHELLDLL_DefView", null);
        SetParent(Handle, nWinHandle);
    }

"MakeWin" should be called in the Constructor of the Form, best before "InitializeComponent". Works good for me at least under Win7.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...