getting a pointer to a Project's window

How do I get a pointer to an Audacity Project’s window? Something like:

wxWindow * projectWindow = gAudacityProjects[0]->GetWindow();

Tracing up the inheritance tree for AudacityProject I find:

class AUDACITY_DLL_API AudacityProject:  public wxFrame,
class WXDLLEXPORT wxFrame : public wxFrameBase
class WXDLLEXPORT wxFrameBase : public wxTopLevelWindow
class WXDLLEXPORT wxTopLevelWindow : public wxTopLevelWindowMSW
class WXDLLEXPORT wxTopLevelWindowMSW : public wxTopLevelWindowBase
class WXDLLEXPORT wxTopLevelWindowBase : public wxWindow

(where wxTopLevelWindowMSW is compiled in on a processor dependent basis) but doing:

wxWindow * projectWindow = gAudacityProjects[0];

causes a compiler error. I’m concerned that if I force it with a cast (which works on 64-bit Vista SP2):

wxWindow * projectWindow = (wxWindow *)gAudacityProjects[0];

I will get problems, especially on other OSes. Note that wxTopLevelWindowMSW is a Windows specific class.

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)?


You can use WindowFromPoint() to retrieve the window at a specific coordinate like the mouse position. This function retrieves a handle to the window that contains the specified point.

HWND WindowFromPoint(
__in POINT Point


Point [in]

Specifies a POINT structure that defines the point to be checked.

Return Value