fjfjfjfjfjfj

【.Net】把窗体“钉”到桌面上

#region "WinAPI"

        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", EntryPoint = "GetWindow")]
        public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd);

#endregion


                //put the form onto DeskTop
                const int GW_CHILD = 5;                     //desktop
                hDeskTop = FindWindow("Progman", null);     //get system handle
                hDeskTop = GetWindow(hDeskTop, GW_CHILD);   //get desktop handle
                SetParent(this.Handle, hDeskTop);           //set this form's parent as desktop

 把窗体放在桌面上显示,也就是先找到 desktop窗口,设置其为程序的父窗口。

posted on 2013-09-19 12:37  撬棍  阅读(444)  评论(0编辑  收藏  举报

导航