views:

319

answers:

5

Hi all.

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?

+1  A: 

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();
Michael Petrotta
A: 

Try:

 Convert.ToInt32("00010010", 16);
richardtallent
A: 

This should work

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

The constructor of IntPtr accepts an initialization parameter:

IntPtr hwndParent = new IntPtr(0x00010010);
joshperry
A: 

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?

Benjamin Podszun