Solved

Visual C++ 5.0 Question

Posted on 2000-05-02
11
344 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now