Solved

Visual C++ 5.0 Question

Posted on 2000-05-02
11
375 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 174
deburging in oracle form 12 112
Looking for a specific application/software 2 119
windows 10 how make picture as desktop background 2 66
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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