Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to view some information of a external Window (not from my application).
getting the IntPtr work but for the GetWindowRect i need a HandleRef, but How do I get this from the IntPtr as it would be more infromation.


The Code looks like:
C#
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);

IntPtr hwnd = FindWindow(null, "WindowName");
RECT rct;

bool ret = GetWindowRect(hwnd, out rct); # Error (hwnd)


Problem:
Argument 1: cannot convert from 'System.IntPtr' to 'System.Runtime.InteropServices.HandleRef'


How can I convert the IntPtr to HandleRef?
Posted
Updated 27-Sep-11 0:56am
v2
Comments
Md. Rashim Uddin 28-Sep-11 1:35am    
Did u try with given solutions???

1 solution

Please have a look on that [^]

Another way you might use something like that

C#
GetWindowRect(new HandleRef(this, this.Handle), out rct ) 
 
Share this answer
 
v2
Comments
TomasEe 2-Oct-11 14:09pm    
I do not realy understand why should use 'this'?

But the hint helped my ...
new HandleRef(NULL, hwnd);
Md. Rashim Uddin 2-Oct-11 14:16pm    
See here this refers the current window. Better if you visit http://pinvoke.net/ and look on that.
AlexanderPD 1-Jul-14 4:46am    
Thank you TomasEe, that was exatly what i needed ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900