VC程序中定制对话框中的回车键(4)
///////////////////////////////////////////
// CDlgWithAccelerators is a general-purpose class that adds accelerators to CDialog.
#include "stdafx.h"
#include "dlgaccel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CDlgWithAccelerators,CDialog)
END_MESSAGE_MAP()
CDlgWithAccelerators::CDlgWithAccelerators(LPCTSTR lpszTemplateName,
CWnd* pParentWnd) : CDialog(lpszTemplateName, pParentWnd)
{}
CDlgWithAccelerators::CDlgWithAccelerators(UINT nIDTemplate,
CWnd* pParentWnd) : CDialog(nIDTemplate, pParentWnd)
{}
CDlgWithAccelerators::~CDlgWithAccelerators()
{}
/////////////////////////// Pre-translate message: translate keystrokes using acclerator table.
BOOL CDlgWithAccelerators::PreTranslateMessage(MSG* pMsg)
{
if (WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST) {
HACCEL hAccel = m_hAccel;
if (hAccel && ::TranslateAccelerator(m_hWnd, hAccel, pMsg))
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
//////////////////// Initialize dialog: load accelerators
BOOL CDlgWithAccelerators::OnInitDialog()
{
BOOL bRet = CDialog::OnInitDialog();
// Load dialog's accelerators
m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(),
m_lpszTemplateName); // use same resource name as dialog
return bRet;
}
/////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "dlgaccel.h"
#include "TraceWin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////MFC app
class CMyApp : public CWinApp {
public:
CMyApp();
~CMyApp();
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
CMyApp theApp; // THE one-and-only app
- 上一篇:VC通过HTTP方式获取网页
- 下一篇:VC++实现Windows回收站的文件存取