简体   繁体   English

反向点击表单?

[英]Reverse Form Click-Through?

So you can make a form Click-Through-Able... 因此,您可以创建一个表格,点击即可

Imports: 进口:

[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);

Code: 码:

int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);

Now how would I go about reversing the effect after running the code once? 现在,一旦运行代码,我将如何恢复效果?

I tried this: 我尝试了这个:

int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x10000 | 0x10);

But that did not work. 但这没有用。

Thanks in advance! 提前致谢!

As another option, you can remove those styles this way: 作为另一种选择,您可以通过以下方式删除这些样式:

var style = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, style & ~(0x80000 | 0x20));

Note 注意

The code would be more understandable using these constants: 使用以下常量将更易于理解代码:

const int GWL_EXSTYLE = -20;
const int WS_EX_LAYERED = 0x80000;
const int WS_EX_TRANSPARENT = 0x20;

In order to restore the style back to its initial state, you need to set the style to the value of initialStyle from the first snippet. 为了将样式恢复到其初始状态,您需要从第一个代码段中将样式设置为initialStyle的值。

You can't just simply keep appending more flags onto the style and expecting it to return to normal. 您不能只是简单地继续在样式上添加更多标志,并期望它恢复正常。


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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM