Multiple Selection Menu – Part 2

The previous article showed how tu use a WH_MSGFILTER hook in order to make a menu with multiple selection. Now, let’s see an MFC-extension class that implements a context pop-up menu with multiple selection. CMultiSelPopupMenu class class CMultiSelPopupMenu : public CMenu { // Construction public: CMultiSelPopupMenu(UINT nIDResource, UINT nSubMenu); // Operations public: void MDX_Check(CDataExchange* pDX, WORD wItemID, BOOL& … Read more

Custom MDI “More Windows” Dialog

Few words about MDI Window menu In an MDI aplication, the Window menu contains items which alow selecting/activating one of the open documents. If the number of open documents exceeds 9, then Window menu is appended with a “More Windows…” item.   If the user selects “More Windows…”, a “Select Window” dialog appears, in which all … Read more

How to detect memory leaks in MFC?

MFC framework has bult-in support for detecting memory leaks. Let’s say we have the following in the CFoo class implementation: #include “StdAfx.h” #include “Foo.h” CFoo::CFoo() { m_buffer = new char[128]; strcpy(m_buffer, “Baba Safta”); } CFoo::~CFoo() { } Neither in CFoo’s destructor, nor in any other place, the delete operator is called for freeing m_buffer. After … Read more

Enumerate documents in MDI applications

To enumerate all open documents in MDI (Multiple Document Interface) MFC applications we can do the following: Use CWinApp::GetFirstDocTemplatePosition and CWinApp::GetNextDocTemplate to get application document templates. For each document template, use CDocTemplate::GetFirstDocPosition and CDocTemplate::GetNextDoc to get contained documents. Getting documents list // MyMDIApp.h // … typedef CTypedPtrList<CObList, CDocument*> DocsPtrList; // … class CMyMDIApp : public … Read more