Click here to Skip to main content
16,017,261 members
Articles / Desktop Programming / MFC
Article

Simple RTF based Help Dialog

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
3 Oct 2001CPOL2 min read 100.6K   3.3K   29   16
Yet Another Simple Help Dialog

Sample Image - MyHelpDialog.jpg

Introduction

This Rich Text based Help Dialog is a quick and easy way of adding on-line help to your applications. For some applications its just too much work to build a complete help system, but its sufficient to display some guide lines. This dialog has the "looks and feel" of the real thing.

Features

  • Standard Help Window look and feel
  • Auto size of window to fit RTF text
  • Resizable
  • Auto scrollbars in case window is resized too small to fit complete RTF text
  • Copy and Print via context menu
  • Can load RTF from resource OR from file on disk

How to add this class to your project

The steps to include this dialog into your project are:

  1. Add the HelpDialog.cpp and HelpDialog.h files to your project
  2. Copy and Paste the following Help Dialog resources from the demo project resources into your project:
    • IDR_POPUP_HELP_MENU menu
    • IDD_HELP_DIALOG dialog
    • IDI_HELP_ICON icon
  3. Add a Help button or menu to your project (see sample project)

The Rich Text Format (RTF) contents of the help message can best be created using Wordpad. I have tried Word as well, but the resulting RTF format is sometimes too elaborate to be used in the Rich Edit control. You can tell if your RTF it too elaborate, because if that is the case the Help Dialog will not show any message at all ;-)

The RTF can be loaded in two different methods, the first is to import the RTF file into the resources of your project. The 2nd method is to load the RTF file from disk at runtime. Select the method that fits your needs best. The demo project shows both methods.

#include "HelpDialog.h"
//
// Example using the class from RTF resource
//
CSimpleHelpDemoDlg::OnHelpButton()
{
	CHelpDialog hlp(this, IDR_HELP); 	// create Help Dialog using RTF resource
	hlp.SetTitle( "Simple Help Demo" ); 	// set a title (optional)
	hlp.DoModal(); 			// pop it up
}

The next code show how to load the help message from a file on disk:

#include "HelpDialog.h"
//
// Example loading RTF from disk
//
CSimpleHelpDemoDlg::OnHelpButton()
{
	CHelpDialog hlp(this); 		// create Help Dialog
	hlp.SetTitle( "Simple Help Demo" ); 	// set a title (optional)
	hlp.LoadRTFFile( "Help2.rtf" );	// load the RTF from file
	hlp.DoModal(); 			// pop it up
}

The demo project also shows (see both Help menu items) how to use the dialog in modeless mode. Although a little bit more work is required, this is the preferred method. With a modeless help dialog, the user can switch to the application and refer to the help dialog at the same time. With the modal approach, as in the samples above, the help dialog must be closed first before the application window can be accessed.

Final notes

This article was inspired by the TCX Message Box By Thales P. Carvalho and in fact I used his dialog class at first for my help messages. Later I felt the need to make it look more like a real help message, hence this class. And yes, I know there's the real help system out there, but the steps involved in building a real help file (RTF file, Help ID's, Help Compiler, etc.) are sometimes simply too much work.

History

4 Oct 2001 - fix for the detected streamin bug.

License

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


Written By
Software Developer (Senior)
Netherlands Netherlands
I've been in touch with computers since 1979 when I bought my OSI Superboard. Self taught men ever since, learned C programming on a VAX, learned MFC for a nice Space related project.
Later came into contact with C#/.NET and reached MCAD level in 2007 (now expired).

I'm currently employed by a small engineering firm in the Netherlands, where I live.

Comments and Discussions

 
QuestionHow to Load Image?? Pin
xdchen2620-Feb-14 19:11
xdchen2620-Feb-14 19:11 
AnswerRe: How to Load Image?? Pin
Antoine Megens20-Feb-14 22:07
Antoine Megens20-Feb-14 22:07 
QuestionCallback routine incorrect for unicode Pin
Member 949563210-Oct-13 13:29
Member 949563210-Oct-13 13:29 
Questionhow to go set and use a bookmark ?? Pin
xiaocong00421-Feb-12 18:15
xiaocong00421-Feb-12 18:15 
AnswerRe: how to go set and use a bookmark ?? Pin
Antoine Megens22-Feb-12 0:24
Antoine Megens22-Feb-12 0:24 
GeneralRe: how to go set and use a bookmark ?? Pin
xiaocong00422-Feb-12 1:44
xiaocong00422-Feb-12 1:44 
QuestionRTF Image support [modified] Pin
bethgocs18-Jun-06 1:12
bethgocs18-Jun-06 1:12 
AnswerRe: RTF Image support [modified] Pin
Antoine Megens18-Jun-06 21:31
Antoine Megens18-Jun-06 21:31 
GeneralWindow is not Updated Pin
Azghar Hussain6-Oct-03 2:18
professionalAzghar Hussain6-Oct-03 2:18 
GeneralRe: Window is not Updated Pin
Antoine Megens6-Oct-03 3:04
Antoine Megens6-Oct-03 3:04 
GeneralRe: Window is not Updated Pin
Azghar Hussain6-Oct-03 4:21
professionalAzghar Hussain6-Oct-03 4:21 
GeneralRe: Window is not Updated Pin
Antoine Megens6-Oct-03 4:52
Antoine Megens6-Oct-03 4:52 
General[Message Removed] Pin
immetoz4-Oct-08 15:12
immetoz4-Oct-08 15:12 
Questionwindow too big? Pin
Antoine Megens12-Jun-02 23:15
Antoine Megens12-Jun-02 23:15 
Generala bug Pin
dragonred10-Sep-01 15:30
dragonred10-Sep-01 15:30 
i got some useful information from you program.but there is something wrong with your callback function '_LoadRtfCallback'. i think it should be written as follow:
HELP *pHelp = (HELP *)dwCookie;
if (!pHelp) return 0xFFFFFFFF; //error

LPCTSTR pszMsg = (LPCTSTR)pHelp->m_StrPointer;


// number of bytes to copy
*pcb = _tcslen( pszMsg ) * sizeof(TCHAR);

if (pHelp->m_nOffset >= *pcb )
return 0xFFFFFFFF; //end

pszMsg += pHelp->m_nOffset ;

*pcb -= pHelp->m_nOffset;
// limiting it up to the buffer's size
if( *pcb > cb )
*pcb = cb;
// copying the string to the buffer
memcpy( pbBuff,pszMsg, *pcb );


// advancing to the end of the string
pHelp->m_nOffset += *pcb;
return NULL;
GeneralRe: a bug Pin
Antoine Megens3-Oct-01 3:27
Antoine Megens3-Oct-01 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.