Is there any win32 API to do that? Thanks for your inputs.
Printable View
Is there any win32 API to do that? Thanks for your inputs.
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.
Thanks for your reply. But I am using CWindow not CWnd. Any idea? Thanks.
Quote:
Originally Posted by wonder88
try this
Retrieves the current window handle.
ParametersCode:HRESULT GetWindowHandle(
HWND *pHwnd);
pHwnd
[out] Window handle.
Return Values
Returns a pointer to the 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);
But I am looking for a win32 API.
Quote:
Originally Posted by humptydumpty
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?"Quote:
Originally Posted by dullboy
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