MFC CSingleDocTemplate - Programmer

This is a discussion on MFC CSingleDocTemplate - Programmer ; Hello, I'm using the following code : BOOL CappApp::InitInstance() { .... pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME, RUNTIME_CLASS(CappDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CappView)); .... } void CappApp::OnFileOpen() { OPENFILENAME ofn; LPSTR fn; memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ::GetOpenFileName(&ofn); fn = ofn.lpstrFile; !>> Here I ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: MFC CSingleDocTemplate

  1. MFC CSingleDocTemplate

    Hello,

    I'm using the following code :

    BOOL CappApp::InitInstance()
    {
    ....
    pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
    RUNTIME_CLASS(CappDoc), RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CappView));
    ....
    }

    void CappApp::OnFileOpen()
    {
    OPENFILENAME ofn;
    LPSTR fn;

    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ::GetOpenFileName(&ofn);
    fn = ofn.lpstrFile;

    !>> Here I need to access the view window DC instead of the app window
    DC.

    CDC *dc = this->m_pMainWnd->GetWindowDC();
    dc->TextOut(0,0,"Done!");
    }

    I'm new to MFC, so any help would be appreciated.

    Adrien


  2. Re: MFC CSingleDocTemplate

    This will give you a pointer to the active view class from your CWinApp
    derived class.

    CView* pActiveView= ((CFrameWnd*) m_pMainWnd)->GetActiveView();

    -Eric

    "Adrien Constant" wrote in message
    news:1125525048.920035.199190@f14g2000cwb.googlegr oups.com...
    > Hello,
    >
    > I'm using the following code :
    >
    > BOOL CappApp::InitInstance()
    > {
    > ...
    > pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
    > RUNTIME_CLASS(CappDoc), RUNTIME_CLASS(CMainFrame),
    > RUNTIME_CLASS(CappView));
    > ...
    > }
    >
    > void CappApp::OnFileOpen()
    > {
    > OPENFILENAME ofn;
    > LPSTR fn;
    >
    > memset(&ofn, 0, sizeof(ofn));
    > ofn.lStructSize = sizeof(ofn);
    > ::GetOpenFileName(&ofn);
    > fn = ofn.lpstrFile;
    >
    > !>> Here I need to access the view window DC instead of the app window
    > DC.
    >
    > CDC *dc = this->m_pMainWnd->GetWindowDC();
    > dc->TextOut(0,0,"Done!");
    > }
    >
    > I'm new to MFC, so any help would be appreciated.
    >
    > Adrien
    >




  3. Re: MFC CSingleDocTemplate


    "Adrien Constant" wrote in message
    news:1125525048.920035.199190@f14g2000cwb.googlegr oups.com...
    >
    > void CappApp::OnFileOpen()
    > {
    > OPENFILENAME ofn;
    > LPSTR fn;
    >
    > memset(&ofn, 0, sizeof(ofn));
    > ofn.lStructSize = sizeof(ofn);
    > ::GetOpenFileName(&ofn);
    > fn = ofn.lpstrFile;
    >
    > !>> Here I need to access the view window DC instead of the app window
    > DC.
    >
    > CDC *dc = this->m_pMainWnd->GetWindowDC();
    > dc->TextOut(0,0,"Done!");
    > }
    >
    > I'm new to MFC, so any help would be appreciated.
    >


    You usually don't want to do "dc->TextOut" - particularly from the
    CDocument.

    Either:
    - pop up a MessageBox

    or call:
    - UpdateAllViews(... );
    and then handle your message from the OnUpdate() function in the View.

    Your Doc shouldn't make any assumptions about your View. "dc->TextOut"
    makes the assumption that your view is a Window - either a CView or a
    CScrollView. It could just as easily be a CFormView (dialog), a ListView, a
    TreeView or some other such critter.



+ Reply to Thread