-
Notifications
You must be signed in to change notification settings - Fork 14
/
SetHotkey.c
115 lines (101 loc) · 2.43 KB
/
SetHotkey.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* CLCL
*
* SetHotkey.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include <commctrl.h>
#include "General.h"
#include "Data.h"
#include "resource.h"
/* Define */
/* Global Variables */
/* Local Function Prototypes */
static BOOL CALLBACK set_hotkey_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
/*
* set_hotkey_proc - ホットキー設定ウィンドウプロシージャ
*/
static BOOL CALLBACK set_hotkey_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DATA_INFO *di;
int i;
switch (uMsg) {
case WM_INITDIALOG:
if ((di = (DATA_INFO *)lParam) == NULL) {
EndDialog(hDlg, FALSE);
break;
}
// ホットキー
i = 0;
if (di->op_modifiers & MOD_SHIFT) {
i |= HOTKEYF_SHIFT;
}
if (di->op_modifiers & MOD_CONTROL) {
i |= HOTKEYF_CONTROL;
}
if (di->op_modifiers & MOD_ALT) {
i |= HOTKEYF_ALT;
}
if (di->op_modifiers & MOD_WIN) {
CheckDlgButton(hDlg, IDC_CHECK_WIN, 1);
}
if (di->op_virtkey != 0) {
SendDlgItemMessage(hDlg, IDC_HOTKEY_ITEM, HKM_SETHOTKEY,
(WPARAM)MAKEWORD(di->op_virtkey, i), 0);
// 貼り付け
CheckDlgButton(hDlg, IDC_CHECK_PASTE, di->op_paste);
} else {
CheckDlgButton(hDlg, IDC_CHECK_PASTE, 1);
}
SetWindowLong(hDlg, GWL_USERDATA, lParam);
break;
case WM_CLOSE:
EndDialog(hDlg, FALSE);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
SendMessage(hDlg, WM_CLOSE, 0, 0);
break;
case IDOK:
di = (DATA_INFO *)GetWindowLong(hDlg, GWL_USERDATA);
if (di == NULL) {
EndDialog(hDlg, FALSE);
break;
}
// ホットキー
i = SendDlgItemMessage(hDlg, IDC_HOTKEY_ITEM, HKM_GETHOTKEY, 0, 0);
di->op_virtkey = LOBYTE(i);
i = HIBYTE(i);
di->op_modifiers = ((i & HOTKEYF_SHIFT) ? MOD_SHIFT : 0) |
((i & HOTKEYF_CONTROL) ? MOD_CONTROL : 0) |
((i & HOTKEYF_ALT) ? MOD_ALT : 0);
if (IsDlgButtonChecked(hDlg, IDC_CHECK_WIN) == 1) {
di->op_modifiers |= MOD_WIN;
}
// 貼り付け
di->op_paste = IsDlgButtonChecked(hDlg, IDC_CHECK_PASTE);
EndDialog(hDlg, TRUE);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
/*
* set_hotkey - ホットキー設定
*/
BOOL set_hotkey(const HINSTANCE hInst, const HWND hWnd, DATA_INFO *di)
{
return DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_SET_HOTKEY), hWnd, set_hotkey_proc, (LPARAM)di);
}
/* End of source */