Developer Sample Code

Only include OnWhatIsThis, OnRButtonDown and m_cLastRClickControl if you want a right click to bring up the "What's this?" popup menu.
[ Note the use of & in this web page source ]

#include "afxpriv.h";	// To get HID_BASE_CONTROL

class CMyDlg : public CDialog
{
	...
protected:
	afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnWhatIsThis();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
private:
	CWnd* m_cLastRClickControl;
};


BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	...
	ON_WM_HELPINFO()
	ON_WM_RBUTTONDOWN()
	//}}AFX_MSG_MAP
	ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()


BOOL CMyDlg::OnHelpInfo(HELPINFO* pHelpInfo) 
{
	if( AfxGetApp()->m_bHelpMode)
	{
		AfxGetApp()->WinHelp(HID_BASE_CONTROL + (pHelpInfo->dwContextId & 0x0000FFFF),HELP_CONTEXTPOPUP);
		AfxGetApp()->m_bHelpMode = FALSE;
		return TRUE;
	}
	return CDialog::OnHelpInfo(pHelpInfo);
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if( (nID&0xFFF0) == SC_CONTEXTHELP)
		AfxGetApp()->m_bHelpMode = TRUE;
	CDialog::OnSysCommand(nID, lParam);
	if( (nID&0xFFF0) == SC_CONTEXTHELP)
		AfxGetApp()->m_bHelpMode = FALSE;
}

void CMyDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	m_cLastRClickControl = ChildWindowFromPoint (point);
	if (m_cLastRClickControl == NULL ||
		m_cLastRClickControl->m_hWnd == m_hWnd ||
		m_cLastRClickControl->GetWindowContextHelpId()==0)
		return;

	CMenu menu;
	if (menu.LoadMenu(IDR_WHAT_IS_THIS_MENU))
	{
		CMenu* pPopup = menu.GetSubMenu(0);
		if( pPopup!=NULL)
		{
			ClientToScreen(&point);
			pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
				point.x, point.y,
				this); // use me for cmds
		}
	}
}

void CMyDlg::OnWhatIsThis()
{
	theApp.WinHelp( HID_BASE_CONTROL + m_cLastRClickControl->GetDlgCtrlID(), HELP_CONTEXTPOPUP);
}