// 使用C#代码实现Windows 10全屏:using System;
// 使用C#代码实现Windows 10全屏:
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace WindowsFormsApp1
{
public class FullScreen
{
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
public static void GoFullscreen(IntPtr WindowHandle)
{
// Store the current window style
var windowStyle = GetWindowLong(WindowHandle, GWL_STYLE);
// Remove the window style from the window
SetWindowLong(WindowHandle, GWL_STYLE, windowStyle & ~WS_BORDER & ~WS_THICKFRAME);
// Store the current window position
Rectangle windowRect;
GetWindowRect(WindowHandle, out windowRect);
// Set the window to fullscreen
SetWindowPos(WindowHandle, HWND_TOPMOST, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, TOPMOST_FLAGS);
}
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
private static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
private const int GWL_STYLE = -16;
private const int WS_BORDER = 0x00800000;
private const int WS_THICKFRAME = 0x00040000;
}
}
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(40条)