Getting pointer to CMainFrame with AfxGetMainWnd not working ? 
Author Message
 Getting pointer to CMainFrame with AfxGetMainWnd not working ?


I was trying to get a pointer to the CMainFrame from another class using
this code:

CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();

which i have read will get a pointer from anywhere, but it didn't work and
pFrame was empty after calling. I got the pointer ok using this code

CMainFrame* pFrame = (CMainFrame) AfxGetApp()->m_pMainWnd;

but was wondering why the first code failed and this worked and if there is
certain times when one should be used and the other not or instances which
would result in the return pointer not being valid so the other should be
used like above??


Fri, 03 Sep 2004 21:09:12 GMT  
 Getting pointer to CMainFrame with AfxGetMainWnd not working ?
According to MSDN:

Return Value of AfxGetMainWnd( ):

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.

Therefore, the routine may return NULL if the calling thread has no Main

Sun, 05 Sep 2004 14:43:43 GMT  
 [ 2 post ] 

 Relevant Pages 

1. AfxGetMainWnd returns CSplashWnd not CMainFrame during app startup

2. Getting pointer to CMainFrame

3. Getting the CMainFrame Pointer

4. Q: Getting pointer to CMainFrame from document?

5. AfxGetMainWnd won't work!

6. AfxGetMainWnd doesn't work in Doc

7. AfxGetMainWnd won't work!

8. AfxGetMainWnd()->PostMessage(WM_CLOSE) is not fast enough

9. gets() and fgets() Not Working Properly - Source Included


11. C++/ATL/ADO - Intellisense not working (statement completion options) not working

12. FILE pointer not getting value from function


Powered by phpBB® Forum Software