?
Solved

Visual C++ 5.0 Question

Posted on 2000-05-02
11
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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 8000 total points
ID: 2783121
The answer is above.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

777 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