Solved

Visual C++ 5.0 Question

Posted on 2000-05-02
11
365 Views
Last Modified: 2013-11-20
Why does a simple app created with the app wizard contain the code;
CFrameWnd::OnHelp, I thought you should always use CWinApp::OnHelp

Please give me a detailed answer.  Is there something in the macros that allow it to do this?

Thank you.
0
Comment
Question by:jackyhead
  • 5
  • 3
  • 2
  • +1
11 Comments
 

Author Comment

by:jackyhead
ID: 2771330
Don't lock this question until I say so, in order to generate the most feedback on this question from all experts.
0
 

Author Comment

by:jackyhead
ID: 2771585
Adjusted points from 1000 to 2000
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2772099
In short, that doesn't matter, if the main window of your app is derived from the CFrameWnd.

You'll get the same result whether you call CWinApp::OnHelp() or CFrameWnd::OnHelp().

void CWinApp::OnHelp()
{
   if (m_dwPromptContext != 0)
   {
      // do not call WinHelp when the error is failing to lauch help
      if (m_dwPromptContext != HID_BASE_PROMPT+AFX_IDP_FAILED_TO_LAUNCH_HELP)
         WinHelp(m_dwPromptContext);
      return;
   }

   // otherwise, use CWnd::OnHelp implementation
   CWnd* pWnd = AfxGetMainWnd();
   ASSERT_VALID(pWnd);
   if (!pWnd->IsFrameWnd())
      pWnd->OnHelp();
   else
      ((CFrameWnd*)pWnd)->OnHelp();
}
      
-------------

void CFrameWnd::OnHelp()
{
   // Be careful not call WinHelp when the error is failing to lauch help
   if (m_dwPromptContext != 0)
   {
      if (m_dwPromptContext != HID_BASE_PROMPT+AFX_IDP_FAILED_TO_LAUNCH_HELP)
         AfxGetApp()->WinHelp(m_dwPromptContext);
      return;
   }
   CWnd::OnHelp();
}
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 15

Expert Comment

by:NickRepin
ID: 2772105
You can see, in both cases will be called either

WinHelp(m_dwPromptContext), if m_dwPromptContext!=0

or

CWnd::OnHelp.

I hope there is nothing to add to my answer.
     
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2772119
When an ID_HELP command is sent to a window, this follows the usual command routing until it get to the frame (if any) or the application.

If the app gets the message, it will (usually, see below) pass the work on to the frame or dialog etc that is the application's main window.

The real work of finding the correct context for the help (ID_HELP command) is handled by CWnd::OnHelp, this looks at the captured window (and its parents), the window with the focus (and its parents) and the active window (and its parents) until one of them knows how to handle WM_COMMANDHELP to display the help.  All frames and dialogs know how to handle WM_COMMANDHELP - by default the simply call the application's WinHelp to display the appropriate help.

There is a slight complication when you use message boxes (AfxMessageBox etc).

You can specify a particular help context for a message box.  When you do so, whatever frame window that owns the message box (if any) remembers a help context id, otherwise the application remembers the id.  When the frame (or application) handles the OnHelp, it first checks for this context, and if there is one it displays the appropriate help using WinHelp.

NOTE: VC 6 stuffed things up anyway .. see the MS KB article for a workaround to get context help OK for message boxes

BUG: AfxMessageBox Help Fails to Bring Up Proper Topic
ID: Q229964

I think that should cover it.

Can I provide an ANSWER () now ???

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2772126
In your case, ID_HELP handler is defined inside CMainFrame class:

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
....
ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
....

Because CMainFrame is derived from the CFrameWnd, it is slightly easier to call CFrameWnd::OnHelp, instead of    AfxGetApp()->OnHelp().
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2772130
nick -- you got in while I was typing.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2772226
Such is life...
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2773482
Listening
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2775628
What else do you want to know?

I think I've explained it pretty well, or is thre some more detail you want, or more general info, or what?

BTW: The answer to you question is .. you should have handlers at BOTH the application and the frame window level (just as the wizard writes for you).

If you want to change behaviour of the help, respond to the WM_COMMANDHELP message or override WinHelp for you application
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 2000 total points
ID: 2783121
The answer is above.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question