SetWindowLong/GetWindowLong 和 32 位/64 位 CPU
我正在使用以下代码:
const int GWL_STYLE = (-16);
const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;
[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
在某处...
SetWindowLong(this.Handle, GWL_STYLE,
((GetWindowLong(this.Handle, GWL_STYLE) & ~(WS_POPUP)) | WS_CHILD));
这可以在 32 位和 64 位计算机上正常运行吗?
如果不是,如果我将应用程序编译为 x86 进程运行,它在 64 位计算机上仍然可以正常工作吗?
那么如何重写下面的代码才能在32位和64位机器上都正常呢?
I'm using the following code:
const int GWL_STYLE = (-16);
const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;
[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
and somewhere...
SetWindowLong(this.Handle, GWL_STYLE,
((GetWindowLong(this.Handle, GWL_STYLE) & ~(WS_POPUP)) | WS_CHILD));
Will this run properly on both 32-bit and 64-bit machines?
If not, if I compile my application to be ran as a x86 process, will it still work fine on a 64-bit machine?
And how can I rewrite the following code to be OK in both 32-bit and 64-bit machines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您想知道您是否正确选择了 UInt32 类型。答案是肯定的。文档明确表示它始终是 32 位值: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx
您的代码是正确的。
I guess you are wondering if you chose the type UInt32 correctly. The answer is yes. The docs explicitly say it is always 32 bit value: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx
Your code is correct.