• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

修訂8f8c68742df8c5cca1c294b72282c9a84b5efd2a (tree)
時間2017-04-04 12:03:01
作者渡邉 喜光 <tccwas@gmai...>
Commiter渡邉 喜光

Log Message

keydown

Change Summary

差異

--- a/CPP/ITP1_11/con.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
1-#include <iostream>
2-using namespace std;
3-
4-class cls{
5-public:
6- cls();
7- cls(const cls &c);
8-};
9-
10-cls::cls(){
11- cout << "cls::cls\n";
12-}
13-cls::cls(const cls &c){
14- cout << "cls::cls(cls c)\n";
15-}
16-
17-int main(int argc, char *argv[]){
18- cls c1;
19- cls c2 = c1;
20- return 0;
21-}
--- a/HelloWord/HelloWord/winmain.cpp
+++ b/HelloWord/HelloWord/winmain.cpp
@@ -16,6 +16,7 @@ char ch;
1616 HDC hdc;
1717 RECT rect;
1818 PAINTSTRUCT ps;
19+bool vkKeys[256];
1920
2021 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
2122 {
@@ -87,9 +88,20 @@ bool CreateMainWindow(HINSTANCE hInstance, int nCmdShow)
8788
8889 LRESULT WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
8990 {
90-
91+ short nVirtualKey;
92+ const short SHIFTED = (short)0x8000;
93+ TEXTMETRIC tm;
94+ DWORD chWidth = 20;
95+ DWORD chHeight = 20;
9196
9297 switch (msg) {
98+ case WM_CREATE:
99+ hdc = GetDC(hWnd);
100+ GetTextMetrics(hdc, &tm);
101+ ReleaseDC(hWnd, hdc);
102+ chWidth = tm.tmAveCharWidth;
103+ chHeight = tm.tmHeight;
104+ return 0;
93105 case WM_DESTROY:
94106 PostQuitMessage(0);
95107 return 0;
@@ -109,10 +121,76 @@ LRESULT WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
109121 }
110122 case WM_PAINT:
111123 hdc = BeginPaint(hWnd, &ps);
112- GetClientRect(hWnd, &rect);
113- TextOut(hdc, rect.right / 2, rect.bottom / 2, &ch, 1);
124+ TextOut(hdc, 0, 0, &ch, 1);
125+ for (int r = 0; r < 16; r++) {
126+ for (int c = 0; c < 16; c++)
127+ {
128+ if (vkKeys[r * 16 + c]) {
129+ SetBkMode(hdc, OPAQUE);
130+ TextOut(hdc, c * chWidth + chWidth * 2, r* chHeight + chHeight * 2, "T ", 2);
131+ }
132+ else {
133+ SetBkMode(hdc, TRANSPARENT);
134+ TextOut(hdc, c * chWidth + chWidth * 2, r* chHeight + chHeight * 2, "F ", 2);
135+ }
136+ }
137+ }
114138 EndPaint(hWnd, &ps);
115139 return 0;
140+ case WM_KEYDOWN:
141+ vkKeys[wParam] = true;
142+ switch (wParam)
143+ {
144+ case VK_SHIFT:
145+ nVirtualKey = GetKeyState(VK_LSHIFT);
146+ if (nVirtualKey & SHIFTED) {
147+ vkKeys[VK_LSHIFT] = true;
148+ }
149+ nVirtualKey = GetKeyState(VK_RSHIFT);
150+ if (nVirtualKey & SHIFTED) {
151+ vkKeys[VK_RSHIFT] = true;
152+ }
153+ break;
154+ case VK_CONTROL:
155+ nVirtualKey = GetKeyState(VK_LCONTROL);
156+ if (nVirtualKey & SHIFTED) {
157+ vkKeys[VK_LCONTROL] = true;
158+ }
159+ nVirtualKey = GetKeyState(VK_RCONTROL);
160+ if (nVirtualKey & SHIFTED) {
161+ vkKeys[VK_RCONTROL] = true;
162+ }
163+ break;
164+ }
165+ InvalidateRect(hWnd, NULL, TRUE);
166+ return 0;
167+ case WM_KEYUP:
168+ vkKeys[wParam] = false;
169+ switch (wParam)
170+ {
171+ case VK_SHIFT:
172+ nVirtualKey = GetKeyState(VK_LSHIFT);
173+ if ((nVirtualKey & SHIFTED) == 0) {
174+ vkKeys[VK_LSHIFT] = false;
175+ }
176+ nVirtualKey = GetKeyState(VK_RSHIFT);
177+ if ((nVirtualKey & SHIFTED) == 0) {
178+ vkKeys[VK_RSHIFT] = false;
179+ }
180+ break;
181+ case VK_CONTROL:
182+ nVirtualKey = GetKeyState(VK_LCONTROL);
183+ if ((nVirtualKey & SHIFTED) == 0) {
184+ vkKeys[VK_LCONTROL] = false;
185+ }
186+ nVirtualKey = GetKeyState(VK_RCONTROL);
187+ if ((nVirtualKey & SHIFTED) == 0) {
188+ vkKeys[VK_RCONTROL] = false;
189+ }
190+ break;
191+ }
192+ InvalidateRect(hWnd, NULL, TRUE);
193+ return 0;
116194
117195 }
118196 return DefWindowProc(hWnd, msg, wParam, lParam);