Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

How to enable context sensitive help for individual controls on a FormView

, 25 Oct 2002
Context sensitive help does not distinguish individual controls on a FormView. This sorts that problem
contexthelp.zip
Projects
ContextHelp
ContextHelp.dsp
ContextHelp.dsw
hlp
Scmin.bmp
AfxPrint.rtf
AppExit.bmp
Bullet.bmp
ContextHelp.cnt
CONTEXTHELP.GID
CONTEXTHELP.HLP
ContextHelp.hm
ContextHelp.hpj
ContextHelp.LOG
ContextHelp.ph
CurArw2.bmp
CurArw4.bmp
CurHelp.bmp
EditCopy.bmp
EditCut.bmp
EditPast.bmp
EditUndo.bmp
FileNew.bmp
FileOpen.bmp
FilePrnt.bmp
FileSave.bmp
HlpSBar.bmp
HlpTBar.bmp
RecFirst.bmp
RecLast.bmp
RecNext.bmp
RecPrev.bmp
Scmax.bmp
ScMenu.bmp
AfxCore.rtf
res
Toolbar.bmp
ContextHelpDoc.ico
ContextHelp.ico
// ContextHelpView.cpp : implementation of the CContextHelpView class
//

#include "stdafx.h"
#include "ContextHelp.h"

#include "ContextHelpDoc.h"
#include "ContextHelpView.h"
#include "AfxPriv.h"

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

/////////////////////////////////////////////////////////////////////////////
// CContextHelpView

IMPLEMENT_DYNCREATE(CContextHelpView, CFormView)

BEGIN_MESSAGE_MAP(CContextHelpView, CFormView)
	//{{AFX_MSG_MAP(CContextHelpView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
	ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContextHelpView construction/destruction

CContextHelpView::CContextHelpView()
	: CFormView(CContextHelpView::IDD)
{
	//{{AFX_DATA_INIT(CContextHelpView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CContextHelpView::~CContextHelpView()
{
}

void CContextHelpView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CContextHelpView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CContextHelpView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CContextHelpView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CContextHelpView printing

BOOL CContextHelpView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CContextHelpView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CContextHelpView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CContextHelpView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CContextHelpView diagnostics

#ifdef _DEBUG
void CContextHelpView::AssertValid() const
{
	CFormView::AssertValid();
}

void CContextHelpView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CContextHelpDoc* CContextHelpView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CContextHelpDoc)));
	return (CContextHelpDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CContextHelpView message handlers
LRESULT CContextHelpView::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
{
	// message is sent to us as follows:
	// dwContext = ::SendMessage(hWnd, WM_HELPHITTEST, 0, MAKELONG(point.x, point.y));
	// WPARAM = 0 ;
	// LPARAM = Point clicked

	CPoint	p((DWORD)lParam) ;

	ClientToScreen(&p) ;

	CWnd *pWnd = WindowFromPoint(p) ;
	if (pWnd != NULL)
		{
		if (pWnd == this)
			return IDD + 0x20000 ;				// convert to correct help ID
		else
			return pWnd->GetDlgCtrlID() + 0x60000 ;
		}
	return 0 ;			// failed!
}

LRESULT	CContextHelpView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	// message is sent to us as a test to see whether we make WinHelp appear
	// return non-zero if we process the message
	// wParam = 0, not used
	// lParam = 0, not used
	CWnd *pWnd = GetFocus();
	if (pWnd != NULL)
	{
		DWORD helpID;
		if (pWnd == this)
			helpID = IDD + 0x20000 ;				// convert to correct help ID
		else
			helpID = pWnd->GetDlgCtrlID() + 0x60000 ;
		
		// we have a control with the focus, pop-up help for it
		AfxGetApp()->WinHelp(helpID);
		return TRUE;
	}
	return FALSE;		// let default handling process it
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Roger Allen
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.
 
I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)
 
I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 26 Oct 2002
Article Copyright 2002 by Roger Allen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid