GetWindowLong / SetWindowLong函数VS覆盖的CreateParams? [英] GetWindowLong / SetWindowLong vs overriding CreateParams?

查看:99
本文介绍了GetWindowLong / SetWindowLong函数VS覆盖的CreateParams?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,当我想创造点进的形式,我诱惑使用平台调用设置扩展窗口样式 GetWindowLong / SetWindowLong函数 user32.dll中)。



刚才我想让它无形的Alt + Tab键窗口列表,我发现<一个HREF =htt​​p://www.csharp411.com/hide-form-from-alttab/相对=nofollow>为例的覆盖的CreateParams 来设置扩展的窗口风格,而不是使用 GetWindowLong / SetWindowong



现在我有这样的:

 保护覆盖的CreateParams的CreateParams 
{
的get
{
的CreateParams CP = base.CreateParams;
cp.ExStyle | = 0x80000 / * * WS_EX_LAYERED / |为0x20 / * * WS_EX_TRANSPARENT / | 0x80的/ * * WS_EX_TOOLWINDOW /;
返回CP;
}
}

现在的明显变化是不需要任何平台调用。



所以,我的几个问题:




  1. 威尔有是在Windows上的任​​何功能上的区别? (只是说我甚至没有XP的机器现在尝试。)

  2. 现在,我没有平台调用,可以在Linux / Mac上我的单程序运行? (如果我现在可以试试我就不会在这里问你。)

  3. Control.CreateParams 出现在MSDN上并有操纵窗口风格的一个例子。那么,为什么在计算器上一些在线示例和答案告诉人们使用 GetWindowLong / SetWindowLong函数


解决方案

会不会出现在Windows?

$ b任何功能上的差异$ b

是的,很喜欢这样。重写的CreateParams确保当与是CreateWindowEx()调用创建窗口的风格标志已所需的值。 Pinvoking SetWindowLong函数()做它晚了,它需要因为你需要Handle属性首先被创建的窗口。与GWL_STYLE和GWL_EXSTYLE使用它是有风险的,较早的Windows版本是胡思乱想了一番。正因如此,的WinForms没有做到这一点,它实际上再现的窗口,因此它可以通过新的样式来函数CreateWindowEx()。注意RecreateHandle()方法,它是用来当一个属性被更改是引擎盖下的风格标志。的WinForms确实有负担,还必须支持Windows 98。




可以在Linux / Mac上我的单程序运行?




不知道,你其实也来试试。但显然你有一个很好的可能,你有胜算为零,当你依靠的PInvoke。




在计算器上告诉人们使用GetWindowLong / SetWindowLong函数?




惯性,我想。 。SetWindowsLong()已经有超过25年,为的CreateParams 10岁,仍然是相当模糊的。



预先制止下一个问题:没有,我从来没有看到什么样的风格标志可以安全地改变一个全面的列表,这些预定义的窗口类在每个Windows版本在窗口的生命周期是什么确切时间。相当确信这样的列表不存在,或者可以被信任,试验和错误是必需的。请注意,可能需要与SWP_FRAMECHANGED到SetWindowsPos()的调用,使样式更改生效。


Previously when I wanted to create a click-through form, I was tempted to use platform invokes to set the extended window styles (GetWindowLong / SetWindowLong in user32.dll).

Just now I wanted to make it invisible to Alt+Tab window list, and I've found an example overriding CreateParams to set the extended window style instead of using GetWindowLong / SetWindowong.

Now I have this:

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x80000 /* WS_EX_LAYERED */ | 0x20 /* WS_EX_TRANSPARENT */ | 0x80/* WS_EX_TOOLWINDOW */;
        return cp;
    }
}

Now the apparent changes is not needing any platform invoke.

So my few questions:

  1. Will there be any functional differences on Windows? (Just to say I don't even have an XP machine to try now.)
  2. Now I don't have the platform invoke, will my program run on Mono on Linux/Mac? (If I could try now I wouldn't be asking you here.)
  3. Control.CreateParams appears on msdn and has an example of manipulating window styles. Then why some online "examples" and answers on StackOverflow tell people to use GetWindowLong / SetWindowLong?

解决方案

Will there be any functional differences on Windows?

Yes, very much so. Overriding CreateParams ensures that the style flags have the desired value when the window is created with the CreateWindowEx() call. Pinvoking SetWindowLong() does it late, it requires the window to be created first since you need the Handle property. Using it with GWL_STYLE and GWL_EXSTYLE is risky, older Windows versions were cranky about that. So much so that Winforms does not do this, it actually recreates the window so it can pass new style flags to CreateWindowEx(). Note the RecreateHandle() method, it is used when a property is changed that is a style flag under the hood. Winforms did have the burden to also have to support Windows 98.

will my program run on Mono on Linux/Mac?

Not sure, you actually do have to try. But clearly you have a good "maybe", you have zero odds when you'd rely on pinvoke.

on StackOverflow tell people to use GetWindowLong / SetWindowLong?

Inertia, I think. SetWindowsLong() has been around for over 25 years, CreateParams is 10 years old and still is pretty obscure.

Pre-empting the next question: no, I've never seen a comprehensive list of what style flags can be change safely for which predefined window class at what exact time in the window life cycle by each Windows version. Pretty sure such a list doesn't exist, or could be trusted, trial and error is required. Do note that a call to SetWindowsPos() with SWP_FRAMECHANGED may be required to make the style changes effective.

这篇关于GetWindowLong / SetWindowLong函数VS覆盖的CreateParams?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆