现在做的一个程序要响应键盘按键,比如响应F1键,但在Windows里F1又具有查找帮助文件的功能,请问如何屏蔽掉F1的原有功能?

解决方案 »

  1.   

    在PreTranslateMessage(MSG* pMsg) 函数中处理
      

  2.   

    响应ON_COMMAND( ID_HELP, myhelp )
      

  3.   

    window有个处理消息的函数:
    PreTranslateMessage(MSG *pMsg){
     if(pMsg==WM_KEYDOWN){
      ::PreTranslateMessage(*pMsg)
      }
    }
      

  4.   

    响应 ON_COMMAND( ID_HELP, myhelp ) 就不会执行windows的查找帮助了。
      

  5.   

    PreTranslateMessage(MSG *pMsg)

    if(pMsg==WM_KEYDOWN&&pMsg->wParam == VK_F1)

      //在此处理你的操作

    ..................
    }
      

  6.   

    你自己添加PreTranslateMessage消息,再用楼上的方法
      

  7.   


    PreTranslateMessage(MSG* pMsg) 
    {
      if(pMsg->message==WM_KEYDOWN)
    {   
    switch(pMsg->wParam)
    {
    case VK_F1:
    OnRead();//我的处理
    break;
    default:
    break;
    }
    }各位:我的处理方式如上,我的问题是按F1键时,只响应我的处理,而不执行查找帮助文件的功能.请问jennyvenus,响应ON_COMMAND命令是怎么操作的,没这么用过,能不能详细点,或者将我上面的程序改一下,不甚感谢.
      

  8.   

    在.h里面加入afx_msg void ShowHelp( void );别的afx_msg 加在哪,你就加在哪在.cpp的
    END_MESSAGE_MAP()和END_MESSAGE_MAP()之间加入
    ON_COMMAND(ID_HELP, ShowHelp)//效果如下
    END_MESSAGE_MAP()ON_COMMAND(ID_HELP, ShowHelp)END_MESSAGE_MAP()
    最后实现函数体void CTestDlg::ShowHelp() 
    {
    AfxMessageBox( "fdafa" );
    }
      

  9.   

    jennyvenus,你好:
    我按照你的方法做了,依旧会响应windows中F1自带查找帮助文件的功能,并且不响应我自己的消息处理函数.请问是什么原因?
      

  10.   

    我只能贴代码了// makehelpDlg.h : header file
    //#if !defined(AFX_MAKEHELPDLG_H__0D447ACA_5D5F_4BB7_B83C_FE6A2DFBD8C7__INCLUDED_)
    #define AFX_MAKEHELPDLG_H__0D447ACA_5D5F_4BB7_B83C_FE6A2DFBD8C7__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CMakehelpDlg dialogclass CMakehelpDlg : public CDialog
    {
    // Construction
    public:
    CMakehelpDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CMakehelpDlg)
    enum { IDD = IDD_MAKEHELP_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMakehelpDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CMakehelpDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void myhelp( void );
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MAKEHELPDLG_H__0D447ACA_5D5F_4BB7_B83C_FE6A2DFBD8C7__INCLUDED_)
      

  11.   

    // makehelpDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "makehelp.h"
    #include "makehelpDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMakehelpDlg dialogCMakehelpDlg::CMakehelpDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMakehelpDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMakehelpDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CMakehelpDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMakehelpDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }void CMakehelpDlg::myhelp( void )
    {
    AfxMessageBox( "fdsafdas" );
    }BEGIN_MESSAGE_MAP(CMakehelpDlg, CDialog)
    //{{AFX_MSG_MAP(CMakehelpDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_COMMAND( ID_HELP, myhelp )
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMakehelpDlg message handlersBOOL CMakehelpDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CMakehelpDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMakehelpDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }
      

  12.   

    只有少数按键需要特殊处理,其他大部分key都可以在pretranslatemessage中集中处理。
      

  13.   

    PreTranslateMessage(MSG *pMsg) 

    if(pMsg==WM_KEYDOWN&&pMsg->wParam == VK_F1) 

      //在此处理你的操作 

    .................. 

    答案就是这样的,不过在处理完你自己的操作之后,要直接返回,不要继续把消息传递下去
      

  14.   

    谢谢jennyvenus及其他各位兄弟的回复.
    其实在MFC的对话框程序里屏蔽F1键只需将APP类中的语句ON_COMMAND(ID_HELP, CWinApp::OnHelp)屏掉即可.
    望各位能够参考.