Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual C++ 5.0 Question

Posted on 2000-05-02
11
Medium Priority
?
385 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
Industry Leaders: 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 8000 total points
ID: 2783121
The answer is above.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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