Esempio n. 1
0
        /// <summary>
        /// 将窗口置顶
        /// </summary>
        /// <param name="hWnd">窗口句柄</param>
        public static void SetWindowTopMost(IntPtr hWnd)
        {
            //SWP_NOSIZE:维持当前尺寸(忽略cx和cy参数)
            //SWP_NOMOVE:维持当前位置(忽略X和Y参数)
            const uint flags = Win32Consts.SWP_NOSIZE | Win32Consts.SWP_NOMOVE;

            Win32Funcs.SetWindowPosWrapper(hWnd, Win32Consts.HWND_TOPMOST_PTR, 0, 0, 0, 0, flags);
            Win32Funcs.SendMessageWrapper(hWnd, Win32Consts.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);

            Win32Funcs.SetForegroundWindowWrapper(hWnd);
        }