Link to home
Start Free TrialLog in
Avatar of r parkinson
r parkinson

asked on

Context Sensitive Help

I want to be able to change the ID of the help that is displayed after selecting a button that has the ID_CONTEXT_HELP id.  The default MFC routine for this just grabs your EXE name and path and calls it asking for the help for the ID of the control that you pressed.  I know that I can change the help file name quite easily by setting m_pszHelpFilePath, but I can't seem to trap the call to WinHelp.  I have tried overriding the OnCommandHelp routine as described in the MFC Tech Note 28 but it does not work, the routine is never called. Anyone know what I am doing wrong?

I would also like to know how to change the ID of the button that instigates context sensitive help, if I change the ID it does not work anymore!

Thanks.
Avatar of cdesigner
cdesigner
Flag of Russian Federation image

add handler for WM_HELPINFO in Class wizard.

OnHelpInfo(HELPINFO* pHelpInfo)
{

CDialog::OnHelpInfo(pHelpInfo);
}

look the HELPINFO structure
Avatar of r parkinson
r parkinson

ASKER

More information please.

My App is not a standard MFC app, it has several windows that appear as the mainframe.  It started off as a C app which was ported to MFC so it's quite a complex inntegration with MFC. I have tried in a simple MFC app and the OnHelpInfo routine does not get called.
may be you can simply hook F1 and call you help file?
After the ID_CONTEXT_HELP button is pressed and I get the pointer with the '?'  I cant get any command message untill after the mouse has been clicked again.  Any other sugestions, or shall I reject the answer to let someone else have a go.
ok
I dont know now other way
Override CWinApp::WinHelp(). Do you processing (i.e. change the help id) and then call base class WinHelp() function (i.e. the original CWinApp version).

i.e.

void CYourApp::WinHelp(DWORD dwData, UINT nCmd)
{  
  if (nCmd==HELP_CONTEXT)
    dwData = <Whatever you want>

  CWinApp::WinHelp(dwData, nCmd);
}
abancroft

When I add the WinHelp Override I get an error on the line

CWinApp::WinHelp(dwData,nCmd);

ganttfrm.cpp(800) : error C2352: 'CWinApp::WinHelpA' : illegal call of non-static member function

Is this a clue as to what I am doing wrong?

In my app if I comment out the line that causes the error then the WinHelp routine never gets called, however in the scribble example I can do exactly the same thing and it works fine.
Paste the declaration & definition for your WinHelp() override.
declaration :

 virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);

definition :

void CSequencerFrame::WinHelp(DWORD dwData, UINT nCmd)
{
  // Beep to let me know its in the routine
  if (nCmd==HELP_CONTEXT)
    MessageBeep(0xFFFFFFFF);

  CWinApp::WinHelp(dwData, nCmd);
}
You have not overridden CWinApp version - you have added a new function to your frame window (I'm assuming CSequencerFrame is derived from CFrameWnd.

You need to overide in your CWinApp derived class.

Ah!  Now I am getting somwhere, but not quite all the way!

I can now get my App to enter the WinHelp routine, but I can't add the CWinApp::WinHelp line to actually get the help! I get the C2352 error described previously.
And is CWinApp a base class of CSequencerFrame?
Oops, no its not!

I have done it correctly now and it all works, answer the question and I'll give you the points.
ASKER CERTIFIED SOLUTION
Avatar of abancroft
abancroft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial