|
-
August 8th, 2005, 10:36 AM
#1
How to get a pointer from a window handle?
Is there any win32 API to do that? Thanks for your inputs.
-
August 8th, 2005, 10:47 AM
#2
Re: How to get a pointer from a window handle?
CWnd::FromHandle
static CWnd* PASCAL FromHandle( HWND hWnd );
Return Value
Returns a pointer to a CWnd object when given a handle to a window. If a CWnd object is not attached to the handle, a temporary CWnd object is created and attached.
The pointer may be temporary and should not be stored for later use.
Parameters
hWnd
An HWND of a Windows window.
Let me simply be your friend!
-
August 8th, 2005, 10:55 AM
#3
Re: How to get a pointer from a window handle?
Thanks for your reply. But I am using CWindow not CWnd. Any idea? Thanks.
 Originally Posted by wonder88
CWnd::FromHandle
static CWnd* PASCAL FromHandle( HWND hWnd );
Return Value
Returns a pointer to a CWnd object when given a handle to a window. If a CWnd object is not attached to the handle, a temporary CWnd object is created and attached.
The pointer may be temporary and should not be stored for later use.
Parameters
hWnd
An HWND of a Windows window.
-
August 8th, 2005, 11:03 AM
#4
Re: How to get a pointer from a window handle?
try this
Retrieves the current window handle.
Code:
HRESULT GetWindowHandle(
HWND *pHwnd);
Parameters
pHwnd
[out] Window handle.
Return Values
Returns a pointer to the window handle.
-
August 8th, 2005, 11:09 AM
#5
Re: How to get a pointer from a window handle?
CWindow::CWindow
This constructor initializes the m_hWnd data member to hWnd, which by default is NULL.
The CWindow::CWindow method does not create a window. Classes CWindowImpl, CContainedWindow, and CDialogImpl ,all of which derive from CWindow, provide a method to create a window or dialog box, which is then assigned to CWindow::m_hWnd. You can also use the CreateWindow Windows CE function.
CWindow(
HWND hWnd = NULL);
Parameters
hWnd
[in] The handle to a window.
CWindow::Attach
This method attaches the window identified by hWndNew to the CWindow object.
void Attach(
HWND hWndNew );
Parameters
hWndNew
[in] The handle to a window.
Example
// The following example attaches an HWND to the CWindow object.
HWND hWndFoo = ::GetDesktopWindow();
CWindow fooWindow;
fooWindow.Attach(hWndFoo);
Let me simply be your friend!
-
August 8th, 2005, 08:53 PM
#6
Re: How to get a pointer from a window handle?
But I am looking for a win32 API.
 Originally Posted by humptydumpty
try this
Retrieves the current window handle.
Code:
HRESULT GetWindowHandle(
HWND *pHwnd);
Parameters
pHwnd
[out] Window handle.
Return Values
Returns a pointer to the window handle.
-
August 8th, 2005, 10:46 PM
#7
Re: How to get a pointer from a window handle?
 Originally Posted by dullboy
But I am looking for a win32 API.
The Windows API knows nothing about CWindow, CWnd, or any C++ classes used by MFC, ATL, whatever. The next question is "convert HWND to a pointer to what?"
All the API knows is that a window is an HWND. An HWND is whatever it is. This is the type you deal with in an API program, and you don't assume it is a pointer, or a struct, or a class, etc. It is a "HANDLE", which means it represents something that Windows knows about internally that you need not know about.
All you need to know is that HWND is used to represent a window, and you pass it back and forth between your app and the API functions.
For what reason do you need to convert an HWND to a pointer (to something)?
Regards,
Paul McKenzie
Last edited by Paul McKenzie; August 8th, 2005 at 10:50 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|