电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

WinForm特效:桌面上的遮罩层


发布日期:2021/1/30
 

一个窗体特效帮你了解几个windows api函数效果windows桌面上增加一个简单的遮罩层其中WS_EX_TRANSPARENT 比较重要它实现了鼠标穿透的功能

using System;

using SystemDrawing;

using SystemWindowsForms;

using SystemRuntimeInteropServices;

namespace WindowsApplication

{

public partial class Form : Form

{

public Form()

{

InitializeComponent();

}

[DllImport(userdll EntryPoint = GetWindowLong)]

public static extern long GetWindowLong(IntPtr hwnd int nIndex);

[DllImport(userdll EntryPoint = SetWindowLong)]

public static extern long SetWindowLong(IntPtr hwnd int nIndex long dwNewLong);

[DllImport(user EntryPoint = SetLayeredWindowAttributes)]

private static extern int SetLayeredWindowAttributes(IntPtr Handle int crKey byte bAlpha int dwFlags);

const int GWL_EXSTYLE = ;

const int WS_EX_TRANSPARENT = x;

const int WS_EX_LAYERED = x;

const int LWA_ALPHA = ;

private void Form_Load(object sender EventArgs e)

{

thisBackColor = ColorSilver;

thisTopMost = true;

thisFormBorderStyle = FormBorderStyleNone;

thisWindowState = FormWindowStateMaximized;

SetWindowLong(Handle GWL_EXSTYLE GetWindowLong(Handle GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED);

SetLayeredWindowAttributes(Handle LWA_ALPHA );

}

}

}

上一篇:XAML入门之附加属性和绑定属性

下一篇:正则表达式学习:组的定义及引用方式