Date: 2008jun6, 2010feb4
Platform: MFC
Language: C/C++
Q. How do I get the HWND handle for the main Window of my MFC program?
A. First use AfxGetMainWnd() to get the CWnd class then
use GetSafeHwnd() on that as this function demonstrates:
// AfxGetMainWnd() is broken in Visual Studio 2005 so here's my own
inline CWnd *MyGetMainWnd()
{
CWinApp *app;
if ((app = AfxGetApp()) == NULL) return NULL;
return app->m_pMainWnd;
}
inline HWND GetMainHwnd()
{
CWnd * wnd;
if ((wnd = MyGetMainWnd()) == NULL) return NULL;
return wnd->GetSafeHwnd();
}
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment