[英]Reverse Form Click-Through?
因此,您可以创建一个表格,点击即可
进口:
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
码:
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
现在,一旦运行代码,我将如何恢复效果?
我尝试了这个:
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x10000 | 0x10);
但这没有用。
提前致谢!
作为另一种选择,您可以通过以下方式删除这些样式:
var style = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, style & ~(0x80000 | 0x20));
注意
使用以下常量将更易于理解代码:
const int GWL_EXSTYLE = -20;
const int WS_EX_LAYERED = 0x80000;
const int WS_EX_TRANSPARENT = 0x20;
为了将样式恢复到其初始状态,您需要从第一个代码段中将样式设置为initialStyle
的值。
您不能只是简单地继续在样式上添加更多标志,并期望它恢复正常。
public class Example
{
private int _initialStyle = 0;
public void ApplyStyle()
{
_initialStyle = GetWindowLong(...);
SetWindowLong(..., _initialStyle | /* styles */);
}
public void RestoreStyle()
{
SetWindowLong(..., _initialStyle);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.