Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/teraterm/keycode/keycode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (show annotations) (download) (as text)
Tue Mar 24 15:10:33 2009 UTC (15 years, 1 month ago) by maya
File MIME type: text/x-csrc
File size: 4267 byte(s)
CVS から SVN へ移行: 改行コードを LF から CR+LF へ変換
1 /* Tera Term
2 Copyright(C) 1994-1998 T. Teranishi
3 All rights reserved. */
4
5 /* keycode.exe for Tera Term Pro */
6
7 #include <windows.h>
8 #include <stdio.h>
9 #include <string.h>
10
11 #include "kc_res.h"
12 #define ClassName "KeyCodeWin32"
13
14 #include "compat_w95.h"
15
16 // Prototypes
17 LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
18
19 // Global variables;
20 static HANDLE ghInstance;
21 static BOOL KeyDown = FALSE;
22 static BOOL Short;
23 static WORD Scan;
24
25 int PASCAL WinMain(HINSTANCE hInstance,
26 HINSTANCE hPrevInstance,
27 LPSTR lpszCmdLine,
28 int nCmdShow)
29 {
30 WNDCLASS wc;
31 MSG msg;
32 HWND hWnd;
33
34 // インストーラで実行を検出するために mutex を作成する (2006.8.12 maya)
35 // 2重起動防止のためではないので、特に返り値は見ない
36 HANDLE hMutex;
37 hMutex = CreateMutex(NULL, TRUE, "TeraTermProKeycodeAppMutex");
38
39 DoCover_IsDebuggerPresent();
40
41 if(!hPrevInstance)
42 {
43 wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
44 wc.lpfnWndProc = MainWndProc;
45 wc.cbClsExtra = 0;
46 wc.cbWndExtra = 0;
47 wc.hInstance = hInstance;
48 wc.hIcon = NULL;
49 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
50 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
51 wc.lpszMenuName = NULL;
52 wc.lpszClassName = ClassName;
53 RegisterClass(&wc);
54 }
55
56 ghInstance = hInstance;
57
58 hWnd = CreateWindow(ClassName,
59 "Key code for Tera Term",
60 WS_OVERLAPPEDWINDOW,
61 CW_USEDEFAULT,
62 CW_USEDEFAULT,
63 200,
64 100,
65 NULL,
66 NULL,
67 hInstance,
68 NULL);
69
70 ShowWindow(hWnd, nCmdShow);
71
72 PostMessage(hWnd,WM_SETICON,ICON_SMALL,
73 (LPARAM)LoadImage(hInstance,
74 MAKEINTRESOURCE(IDI_KEYCODE),
75 IMAGE_ICON,16,16,0));
76 PostMessage(hWnd,WM_SETICON,ICON_BIG,
77 (LPARAM)LoadImage(hInstance,
78 MAKEINTRESOURCE(IDI_KEYCODE),
79 IMAGE_ICON,0,0,0));
80
81 while(GetMessage(&msg, NULL, 0, 0)) {
82 TranslateMessage(&msg);
83 DispatchMessage(&msg);
84 }
85
86 return msg.wParam;
87 }
88
89 void KeyDownProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
90 {
91 if ((wParam==VK_SHIFT) ||
92 (wParam==VK_CONTROL) ||
93 (wParam==VK_MENU)) return;
94
95 Scan = HIWORD(lParam) & 0x1ff;
96 if ((GetKeyState(VK_SHIFT) & 0x80) != 0)
97 Scan = Scan | 0x200;
98 if ((GetKeyState(VK_CONTROL) & 0x80) != 0)
99 Scan = Scan | 0x400;
100 if ((GetKeyState(VK_MENU) & 0x80) != 0)
101 Scan = Scan | 0x800;
102
103 if (! KeyDown)
104 {
105 KeyDown = TRUE;
106 Short = TRUE;
107 SetTimer(hWnd,1,10,NULL);
108 InvalidateRect(hWnd,NULL,TRUE);
109 }
110 }
111
112 void KeyUpProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
113 {
114 if (! KeyDown) return;
115 if (Short)
116 SetTimer(hWnd,2,500,NULL);
117 else {
118 KeyDown = FALSE;
119 InvalidateRect(hWnd,NULL,TRUE);
120 }
121 }
122
123 void PaintProc(HWND hWnd)
124 {
125 PAINTSTRUCT ps;
126 HDC hDC;
127 char OutStr[30];
128
129 hDC = BeginPaint(hWnd, &ps);
130
131 if (KeyDown)
132 {
133 _snprintf_s(OutStr,sizeof(OutStr),_TRUNCATE,"Key code is %u.",Scan);
134 TextOut(hDC,10,10,OutStr,strlen(OutStr));
135 }
136 else
137 TextOut(hDC,10,10,"Push any key.",13);
138
139 EndPaint(hWnd, &ps);
140 }
141
142 void TimerProc(HWND hWnd, WPARAM wParam)
143 {
144 KillTimer(hWnd,wParam);
145 if (wParam==1)
146 Short = FALSE;
147 else if (wParam==2)
148 {
149 KeyDown = FALSE;
150 InvalidateRect(hWnd,NULL,TRUE);
151 }
152 }
153
154 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
155 LPARAM lParam)
156 {
157 switch( msg ) {
158 case WM_KEYDOWN:
159 KeyDownProc(hWnd, wParam, lParam);
160 break;
161 case WM_KEYUP:
162 KeyUpProc(hWnd, wParam, lParam);
163 break;
164 case WM_SYSKEYDOWN:
165 if (wParam==VK_F10)
166 KeyDownProc(hWnd, wParam, lParam);
167 else
168 return (DefWindowProc(hWnd, msg, wParam, lParam));
169 break;
170 case WM_SYSKEYUP:
171 if (wParam==VK_F10)
172 KeyUpProc(hWnd, wParam, lParam);
173 else
174 return (DefWindowProc(hWnd, msg, wParam, lParam));
175 break;
176 case WM_PAINT:
177 PaintProc(hWnd);
178 break;
179 case WM_TIMER:
180 TimerProc(hWnd, wParam);
181 break;
182 case WM_DESTROY:
183 PostQuitMessage(0);
184 break;
185 default:
186 return (DefWindowProc(hWnd, msg, wParam, lParam));
187 }
188
189 return 0;
190 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26