Keeping window visible through “Show Desktop”/Win+D

后端 未结 1 476
暗喜
暗喜 2020-12-06 19:37

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

1条回答
  •  粉色の甜心
    2020-12-06 20:25

    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.

    0 讨论(0)
提交回复
热议问题