Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I get the hWnd?

484 views
Skip to first unread message

Jose María del Álamo

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to
I have made a program with a class derivate from CWinApp and there I
call to PreTranslateMessage to catch the messages coming from a
joystick. In a joystick's function (joySetCapture), I need to pass th
handle of my window, but I do not know how to get it. Can anyone help
me?
Thanks in advance.


Davorin Perkovic - Pjer

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to
HWND hwnd = GetSafeHwnd(()

"Jose María del Álamo" <gci...@fais.upm.es> wrote in message
news:3896BFD2...@fais.upm.es...

Jose María del Álamo

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to Davorin Perkovic - Pjer
I have tried to do this but I get an error message:
'CWnd::GetSafeHwnd' : illegal call of non-static member function
I do not know whether it is because I haven´t a CWnd class (I have only a
CWinApp and A CFrameWnd classes) or not.
Thanks.

Davorin Perkovic - Pjer escribió:

Davorin Perkovic - Pjer

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to
Try this:
///////////////////////////////////////////////////////////////////////////
CWnd *pWnd = AfxGetMainWnd();
HWND hwnd = NULL;
if (pWnd)
hwnd = pWnd ->GetSafeHwnd();
///////////////////////////////////////////////////////////////////////////

or this:
///////////////////////////////////////////////////////////////////////////
CWnd *pWnd = AfxGetApp()->m_pMainWnd;
HWND hwnd = NULL;
if (pWnd)
hwnd = pWnd->GetSafeHwnd();
///////////////////////////////////////////////////////////////////////////

////////////////////////////////// From MSDN ///////////////////////////

CWnd* AfxGetMainWnd( );

Return Value

If the server has an object that is in-place active inside a container, and
this container is active, this function returns a pointer to the frame
window object that contains the in-place active document.

If there is no object that is in-place active within a container, or your
application is not an OLE server, this function simply returns the
m_pMainWnd of your application object.

If AfxGetMainWnd is called from the application's primary thread, it returns
the application's main window according to the above rules. If the function
is called from a secondary thread in the application, the function returns
the main window associated with the thread that made the call.

Remarks

If your application is an OLE server, call this function to retrieve a
pointer to the active main window of the application instead of directly
referring to the m_pMainWnd member of the application object.

If your application is not an OLE server, then calling this function is
equivalent to directly referring to the m_pMainWnd member of your
application object.

"Jose María del Álamo" <gci...@fais.upm.es> wrote in message

news:3896C90C...@fais.upm.es...

0 new messages