Monthly Archives: April 2006

Creating a new document in a MDI application

Suppose you want to create a new document manually in your MDI application. The following code allows to do this. It assumes that theApp is a CWinApp derived class holding a pointer m_pMyDocTpl to the CMultiDocTemplate which will instantiate your document. But you can use the CWinApp::GetFirstDocTemplatePosition() and CWinApp::GetNextDocTemplate() functions to select the type of document template.

CMultiDocTemplate* pDocTpl = theApp.m_pDocTpl;
CDocument* pDoc     = pMyDocTpl->CreateNewDocument();
CFrameWnd* pFrame   = pDocTpl->CreateNewFrame( pDoc, NULL);
pDocTpl->InitialUpdateFrame( pFrame, pDoc);

Getting list control events for a CListView

Imagine you have a CView derived view, like a CListView. You would like to do some treatments when events occurs on the list control ,like a double click. Since you don’t know the control ID of the CListCtrl in the CListView, you can’t just do a :

ON_NOTIFY(NM_DBLCLK, IDC_VIEWLISTCTRL, OnDblclkList)

This is the utilitiy of ON_NOTIFY_REFLECT

ON_NOTIFY(NM_DBLCLK, OnDblclkList)

Try it, it’s magic, it works !