RE: How to get the main frame window from a doc class?

From: Thomas Sedlaczek (ThomasSedlaczek_at_discussions.microsoft.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 09:46:03 -0800

Hello Gary,

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

Regards
Thomas

"Gary" wrote:

> 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
> NULL
>
> 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!
>
> Gary



Relevant Pages

  • Get the Main Frame window from doc class?
    ... and would like to create a working thread when ... To send message to the main frame window to show what ... I used following code to wrap the pointer: ... AfxBeginThread(Get_Init_Rects, ptp); ...
    (microsoft.public.vc.mfc.docview)
  • How to get the main frame window from a doc class?
    ... and would like to create a working thread when ... To send message to the main frame window to show what ... I used following code to wrap the pointer: ... AfxBeginThread(Get_Init_Rects, ptp); ...
    (microsoft.public.vc.mfc)
  • Re: Get the Main Frame window from doc class?
    ... This is because in an SDI application the OnNewDocument is called prior to ... > I have a SDI application, and would like to create a working thread when ... To send message to the main frame window to show ... I used following code to wrap the pointer: ...
    (microsoft.public.vc.mfc.docview)
  • Re: using Document object from CFrameWnd
    ... I created a simple SDI app to test all this,in that I create two splitters ... If try to use the same thing that I used in CMyFrame to get the pointer i.e: ... I think perhaps that when your frame window (the one in the splitter) is active, ...
    (microsoft.public.vc.mfc)
  • Re: Safe pointer arithmetic and typecasts :D
    ... > to something else, though, you should use a pointer of that type. ... I assume delphi will always allow a programmer to ... > don't get any overflow when doing pointer arithmetic. ... Why doesn't delphi just wrap it? ...
    (alt.comp.lang.borland-delphi)