- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想 P/Invoke 到 GetWindowLongPtr和 SetWindowLongPtr ,而且我看到了关于它们的相互矛盾的信息。
一些消息称,在 32 位平台上,GetWindowLongPtr 只是一个调用 GetWindowLong 的预处理器宏,而 GetWindowLongPtr 并不作为 user32.dll 中的入口点存在。例如:
所以这些来源似乎表明 *Ptr 入口点根本不存在于 user32.dll 版本中,例如,32 位 Windows 7。
但我在 MSDN 文档中看不到这一点的指示。根据 MSDN,SetWindowLongPtr取代 SetWindowLong,简单明了。并根据SetWindowLongPtr page段的要求,似乎 SetWindowLongPtr 自 Windows 2000(客户端和服务器版本)以来一直在 user32.dll 中。同样,没有提到 32 位操作系统中缺少入口点。
我怀疑事实介于两者之间:当您告诉 C++ 编译器针对较旧的操作系统(即编译将在 Win9x 和 NT4 上运行的东西)时,头文件将 SetWindowLongPtr 声明为调用 SetWindowLong 的宏,但入口点可能确实存在于 Windows 2000 及更高版本中,如果您告诉编译器以这些平台为目标,您将直接获取它(而不是宏)。但这只是一个猜测;我真的没有资源或专业知识来挖掘和验证它。
目标平台也有可能发挥作用——如果您为 x86 平台编译您的应用程序,那么您不应该在 64 位操作系统上调用 SetWindowLongPtr。同样,我知道的足以想到这个问题,但我不知道如何找到答案。 MSDN 似乎建议 SetWindowLongPtr 总是正确的。
谁能告诉我简单地 P/Invoke 到 SetWindowLongPtr 并完成它是否安全? (假设是 Windows 2000 及更高版本。)P/调用 SetWindowLongPtr 会给我正确的入口点吗:
最佳答案
我建议您按照 Windows 窗体内部处理的方式处理此问题:
public static IntPtr GetWindowLong(HandleRef hWnd, int nIndex)
{
if (IntPtr.Size == 4)
{
return GetWindowLong32(hWnd, nIndex);
}
return GetWindowLongPtr64(hWnd, nIndex);
}
[DllImport("user32.dll", EntryPoint="GetWindowLong", CharSet=CharSet.Auto)]
private static extern IntPtr GetWindowLong32(HandleRef hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint="GetWindowLongPtr", CharSet=CharSet.Auto)]
private static extern IntPtr GetWindowLongPtr64(HandleRef hWnd, int nIndex);
关于c# - 如何在 32 位平台上调用 GetWindowLongPtr 和 SetWindowLongPtr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3343724/
我尝试子类化另一个窗口(在另一个进程中),因此我注入(inject)了一个 dll,它调用 SetWindowLongPtr,但它失败并且 GetLastError 返回 5。 BOOL APIENT
我想在我的程序中继承 RichEdit(这里是 C++ 代码:http://dumpz.org/46182/)。 _native_log 是richedit 的一个hwnd。起初一切正常,LogWin
我一直在努力学习如何使用 SetWindowLongPtr() 并将其理解如下: 您可以使用以下函数获取当前消息并将其发送到自定义协议(protocol):LONG_PTR Some_Ptr = Se
我还在为钩子(Hook)而苦苦挣扎。 我的目标是: 在notepad.exe中设置一个钩子(Hook) 对其进行子类化(我的最终目标是将 Edit 类子类化并在我自己的窗口中显示内容) 免责声明:我知
前阵子,我用 Win32 API 编写了一个 C++ 程序,它会显示一个对话框,然后收听它生成的消息。有一次,我对将一段数据与对话窗口相关联很感兴趣。如果我手动创建窗口并附加一个窗口过程,我只需使用
关于 MSDN网站,我发现以下内容: Calling SetWindowLongPtr with the GWLP_WNDPROC index creates a subclass of the wi
我知道可以使用 SetWindowLongPtr + GWLP_USERDATA 来存储指向某些数据的指针。但是是否可以直接存储数据,例如“句柄”、“ bool 值”、“整数”或其他更大的数据。 来自
我需要为桌面上的一些应用程序窗口创建一个水印窗口(markHwnd),水印窗口样式为: uint dwStyle = Win32API.WS_CLIPSIBLINGS |
我正在编写一个自定义 Win32 UI 控件,我想在其中加入视觉主题。我将主题加载到它的 WM_NCCREATE 中: case WM_NCCREATE: { HTHEME hTheme =
我想 P/Invoke 到 GetWindowLongPtr和 SetWindowLongPtr ,而且我看到了关于它们的相互矛盾的信息。 一些消息称,在 32 位平台上,GetWindowLongP
我目前正在处理一个涉及使用 SWT 的 Eclipse RCP 的 Java 项目,并试图通过在保存时向 Windows 环境中的用户提供有意义的消息来处理正常关闭。我应该使用 ShutdownBlo
我是一名优秀的程序员,十分优秀!