📄 myhotkeyview.cpp
字号:
// MyHotKeyView.cpp : implementation of the CMyHotKeyView class
//
#include "stdafx.h"
#include "MyHotKey.h"
#include "MyHotKeyDoc.h"
#include "MyHotKeyView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyHotKeyView
IMPLEMENT_DYNCREATE(CMyHotKeyView, CView)
BEGIN_MESSAGE_MAP(CMyHotKeyView, CView)
//{{AFX_MSG_MAP(CMyHotKeyView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_MESSAGE(WM_HOTKEY,OnHotKey)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyHotKeyView construction/destruction
CMyHotKeyView::CMyHotKeyView()
{
// TODO: add construction code here
}
CMyHotKeyView::~CMyHotKeyView()
{
//释放全局原子
GlobalDeleteAtom(m_atomId);
}
BOOL CMyHotKeyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyHotKeyView drawing
void CMyHotKeyView::OnDraw(CDC* pDC)
{
CMyHotKeyDoc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//在用户工作区显示提示信息
//m_bRegister标识热键注册成功与否
if(m_bRegister == FALSE)
pDC->TextOut(0, 0, "系统热键注册失败,请退出程序。");
else
{
pDC->TextOut(0, 0, "系统热键 Alt + Z 注册成功。");
pDC->TextOut(0, 20, "该热键调出一个消息对话框。");
pDC->TextOut(0, 40, "请按此热键进行演示。");
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyHotKeyView diagnostics
#ifdef _DEBUG
void CMyHotKeyView::AssertValid() const
{
CView::AssertValid();
}
void CMyHotKeyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyHotKeyDoc* CMyHotKeyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyHotKeyDoc)));
return (CMyHotKeyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyHotKeyView message handlers
void CMyHotKeyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
//向操作系统添加一个全局原子Atom m_atomId,
m_atomId = GlobalAddAtom("myHotKey");
//设定ALT+Z为热键,尽量使用比较生疏的键。
if(!RegisterHotKey(m_hWnd, m_atomId, MOD_ALT, 'Z'))
m_bRegister = FALSE;
else
m_bRegister = TRUE;
}
//处理自定义系统热键消息的函数
void CMyHotKeyView::OnHotKey(WPARAM wParam, LPARAM lParam)
{
if(m_atomId == wParam)MessageBox("系统热键 Alt+Z 被激活", "响应系统热键", MB_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -