C# 十六进制值到 IntPtr

发布于 2024-08-15 16:08:21 字数 417 浏览 7 评论 0原文

我有一个使用 Spy++ 找到的窗口的十六进制值。

该值是: 00010010

感谢我之前提出的问题的答案,我有这样的代码:

IntPtr hwndf = this.Handle;
IntPtr hwndParent = FindWindow("WINDOW HERE", null); ;

SetParent(hwndf, hwndParent);
this.TopMost = false;

现在,据我了解, IntPtr hwndParent 将包含窗口 WINDOW HERE 的句柄。我如何重写该行以使用我的十六进制句柄?我尝试过:

IntPtr hwndParent = (IntPtr) 0x00010010

但没有成功。有什么想法吗?

I have a hex value to a window i found using Spy++.

the value is: 00010010

Thanks to an answer to a question i asked earlier, i have this code:

IntPtr hwndf = this.Handle;
IntPtr hwndParent = FindWindow("WINDOW HERE", null); ;

SetParent(hwndf, hwndParent);
this.TopMost = false;

Now, as far as i understand it, IntPtr hwndParent will contain the handle to the window WINDOW HERE. How can i rewrite that line to use my hex handle? I tried:

IntPtr hwndParent = (IntPtr) 0x00010010

But it didnt work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

偷得浮生 2024-08-22 16:08:21

那么,00010010 的十六进制等效值是 0x12。所以理论上你可以使用

IntPtr hwndParent = (IntPtr) 0x12

Windows 计算器来完成这种转换。不过,这个值听起来并不正确。您能更详细地解释一下您是如何获得该值的吗?

编辑:您的评论提到您正在尝试获取桌面窗口的句柄。有一个函数:GetDesktopWindow,它返回一个 IntPtr。如果您只对桌面窗口感兴趣,请使用它。

这是该函数的 P/Invoke:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetDesktopWindow();

Well, the hex equivalent of 00010010 is 0x12. So you could theoretically use

IntPtr hwndParent = (IntPtr) 0x12

The Windows calculator can do that conversion. That value doesn't sound correct, though. Can you explain in more detail how you got that value?

EDIT: Your comment mentions that you're trying to get a handle to the desktop window. There's a function for that: GetDesktopWindow, which returns an IntPtr. If all you're ever interested in is the desktop window, use that.

Here's the P/Invoke for that function:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetDesktopWindow();
奢望 2024-08-22 16:08:21

IntPtr 的构造函数接受一个初始化参数:

IntPtr hwndParent = new IntPtr(0x00010010);

The constructor of IntPtr accepts an initialization parameter:

IntPtr hwndParent = new IntPtr(0x00010010);
穿透光 2024-08-22 16:08:21

尝试:

 Convert.ToInt32("00010010", 16);

Try:

 Convert.ToInt32("00010010", 16);
ˉ厌 2024-08-22 16:08:21

这应该有效

 var hwnd = new IntPtr(Convert.ToInt32({HexNumber}, 16));

This should work

 var hwnd = new IntPtr(Convert.ToInt32({HexNumber}, 16));
一笑百媚生 2024-08-22 16:08:21

既然您正在谈论这个问题:您似乎不想创建一个小部件/窗口位于桌面顶部但位于另一个窗口顶部?
如果是这样,为什么不使用 FindWindow() 来查找该窗口呢?

为什么是常数值?

Since you're talking about this question: It seems you don't want to create a widget/window on top of the desktop but on top of another window instead?
If that's the case, why don't you use FindWindow() to - find that window?

Why a constant value?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文