Click to See Complete Forum and Search --> : how to convert Inptr into HWND
r00d0034
August 22nd, 2002, 06:24 AM
if i have hwndle (Intptr)of parent window and hwndle of child window then how to get the point and rectangle of child window with respect to its parent window ?
how to convert HWND into intptr?
sammyh
November 4th, 2002, 05:27 PM
I'm having the opposite problem, I need to convert an IntPtr to an HWND..... Any suggestions. Thanks
-Sam
Sput
November 4th, 2002, 06:12 PM
I don't know a lot about .NET yet, but why would you want to convert from an IntPtr to and HWND? In .NET, an hwnd is an IntPtr.
So, let me take a guess....
For Instance, in the expression: Graphics newGraphic = Graphics.FromHwnd(hWnd)
the hWnd is actually an IntPtr that can come from something like myForm.Handle().
Is it because you are trying to use UnManaged code passing it a managed hWnd (or IntPtr) ?
Anyways, to convert to an SDK's version of an HWND, one theory (without any testing!!) would be: HWND hWnd = (HWND)MyIntPtr.ToInt32().
I also couldn't find any nice methods to convert a .NET hWnd to an SDK's HWND. But I didn't expect to find one either.
To get the rectangle reference to its parent. Look for something like:
Control.RectangleToScreen(), control.RectangleToClient().
Basically, convert the child window's rectangle to the screen, and then convert the screen to the parent's client.
sammyh
November 5th, 2002, 11:16 AM
You are da man.
I was calling a dll function that wanted an HWND, but in C# you can only get an IntPtr.
It gave:
error C2664: cannot convert parameter 2 from 'System::IntPtr' to 'HWND'
but your snippet worked wonderfully.
Thank you very much
WillemM
November 6th, 2002, 11:40 AM
Hwnd = 32 bit integer, so... in the class definition it would look like this.
Int32 hWnd;
or
int hWnd;
You can do the following with the IntPtr variable:
IntPtr.ToInt32();
So
hWnd = IntPtr.ToInt32();
see ?
Simple like it gets, and I think this works also !
(sorry can't test it at the moment)
evschu
March 18th, 2003, 03:51 PM
I'm new to C, new to C++ and new to VC++.net, so you can imagine that i get frustrated, plus I'm learning DirectShow. anyway, this post helped alot.
What worked for me:
IntPtr handle;
handle = CppForm::get_Handle();
g_hwnd = (HWND)handle.ToInt32();
note: g_hwnd is a global variable
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.