Re: Losing the Document in a SDI application
From: Neel Roy (neelagain_at_hotmail.com)
Date: 05/04/04
- Next message: Neel Roy: "Re: Display Unicode letters in a lsit view application"
- Previous message: Phillip N Rounds: "Losing the Document in a SDI application"
- In reply to: Phillip N Rounds: "Losing the Document in a SDI application"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 5 May 2004 03:16:50 +0530
Thoughts and hints...
> CMyMainFrame::GetActiveDocument();
this aint possible... so you must be using either inside MainFrame class or
getting a pointer...
1)
If getting a pointer perhaps this will work... ONLY if you are calling it
from primary thread...
CDocument *pDoc = ((CMainFrame*)AfxGetMainWnd())->GetActiveDocument();
2)
If calling from worker thread, you need to get App pointer first... because
of implementation of AfxGetThread() and then pApp->m_pMainWnd
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
3)
Since GetActiveDocument() is virtual you can set view you want to be active
and then get the document of that view... perhaps no view is active at that
moment...
CDocument* CFrameWnd::GetActiveDocument()
{
ASSERT_VALID(this);
CView* pView = GetActiveView();
if (pView != NULL)
return pView->GetDocument();
return NULL;
}
Article which might be helpful :
INFO: Switching Views in a Single Document Interface Program
Q99562
"Phillip N Rounds" <prounds@cassandragroup.com> wrote in message
news:OgeS0qeMEHA.556@TK2MSFTNGP10.phx.gbl...
> I have a fairly complicated SDI application which recently has had the
> problem that it, at times, looses the document.
> Basic architecture is
> SDI, with a splitter window.
> The Document has three views:
> View1 is always present in Pane(0,0) of the splitter.
> View2 and View3 are presented in Pane(0,1) of the splitter, with the
> Mainframe handling the switching between the two.
>
> The application has a serial connection to a piece of lab equipment. We
> have a threaded serial communication class, which posts a message when
data
> is received. When the RECEIVED message is posted, the Mainframe reads the
> data and stores it in an array for later processing.
> The Mainframe invokes WM_TIMER, with two timers: One at one second to
> refresh the views with current data, the second at (variably) specified
> intervals to process the data. Data gets initial processing in the
> Mainframe, then put into the Doc.
>
> The two views are as follows: View1 is a CView, which is used to present a
> graphical representation of the data. View2 is a CListView
> to present the data in tabular form. Printing is handled within the
views,
> in View1 by passing a CPrinterDC to the OnDraw() method.
> View2 prints with formatted printing of the data to the printer.
>
> All of this is probably irrelevant, but what the hell.
>
> The problem is that the app will hang at random times. In debugging this,
> the problem is always that the Mainframe loses the document.
>
> CMyDocument* pDoc = CMyMainFrame::GetActiveDocument();
> results in pDoc = NULL
>
> I have added the m_bAutoDelete = false to the CMyDocument constructor,
and
> it made no difference.
> I put a trace into the CMyDocument destructor to see when that was being
> called, and it never was.
>
> Any guesses as to how this may be happening?
>
> Thanks
>
> --
> Phillip N Rounds
> The Cassandra Group, Inc
> 68 Sand Hill Rd
> Flemington NJ 08822
> prounds@cassandragroup.com
>
>
- Next message: Neel Roy: "Re: Display Unicode letters in a lsit view application"
- Previous message: Phillip N Rounds: "Losing the Document in a SDI application"
- In reply to: Phillip N Rounds: "Losing the Document in a SDI application"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|