CDialog程序响应键盘消息
KeyMsgDlg.cpp
1
// KeyMsgDlg.cpp : 实现文件
2
//
3![](/Images/OutliningIndicators/None.gif)
4
#include "stdafx.h"
5
#include "KeyMsg.h"
6
#include "KeyMsgDlg.h"
7![](/Images/OutliningIndicators/None.gif)
8
#ifdef _DEBUG
9
#define new DEBUG_NEW
10
#endif
11![](/Images/OutliningIndicators/None.gif)
12![](/Images/OutliningIndicators/None.gif)
13
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
14![](/Images/OutliningIndicators/None.gif)
15
class CAboutDlg : public CDialog
16
{
17
public:
18
CAboutDlg();
19![](/Images/OutliningIndicators/InBlock.gif)
20
// 对话框数据
21
enum { IDD = IDD_ABOUTBOX };
22![](/Images/OutliningIndicators/InBlock.gif)
23
protected:
24
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
25![](/Images/OutliningIndicators/InBlock.gif)
26
// 实现
27
protected:
28
DECLARE_MESSAGE_MAP()
29
};
30![](/Images/OutliningIndicators/None.gif)
31
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
32
{
33
}
34![](/Images/OutliningIndicators/None.gif)
35
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
36
{
37
CDialog::DoDataExchange(pDX);
38
}
39![](/Images/OutliningIndicators/None.gif)
40
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
41
END_MESSAGE_MAP()
42![](/Images/OutliningIndicators/None.gif)
43![](/Images/OutliningIndicators/None.gif)
44
// CKeyMsgDlg 对话框
45![](/Images/OutliningIndicators/None.gif)
46![](/Images/OutliningIndicators/None.gif)
47![](/Images/OutliningIndicators/None.gif)
48![](/Images/OutliningIndicators/None.gif)
49
CKeyMsgDlg::CKeyMsgDlg(CWnd* pParent /*=NULL*/)
50
: CDialog(CKeyMsgDlg::IDD, pParent)
51
{
52
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
53
}
54![](/Images/OutliningIndicators/None.gif)
55
void CKeyMsgDlg::DoDataExchange(CDataExchange* pDX)
56
{
57
CDialog::DoDataExchange(pDX);
58
}
59![](/Images/OutliningIndicators/None.gif)
60
BEGIN_MESSAGE_MAP(CKeyMsgDlg, CDialog)
61
ON_WM_SYSCOMMAND()
62
ON_WM_PAINT()
63
ON_WM_QUERYDRAGICON()
64
//}}AFX_MSG_MAP
65
END_MESSAGE_MAP()
66![](/Images/OutliningIndicators/None.gif)
67![](/Images/OutliningIndicators/None.gif)
68
// CKeyMsgDlg 消息处理程序
69![](/Images/OutliningIndicators/None.gif)
70
BOOL CKeyMsgDlg::OnInitDialog()
71
{
72
CDialog::OnInitDialog();
73![](/Images/OutliningIndicators/InBlock.gif)
74
// 将“关于
”菜单项添加到系统菜单中。
75![](/Images/OutliningIndicators/InBlock.gif)
76
// IDM_ABOUTBOX 必须在系统命令范围内。
77
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
78
ASSERT(IDM_ABOUTBOX < 0xF000);
79![](/Images/OutliningIndicators/InBlock.gif)
80
CMenu* pSysMenu = GetSystemMenu(FALSE);
81
if (pSysMenu != NULL)
82
{
83
CString strAboutMenu;
84
strAboutMenu.LoadString(IDS_ABOUTBOX);
85
if (!strAboutMenu.IsEmpty())
86
{
87
pSysMenu->AppendMenu(MF_SEPARATOR);
88
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
89
}
90
}
91![](/Images/OutliningIndicators/InBlock.gif)
92
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
93
// 执行此操作
94
SetIcon(m_hIcon, TRUE); // 设置大图标
95
SetIcon(m_hIcon, FALSE); // 设置小图标
96![](/Images/OutliningIndicators/InBlock.gif)
97
// TODO: 在此添加额外的初始化代码
98![](/Images/OutliningIndicators/InBlock.gif)
99
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
100
}
101![](/Images/OutliningIndicators/None.gif)
102
void CKeyMsgDlg::OnSysCommand(UINT nID, LPARAM lParam)
103
{
104
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
105
{
106
CAboutDlg dlgAbout;
107
dlgAbout.DoModal();
108
}
109
else
110
{
111
CDialog::OnSysCommand(nID, lParam);
112
}
113
}
114![](/Images/OutliningIndicators/None.gif)
115
// 如果向对话框添加最小化按钮,则需要下面的代码
116
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
117
// 这将由框架自动完成。
118![](/Images/OutliningIndicators/None.gif)
119
void CKeyMsgDlg::OnPaint()
120
{
121
if (IsIconic())
122
{
123
CPaintDC dc(this); // 用于绘制的设备上下文
124![](/Images/OutliningIndicators/InBlock.gif)
125
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
126![](/Images/OutliningIndicators/InBlock.gif)
127
// 使图标在工作矩形中居中
128
int cxIcon = GetSystemMetrics(SM_CXICON);
129
int cyIcon = GetSystemMetrics(SM_CYICON);
130
CRect rect;
131
GetClientRect(&rect);
132
int x = (rect.Width() - cxIcon + 1) / 2;
133
int y = (rect.Height() - cyIcon + 1) / 2;
134![](/Images/OutliningIndicators/InBlock.gif)
135
// 绘制图标
136
dc.DrawIcon(x, y, m_hIcon);
137
}
138
else
139
{
140
CDialog::OnPaint();
141
}
142
}
143![](/Images/OutliningIndicators/None.gif)
144
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
145
//
146
HCURSOR CKeyMsgDlg::OnQueryDragIcon()
147
{
148
return static_cast<HCURSOR>(m_hIcon);
149
}
150
BOOL CKeyMsgDlg::PreTranslateMessage(MSG *pMsg)
151
{
152
if(pMsg->message==WM_KEYDOWN)
153
{
154
switch(pMsg->wParam)
155
{
156
case VK_DOWN:
157
::AfxMessageBox(_T("VK_SHIFT"));//CTRL 按键按下
158
return TRUE;
159
case 'M':
160
if(::GetKeyState(VK_SHIFT)<0)
161
{
162
::AfxMessageBox(_T("VK_SHIFT+M"));//SHIFT+M 按键被按下
163
}
164
return TRUE;
165
}
166
}
167
return CDialog::PreTranslateMessage(pMsg);
168
}
169![](/Images/OutliningIndicators/None.gif)
170![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
30
![](/Images/OutliningIndicators/None.gif)
31
![](/Images/OutliningIndicators/None.gif)
32
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
33
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
34
![](/Images/OutliningIndicators/None.gif)
35
![](/Images/OutliningIndicators/None.gif)
36
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
39
![](/Images/OutliningIndicators/None.gif)
40
![](/Images/OutliningIndicators/None.gif)
41
![](/Images/OutliningIndicators/None.gif)
42
![](/Images/OutliningIndicators/None.gif)
43
![](/Images/OutliningIndicators/None.gif)
44
![](/Images/OutliningIndicators/None.gif)
45
![](/Images/OutliningIndicators/None.gif)
46
![](/Images/OutliningIndicators/None.gif)
47
![](/Images/OutliningIndicators/None.gif)
48
![](/Images/OutliningIndicators/None.gif)
49
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
50
![](/Images/OutliningIndicators/None.gif)
51
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
54
![](/Images/OutliningIndicators/None.gif)
55
![](/Images/OutliningIndicators/None.gif)
56
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
59
![](/Images/OutliningIndicators/None.gif)
60
![](/Images/OutliningIndicators/None.gif)
61
![](/Images/OutliningIndicators/None.gif)
62
![](/Images/OutliningIndicators/None.gif)
63
![](/Images/OutliningIndicators/None.gif)
64
![](/Images/OutliningIndicators/None.gif)
65
![](/Images/OutliningIndicators/None.gif)
66
![](/Images/OutliningIndicators/None.gif)
67
![](/Images/OutliningIndicators/None.gif)
68
![](/Images/OutliningIndicators/None.gif)
69
![](/Images/OutliningIndicators/None.gif)
70
![](/Images/OutliningIndicators/None.gif)
71
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/InBlock.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/InBlock.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/InBlock.gif)
82
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
83
![](/Images/OutliningIndicators/InBlock.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/InBlock.gif)
86
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/InBlock.gif)
89
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
90
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/InBlock.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/InBlock.gif)
95
![](/Images/OutliningIndicators/InBlock.gif)
96
![](/Images/OutliningIndicators/InBlock.gif)
97
![](/Images/OutliningIndicators/InBlock.gif)
98
![](/Images/OutliningIndicators/InBlock.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
101
![](/Images/OutliningIndicators/None.gif)
102
![](/Images/OutliningIndicators/None.gif)
103
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/InBlock.gif)
108
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
109
![](/Images/OutliningIndicators/InBlock.gif)
110
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
113
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
114
![](/Images/OutliningIndicators/None.gif)
115
![](/Images/OutliningIndicators/None.gif)
116
![](/Images/OutliningIndicators/None.gif)
117
![](/Images/OutliningIndicators/None.gif)
118
![](/Images/OutliningIndicators/None.gif)
119
![](/Images/OutliningIndicators/None.gif)
120
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
121
![](/Images/OutliningIndicators/InBlock.gif)
122
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
123
![](/Images/OutliningIndicators/InBlock.gif)
124
![](/Images/OutliningIndicators/InBlock.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/InBlock.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/InBlock.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/InBlock.gif)
133
![](/Images/OutliningIndicators/InBlock.gif)
134
![](/Images/OutliningIndicators/InBlock.gif)
135
![](/Images/OutliningIndicators/InBlock.gif)
136
![](/Images/OutliningIndicators/InBlock.gif)
137
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
138
![](/Images/OutliningIndicators/InBlock.gif)
139
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
140
![](/Images/OutliningIndicators/InBlock.gif)
141
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
142
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
143
![](/Images/OutliningIndicators/None.gif)
144
![](/Images/OutliningIndicators/None.gif)
145
![](/Images/OutliningIndicators/None.gif)
146
![](/Images/OutliningIndicators/None.gif)
147
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
148
![](/Images/OutliningIndicators/InBlock.gif)
149
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
150
![](/Images/OutliningIndicators/None.gif)
151
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
152
![](/Images/OutliningIndicators/InBlock.gif)
153
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/InBlock.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/InBlock.gif)
161
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
162
![](/Images/OutliningIndicators/InBlock.gif)
163
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
164
![](/Images/OutliningIndicators/InBlock.gif)
165
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
166
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
169
![](/Images/OutliningIndicators/None.gif)
170
![](/Images/OutliningIndicators/None.gif)