Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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

Hi..

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..

regards
0
BharathiIntel
Asked:
BharathiIntel
2 Solutions
 
AlexFMCommented:
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.
0
 
Roshan DavisCommented:
Map ID_HELP

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
0
 
FrenchFriesCommented:
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
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now