*UIForm:恢复了WindowState,增加了窗体可拉拽调整大小ShowDragStretch

This commit is contained in:
Sunny 2020-09-17 20:04:08 +08:00
parent 94d867317b
commit dd61dab0de
11 changed files with 301 additions and 136 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -37,7 +37,6 @@
this.uiLogo1 = new Sunny.UI.UILogo(); this.uiLogo1 = new Sunny.UI.UILogo();
this.uiAvatar = new Sunny.UI.UIAvatar(); this.uiAvatar = new Sunny.UI.UIAvatar();
this.StyleManager = new Sunny.UI.UIStyleManager(this.components); this.StyleManager = new Sunny.UI.UIStyleManager(this.components);
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.Header.SuspendLayout(); this.Header.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -46,17 +45,18 @@
this.Aside.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); this.Aside.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.Aside.ItemHeight = 36; this.Aside.ItemHeight = 36;
this.Aside.LineColor = System.Drawing.Color.Black; this.Aside.LineColor = System.Drawing.Color.Black;
this.Aside.Location = new System.Drawing.Point(2, 145);
this.Aside.MenuStyle = Sunny.UI.UIMenuStyle.Black; this.Aside.MenuStyle = Sunny.UI.UIMenuStyle.Black;
this.Aside.ShowOneNode = true; this.Aside.ShowOneNode = true;
this.Aside.ShowTips = true; this.Aside.ShowTips = true;
this.Aside.Size = new System.Drawing.Size(250, 575); this.Aside.Size = new System.Drawing.Size(250, 573);
this.Aside.Style = Sunny.UI.UIStyle.Custom; this.Aside.Style = Sunny.UI.UIStyle.Custom;
// //
// Header // Header
// //
this.Header.Controls.Add(this.uiAvatar); this.Header.Controls.Add(this.uiAvatar);
this.Header.Controls.Add(this.uiLogo1); this.Header.Controls.Add(this.uiLogo1);
this.Header.ImageList = this.imageList1; this.Header.Location = new System.Drawing.Point(2, 35);
treeNode1.ImageIndex = 1; treeNode1.ImageIndex = 1;
treeNode1.Name = "节点0"; treeNode1.Name = "节点0";
treeNode1.Text = "控件"; treeNode1.Text = "控件";
@ -72,7 +72,7 @@
treeNode3, treeNode3,
treeNode4}); treeNode4});
this.Header.SelectedIndex = 0; this.Header.SelectedIndex = 0;
this.Header.Size = new System.Drawing.Size(1024, 110); this.Header.Size = new System.Drawing.Size(1020, 110);
this.Header.Style = Sunny.UI.UIStyle.Custom; this.Header.Style = Sunny.UI.UIStyle.Custom;
this.Header.MenuItemClick += new Sunny.UI.UINavBar.OnMenuItemClick(this.Header_MenuItemClick); this.Header.MenuItemClick += new Sunny.UI.UINavBar.OnMenuItemClick(this.Header_MenuItemClick);
// //
@ -92,19 +92,12 @@
// //
this.uiAvatar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.uiAvatar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.uiAvatar.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiAvatar.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiAvatar.Location = new System.Drawing.Point(943, 25); this.uiAvatar.Location = new System.Drawing.Point(939, 25);
this.uiAvatar.Name = "uiAvatar"; this.uiAvatar.Name = "uiAvatar";
this.uiAvatar.Size = new System.Drawing.Size(66, 70); this.uiAvatar.Size = new System.Drawing.Size(66, 70);
this.uiAvatar.TabIndex = 4; this.uiAvatar.TabIndex = 4;
this.uiAvatar.Text = "uiAvatar1"; this.uiAvatar.Text = "uiAvatar1";
// //
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "002.png");
this.imageList1.Images.SetKeyName(1, "025.png");
//
// FMain // FMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
@ -112,8 +105,10 @@
this.ClientSize = new System.Drawing.Size(1024, 720); this.ClientSize = new System.Drawing.Size(1024, 720);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FMain"; this.Name = "FMain";
this.Padding = new System.Windows.Forms.Padding(2, 35, 2, 2);
this.ShowDragStretch = true;
this.ShowRadius = false;
this.Text = "SunnyUI.Net"; this.Text = "SunnyUI.Net";
this.WindowStateChange += new Sunny.UI.UIForm.OnWindowStateChange(this.FMain_WindowStateChange);
this.Header.ResumeLayout(false); this.Header.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
@ -124,6 +119,5 @@
private UILogo uiLogo1; private UILogo uiLogo1;
private UIAvatar uiAvatar; private UIAvatar uiAvatar;
private UIStyleManager StyleManager; private UIStyleManager StyleManager;
private System.Windows.Forms.ImageList imageList1;
} }
} }

View File

@ -117,56 +117,6 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>150, 17</value>
</metadata>
<data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU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AGAAQEGAAGAAQEGAAGAAQEGAAGAAQEGAAGAAQEGAAGAAQEGAAGA
AQEGAAGAAQEGAAGAAQEGAAGAAQEGAAGAAQEGAAGAAQEEAAL/AeMBxwQAAv8B4wHHBAAL
</value>
</data>
<metadata name="StyleManager.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="StyleManager.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>

View File

@ -40,7 +40,12 @@ namespace Sunny.UI
public UINavMenu() public UINavMenu()
{ {
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
base.UpdateStyles();
BorderStyle = BorderStyle.None; BorderStyle = BorderStyle.None;
//HideSelection = false; //HideSelection = false;
DrawMode = TreeViewDrawMode.OwnerDrawAll; DrawMode = TreeViewDrawMode.OwnerDrawAll;

View File

@ -19,7 +19,8 @@
* 2020-01-01: V2.2.0 * 2020-01-01: V2.2.0
* 2020-05-30: V2.2.5 / * 2020-05-30: V2.2.5 /
* 2020-07-01: V2.2.6 仿QQ * 2020-07-01: V2.2.6 仿QQ
* 2020-07-05: V2.2.6 UIForm * 2020-07-05: V2.2.6
* 2020-09-17: V2.2.7 WindowState相关代码
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -39,10 +40,6 @@ namespace Sunny.UI
private UIStatusForm statusForm; private UIStatusForm statusForm;
public delegate void OnWindowStateChange(object sender, FormWindowState state);
public event OnWindowStateChange WindowStateChange;
public UIForm() public UIForm()
{ {
InitializeComponent(); InitializeComponent();
@ -52,11 +49,32 @@ namespace Sunny.UI
SetStyle(UIStyles.Style); SetStyle(UIStyles.Style);
} }
SetStyle(ControlStyles.UserPaint, true); base.SetStyle(
SetStyle(ControlStyles.AllPaintingInWmPaint, true); ControlStyles.UserPaint |
SetStyle(ControlStyles.DoubleBuffer, true); ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.SupportsTransparentBackColor, true);
UpdateStyles(); UpdateStyles();
Version = UIGlobal.Version; Version = UIGlobal.Version;
FormBorderStyle = FormBorderStyle.None;
base.MaximumSize = ShowFullScreen ? Screen.PrimaryScreen.Bounds.Size : Screen.PrimaryScreen.WorkingArea.Size;
}
//不显示FormBorderStyle属性
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new FormBorderStyle FormBorderStyle
{
get { return base.FormBorderStyle; }
set
{
base.FormBorderStyle = FormBorderStyle.None;
Console.WriteLine(value);
}
} }
public void Render() public void Render()
@ -357,8 +375,7 @@ namespace Sunny.UI
if (MinimizeBox) if (MinimizeBox)
{ {
MinimizeBoxRect = new Rectangle(MaximizeBox ? MaximizeBoxRect.Left - 28 - 2 : ControlBoxRect.Left - 28 - 2, MinimizeBoxRect = new Rectangle(MaximizeBox ? MaximizeBoxRect.Left - 28 - 2 : ControlBoxRect.Left - 28 - 2, ControlBoxRect.Top, 28, 28);
ControlBoxRect.Top, 28, 28);
ControlBoxLeft = MinimizeBoxRect.Left - 2; ControlBoxLeft = MinimizeBoxRect.Left - 2;
} }
else else
@ -458,21 +475,20 @@ namespace Sunny.UI
{ {
if (InControlBox) if (InControlBox)
{ {
Close();
InControlBox = false; InControlBox = false;
Close();
} }
if (InMinBox) if (InMinBox)
{ {
base.WindowState = FormWindowState.Minimized;
WindowStateChange?.Invoke(this, FormWindowState.Minimized);
InMinBox = false; InMinBox = false;
WindowState = FormWindowState.Minimized;
} }
if (InMaxBox) if (InMaxBox)
{ {
ShowMaximize();
InMaxBox = false; InMaxBox = false;
ShowMaximize();
} }
} }
} }
@ -490,7 +506,8 @@ namespace Sunny.UI
private void ShowMaximize(bool IsOnMoving = false) private void ShowMaximize(bool IsOnMoving = false)
{ {
Screen screen = Screen.FromPoint(MousePosition); Screen screen = Screen.FromPoint(MousePosition);
if (windowState == FormWindowState.Normal) base.MaximumSize = ShowFullScreen ? Screen.PrimaryScreen.Bounds.Size : Screen.PrimaryScreen.WorkingArea.Size;
if (WindowState == FormWindowState.Normal)
{ {
size = Size; size = Size;
// 若窗体从正常模式->最大化模式,该操作是由移动窗体至顶部触发的,记录的是移动前的窗体位置 // 若窗体从正常模式->最大化模式,该操作是由移动窗体至顶部触发的,记录的是移动前的窗体位置
@ -500,11 +517,9 @@ namespace Sunny.UI
Left = screen.Bounds.Left; Left = screen.Bounds.Left;
Top = screen.Bounds.Top; Top = screen.Bounds.Top;
SetFormRoundRectRegion(this, 0); SetFormRoundRectRegion(this, 0);
if (ShowFullScreen) base.WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
windowState = FormWindowState.Maximized;
WindowStateChange?.Invoke(this, FormWindowState.Maximized);
} }
else if (windowState == FormWindowState.Maximized) else if (WindowState == FormWindowState.Maximized)
{ {
if (size.Width == 0 || size.Height == 0) if (size.Width == 0 || size.Height == 0)
{ {
@ -516,11 +531,9 @@ namespace Sunny.UI
screen.Bounds.Top + screen.WorkingArea.Height / 2 - Size.Height / 2); screen.Bounds.Top + screen.WorkingArea.Height / 2 - Size.Height / 2);
if (location.X == 0 && location.Y == 0) location = center; if (location.X == 0 && location.Y == 0) location = center;
Location = StartPosition == FormStartPosition.CenterScreen ? center : location; Location = location;
SetFormRoundRectRegion(this, ShowRadius ? 5 : 0); SetFormRoundRectRegion(this, ShowRadius ? 5 : 0);
windowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
base.WindowState = FormWindowState.Normal;
WindowStateChange?.Invoke(this, FormWindowState.Normal);
} }
Invalidate(); Invalidate();
@ -625,7 +638,7 @@ namespace Sunny.UI
{ {
if (FormMoveMouseDown && !MousePosition.Equals(mouseOffset)) if (FormMoveMouseDown && !MousePosition.Equals(mouseOffset))
{ {
if (windowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
int MaximizedWidth = Width; int MaximizedWidth = Width;
int LocationX = Left; int LocationX = Left;
@ -695,6 +708,8 @@ namespace Sunny.UI
InControlBox = InMaxBox = InMinBox = false; InControlBox = InMaxBox = InMinBox = false;
} }
} }
base.OnMouseMove(e);
} }
protected override void OnMouseLeave(EventArgs e) protected override void OnMouseLeave(EventArgs e)
@ -754,7 +769,7 @@ namespace Sunny.UI
if (ShowRect) if (ShowRect)
{ {
Point[] points; Point[] points;
bool unShowRadius = !ShowRadius || windowState == FormWindowState.Maximized || bool unShowRadius = !ShowRadius || WindowState == FormWindowState.Maximized ||
(Width == Screen.PrimaryScreen.WorkingArea.Width && (Width == Screen.PrimaryScreen.WorkingArea.Width &&
Height == Screen.PrimaryScreen.WorkingArea.Height); Height == Screen.PrimaryScreen.WorkingArea.Height);
if (unShowRadius) if (unShowRadius)
@ -840,7 +855,7 @@ namespace Sunny.UI
// ? FontAwesomeIcons.fa_window_restore // ? FontAwesomeIcons.fa_window_restore
// : FontAwesomeIcons.fa_window_maximize, 24, Color.White, MaximizeBoxRect, 1); // : FontAwesomeIcons.fa_window_maximize, 24, Color.White, MaximizeBoxRect, 1);
if (windowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
e.Graphics.DrawRectangle(Color.White, e.Graphics.DrawRectangle(Color.White,
MaximizeBoxRect.Left + MaximizeBoxRect.Width / 2 - 5, MaximizeBoxRect.Left + MaximizeBoxRect.Width / 2 - 5,
@ -872,7 +887,7 @@ namespace Sunny.UI
MaximizeBoxRect.Top + MaximizeBoxRect.Height / 2 + 3); MaximizeBoxRect.Top + MaximizeBoxRect.Height / 2 + 3);
} }
if (windowState == FormWindowState.Normal) if (WindowState == FormWindowState.Normal)
{ {
e.Graphics.DrawRectangle(Color.White, e.Graphics.DrawRectangle(Color.White,
MaximizeBoxRect.Left + MaximizeBoxRect.Width / 2 - 5, MaximizeBoxRect.Left + MaximizeBoxRect.Width / 2 - 5,
@ -1137,7 +1152,7 @@ namespace Sunny.UI
/// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param> /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
private void CtrlMouseDown(object sender, MouseEventArgs e) private void CtrlMouseDown(object sender, MouseEventArgs e)
{ {
if (windowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
return; return;
} }
@ -1162,7 +1177,7 @@ namespace Sunny.UI
return; return;
} }
if (windowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
SetFormRoundRectRegion(this, 0); SetFormRoundRectRegion(this, 0);
} }
@ -1200,35 +1215,15 @@ namespace Sunny.UI
public string CloseAskString { get; set; } public string CloseAskString { get; set; }
private FormWindowState windowState = FormWindowState.Normal;
public new FormWindowState WindowState
{
get => windowState;
set
{
if (value == FormWindowState.Minimized)
{
base.WindowState = FormWindowState.Minimized;
return;
}
ShowMaximize();
windowState = value;
}
}
protected override CreateParams CreateParams protected override CreateParams CreateParams
{ {
get get
{ {
if (this.FormBorderStyle == FormBorderStyle.None) if (base.FormBorderStyle == FormBorderStyle.None)
{ {
// 当边框样式为FormBorderStyle.None时
// 点击窗体任务栏图标,可以进行最小化 // 点击窗体任务栏图标,可以进行最小化
const int WS_MINIMIZEBOX = 0x00020000;
CreateParams cp = base.CreateParams; CreateParams cp = base.CreateParams;
cp.Style = cp.Style | WS_MINIMIZEBOX; cp.Style |= 0x00020000;
return cp; return cp;
} }
else else
@ -1238,27 +1233,67 @@ namespace Sunny.UI
} }
} }
public void Show(FormWindowState state) private bool showDragStretch;
[Description("显示边框可拖拽调整窗体大小"), Category("SunnyUI"), DefaultValue(false)]
public bool ShowDragStretch
{ {
ShowFullScreen = false; get => showDragStretch;
set
switch (state)
{ {
case FormWindowState.Minimized: showDragStretch = value;
WindowState = FormWindowState.Minimized; if (value)
base.WindowState = FormWindowState.Minimized; {
break; ShowRect = true;
case FormWindowState.Maximized: ShowRadius = false;
base.WindowState = FormWindowState.Normal; Padding = new Padding(2, showTitle ? TitleHeight : 2, 2, 2);
WindowState = FormWindowState.Normal; }
ShowMaximize();
break;
case FormWindowState.Normal:
base.WindowState = FormWindowState.Normal;
WindowState = FormWindowState.Maximized;
ShowMaximize();
break;
} }
} }
#region
const int WM_LEFT = 10;
const int WM_RIGHT = 11;
const int WM_TOP = 12;
const int WM_TOPLEFT = 13;
const int WM_TOPRIGHT = 14;
const int WM_BOTTOM = 15;
const int WM_BOTTOMLEFT = 0x10;
const int WM_BOTTOMRIGHT = 17;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (ShowDragStretch && WindowState == FormWindowState.Normal && m.Msg == 0x0084)
{
Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
int dragSize = 5;
if (vPoint.X <= dragSize)
{
if (vPoint.Y <= dragSize)
m.Result = (IntPtr)WM_TOPLEFT;
else if (vPoint.Y >= ClientSize.Height - dragSize)
m.Result = (IntPtr)WM_BOTTOMLEFT;
else m.Result = (IntPtr)WM_LEFT;
}
else if (vPoint.X >= ClientSize.Width - dragSize)
{
if (vPoint.Y <= dragSize)
m.Result = (IntPtr)WM_TOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - dragSize)
m.Result = (IntPtr)WM_BOTTOMRIGHT;
else m.Result = (IntPtr)WM_RIGHT;
}
else if (vPoint.Y <= dragSize)
{
m.Result = (IntPtr)WM_TOP;
}
else if (vPoint.Y >= ClientSize.Height - dragSize)
{
m.Result = (IntPtr)WM_BOTTOM;
}
}
}
#endregion
} }
} }

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.7.0")] [assembly: AssemblyVersion("2.2.8.0")]
[assembly: AssemblyFileVersion("2.2.7.0")] [assembly: AssemblyFileVersion("2.2.8.0")]

View File

@ -411,6 +411,7 @@
<Compile Include="Units\UConcurrentDoubleKeyDictionary.cs" /> <Compile Include="Units\UConcurrentDoubleKeyDictionary.cs" />
<Compile Include="Units\UConcurrentGroupDictionary.cs" /> <Compile Include="Units\UConcurrentGroupDictionary.cs" />
<Compile Include="Units\USnowflakeID.cs" /> <Compile Include="Units\USnowflakeID.cs" />
<Compile Include="Units\USuspendCtrlAltDel.cs" />
<Compile Include="Units\UThunder.cs" /> <Compile Include="Units\UThunder.cs" />
<Compile Include="Controls\UILine.cs"> <Compile Include="Controls\UILine.cs">
<SubType>Component</SubType> <SubType>Component</SubType>

View File

@ -0,0 +1,180 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@qq.com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : USuspendCtrlAltDel.cs
* : winlogon线程来屏蔽Ctrl+Alt+Delete
* : V2.2
* : 2020-01-01
*
* 2020-09-17: V2.2.7
******************************************************************************/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Sunny.UI
{
/// <summary>
/// 通过挂起winlogon.exe线程来屏蔽Ctrl+Alt+Delete
/// 程序需要管理员权限
/// 需要提升进程权限为SE_PRIVILEGE_ENABLED权限
/// winlogon管理着开关机登录界面等功能
/// 调用Suspend挂起winlogon.exe用完后需要Resume否则无法调用关机界面
/// </summary>
public static class SuspendCtrlAltDelete
{
public static void GetSeDebugPrivilege()
{
IntPtr hToken;
LUID luidSEDebugNameValue = new LUID();
if (!OpenProcessToken(Process.GetCurrentProcess().Handle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out hToken))
{
Console.WriteLine("OpenProcessToken() failed, error = {0} . SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
return;
}
else
{
Console.WriteLine("OpenProcessToken() successfully");
}
if (!LookupPrivilegeValue(null, SE_DEBUG_NAME, ref luidSEDebugNameValue))
{
Console.WriteLine("LookupPrivilegeValue() failed, error = {0} .SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
CloseHandle(hToken);
return;
}
else
{
Console.WriteLine("LookupPrivilegeValue() successfully");
}
TOKEN_PRIVILEGES tkpPrivileges = new TOKEN_PRIVILEGES();
tkpPrivileges.PrivilegeCount = 1;
tkpPrivileges.Privilege.Luid = luidSEDebugNameValue;
tkpPrivileges.Privilege.Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, false, ref tkpPrivileges, 0, IntPtr.Zero, 0))
{
Console.WriteLine("LookupPrivilegeValue() failed, error = {0} .SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
}
else
{
Console.WriteLine("SeDebugPrivilege is now available");
}
CloseHandle(hToken);
Console.ReadLine();
}
public static void Suspend()
{
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
if (process.ProcessName == "winlogon")
{
IntPtr p = OpenThread(PROCESS_ALL_ACCESS, false, (IntPtr)process.Threads[0].Id);
SuspendThread(p);
CloseHandle(p);
}
}
}
public static void Resume()
{
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
if (process.ProcessName == "winlogon")
{
IntPtr p = OpenThread(PROCESS_ALL_ACCESS, false, (IntPtr)process.Threads[0].Id);
ResumeThread(p);
CloseHandle(p);
}
}
}
const int PROCESS_ALL_ACCESS = 0x001F03FF;
const string SE_DEBUG_NAME = "SeDebugPrivilege";
const uint SE_PRIVILEGE_ENABLED = 0x00000002;
const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
const uint STANDARD_RIGHTS_READ = 0x00020000;
const uint TOKEN_ASSIGN_PRIMARY = 0x0001;
const uint TOKEN_DUPLICATE = 0x0002;
const uint TOKEN_IMPERSONATE = 0x0004;
const uint TOKEN_QUERY = 0x0008;
const uint TOKEN_QUERY_SOURCE = 0x0010;
const uint TOKEN_ADJUST_PRIVILEGES = 0x0020;
const uint TOKEN_ADJUST_GROUPS = 0x0040;
const uint TOKEN_ADJUST_DEFAULT = 0x0080;
const uint TOKEN_ADJUST_SESSIONID = 0x0100;
const uint TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY;
const uint TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY |
TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE |
TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT |
TOKEN_ADJUST_SESSIONID);
[DllImport("kernel32.dll")]
private static extern IntPtr OpenThread(int dwDesiredAccess, bool bInheritHandle, IntPtr dwThreadId);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32")]
private static extern int SuspendThread(IntPtr hThread);
[DllImport("kernel32")]
private static extern int ResumeThread(IntPtr hThread);
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool LookupPrivilegeValue(string lpSystemName, string lpName,
[MarshalAs(UnmanagedType.Struct)] ref LUID lpLuid);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AdjustTokenPrivileges(IntPtr TokenHandle,
[MarshalAs(UnmanagedType.Bool)] bool DisableAllPrivileges,
[MarshalAs(UnmanagedType.Struct)] ref TOKEN_PRIVILEGES NewState,
uint BufferLength, IntPtr PreviousState, uint ReturnLength);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct LUID
{
internal int LowPart;
internal uint HighPart;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct TOKEN_PRIVILEGES
{
internal int PrivilegeCount;
internal LUID_AND_ATTRIBUTES Privilege;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct LUID_AND_ATTRIBUTES
{
internal LUID Luid;
internal uint Attributes;
}
}
}