How do i override a F1 functionality for control in a dialog.

Posted on 2003-03-18
Medium Priority
Last Modified: 2013-11-20

I have a dialog based application with many controls like edit box, list box, combo box etc..
i want to give a diffrent message for pressing F1 on each of these controls which are all dervied form CWND. how do i do this..

Question by:BharathiIntel
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
LVL 48

Accepted Solution

AlexFM earned 500 total points
ID: 8157789
This code gives different TRACE messages when F1 is pressed on two edit boxes:

BOOL CSampleDlg::PreTranslateMessage(MSG* pMsg)
    if ( pMsg->message == WM_KEYDOWN  &&  pMsg->wParam == VK_F1 )
        if ( pMsg->hwnd == GetDlgItem(IDC_EDIT1)->m_hWnd )
            TRACE(_T("F1 on IDC_EDIT1\n"));
            return TRUE;
        if ( pMsg->hwnd == GetDlgItem(IDC_EDIT2)->m_hWnd )
            TRACE(_T("F1 on IDC_EDIT2\n"));
            return TRUE;


    return CDialog::PreTranslateMessage(pMsg);

You can continue from this point adding your functionality.
LVL 23

Assisted Solution

by:Roshan Davis
Roshan Davis earned 500 total points
ID: 8158468

The F1 key is usually translated to a command with an ID of ID_HELP by an accelerator placed into the main window's accelerator table. The ID_HELP command may also be generated by a button with an ID of ID_HELP on the main window or dialog box. Also, when a menu or a dialog box is active and the user presses F1, the keystroke is hard-coded to translate into an ID_HELP command.

Good Luck

Expert Comment

ID: 8159156
AlexFM and roshmon gave you the best solutions for F1 key usage but you can also override WinHelp :
go in ClassWizard if you are using VC++ 6.0 and declare a new WinHelp method

Featured Post

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!

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. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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

764 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