龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC程序中定制对话框中的回车键(4)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
/////////////////////////////////////////// // CDlgWithAccelerators is a general-purpose class that adds accelerators to CDialog. #include "stdafx.h" #include "dlgaccel.h" #ifdef _DEBUG #define new DE

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

精彩图集

赞助商链接