RE: How to get the main frame window from a doc class?
From: Thomas Sedlaczek (ThomasSedlaczek_at_discussions.microsoft.com)
Date: Mon, 29 Nov 2004 09:46:03 -0800
All what you need to send a message to you MainFaim is adding the following
line to your thread function:
AfxGetMainWnd()->PostMessage(wParam, lParam, 0);
> Hi, there,
> I have a SDI application, and would like to create a working thread when
> loading the doc class. To send message to the main frame window to show what
> is going on, I have to wrap the main frame window's pointer or handler to the
> working thread. I used following code to wrap the pointer:
> BOOL CMyDoc::OnNewDocument()
> THREADPARMS* ptp = new THREADPARMS;
> ptp->hWnd = ::AfxGetMainWnd(); //*
> AfxBeginThread(Get_Init_Rects, ptp);
> ptp->hWnd is a CWnd* data. It get always NULL here. I tried to use
> CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd(); // failed, get NULL
> and HWND hWnd = ::GetActiveWindow(); // failed, get
> What was wrong with my code? Will AfxGetMainWnd return the APP's pointer or
> the Main Frame's pointer? I checked the executing sequence. The doc's new
> method is after the main frame's constructor. Why it turns NULL?
> And in my case, is there any better method to send message to mainframe?
> Any suggestion?
> Thanks lot!