Figures
Figure 3 DynPrompt MainFrm.h

////////////////
// Standard MFC main frame window
//
class CMainFrame : public CFrameWnd {
public:
   virtual ~CMainFrame();

protected:
   CStatusBar  m_wndStatusBar;
   CToolBar    m_wndToolBar;
   CMainFrame();
   DECLARE_DYNCREATE(CMainFrame)

   //{{AFX_MSG(CMainFrame)
   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
   afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
};
MainFrm.cpp

////////////////////////////////////////////////////////////////
// DynPrompt
// If this program works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// DynPrompt shows how to implement a dynamically changing menu prompt in MFC.
// All the action is in CMainFrame::OnMenuSelect.
//
#include "StdAfx.h"
#include "DynPrompt.h"
#include "MainFrm.h"
#include <afxpriv.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
   //{{AFX_MSG_MAP(CMainFrame)
   ON_WM_CREATE()
   ON_WM_MENUSELECT()
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] = {
   ID_SEPARATOR,           // status line indicator
   ID_INDICATOR_CAPS,
   ID_INDICATOR_NUM,
   ID_INDICATOR_SCRL,
};

CMainFrame::CMainFrame()
{
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   .
   . // zzz
   .
   return 0;
}

//////////////////
// Handler for WM_MENUSELECT: If the command ID has a dynamic prompt,
// send WM_SETMESSAGESTRING. Otherwise pass to MFC.
//
void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
   if (ID_FILE_MRU_FILE1<=nItemID && nItemID<=ID_FILE_MRU_FILE16) {

      // Get menu item name, which is something like "&1 file name".
      CMenu* pMenu = GetMenu();         // top level menu
      ASSERT(pMenu);
      pMenu=pMenu->GetSubMenu(0);       // File menu is 1st
      ASSERT(pMenu);
      CString sFileName;
      pMenu->GetMenuString(nItemID, sFileName, MF_BYCOMMAND);

      // Strip "&n" where n is file number.
      int nSkip = sFileName.Find(' ');
      sFileName = sFileName.Right(sFileName.GetLength()-nSkip);

      // Create prompt string.
      CString sPrompt;
      sPrompt.Format(_T("Open the file %s"), (LPCTSTR)sFileName);

      // Set prompt in status bar.
      SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)sPrompt);

   } else {
      CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
   }
}
Page view tracker