现在做的一个程序要响应键盘按键,比如响应F1键,但在Windows里F1又具有查找帮助文件的功能,请问如何屏蔽掉F1的原有功能?
解决方案 »
- *************VC中我有一个全局线程函数,用于网络监听,有新用户连接时,将新用户信息显示在TreeView上,如何在线程函数中访问TreeView
- 求购二手书 ——《windows编程》!
- vc里资源如何与具体的类关联起来的?多谢!
- 如何获得毫秒级的时间?
- 一个服务怎么向另外的窗口发送消息?(急……)
- 如何确定某点在某不规则区域中。
- 请问英文音标的字符如何获得?谢谢!(第一次提问请关照)
- 哪里有ODBC API编程的资料可以参考?除了MSDN
- 有关CFtpFileFind的奇怪问题!
- 关于directx的问题,定给分,只是系统让小弟最多只能给27分:))
- 有关TAB键转移焦点问题
- 如何用定时器完成屏幕背景颜色的切换呢?
PreTranslateMessage(MSG *pMsg){
if(pMsg==WM_KEYDOWN){
::PreTranslateMessage(*pMsg)
}
}
{
if(pMsg==WM_KEYDOWN&&pMsg->wParam == VK_F1)
{
//在此处理你的操作
}
..................
}
PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
switch(pMsg->wParam)
{
case VK_F1:
OnRead();//我的处理
break;
default:
break;
}
}各位:我的处理方式如上,我的问题是按F1键时,只响应我的处理,而不执行查找帮助文件的功能.请问jennyvenus,响应ON_COMMAND命令是怎么操作的,没这么用过,能不能详细点,或者将我上面的程序改一下,不甚感谢.
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" );
}
我按照你的方法做了,依旧会响应windows中F1自带查找帮助文件的功能,并且不响应我自己的消息处理函数.请问是什么原因?
//#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_)
//#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;
}
{
if(pMsg==WM_KEYDOWN&&pMsg->wParam == VK_F1)
{
//在此处理你的操作
}
..................
}
答案就是这样的,不过在处理完你自己的操作之后,要直接返回,不要继续把消息传递下去
其实在MFC的对话框程序里屏蔽F1键只需将APP类中的语句ON_COMMAND(ID_HELP, CWinApp::OnHelp)屏掉即可.
望各位能够参考.