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 2580 - (show annotations) (download) (as text)
Wed Sep 3 05:27:50 2008 UTC (15 years, 9 months ago) by maya
Original Path: teraterm/trunk/keycode/keycode.c
File MIME type: text/x-csrc
File size: 4020 byte(s)
Vista の Aero において Alt+Tab 切り替えで表示されるアイコンが 16x16 アイコンの
拡大になってしまうので、大きいアイコンもセットするようにした。

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

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