-
Notifications
You must be signed in to change notification settings - Fork 0
/
h2o_console_draw.cpp
189 lines (157 loc) · 3.64 KB
/
h2o_console_draw.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <windows.h>
#include <cstdio>
UINT_PTR timer;
void prnt(const char* t);
void pc(char c);
void pi(long long int i);
char getch();
void tproc(HWND p1, UINT p2, UINT_PTR p3, DWORD p4);
DWORD WINAPI input_thread(LPVOID lp);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HANDLE thread = CreateThread(NULL, 0, input_thread, NULL, 0, NULL);
/* HANDLE chand = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO inf;
inf.dwSize = 100;
inf.bVisible = FALSE;
SetConsoleCursorInfo(chand, &inf); */
HWND wnd = GetConsoleWindow();
prnt("HWND: ");
pi((long long int)wnd);
prnt("\n");
char c = getch();
pc(c);
FLASHWINFO flash;
flash.cbSize = sizeof(FLASHWINFO);
flash.hwnd = wnd;
flash.dwFlags = FLASHW_TRAY | FLASHW_TIMER;
//flash.dwFlags = FLASHW_TRAY | FLASHW_TIMER | 1; // Flash ALL
flash.uCount = 0;
flash.dwTimeout = 500;
FlashWindowEx(&flash);
c = getch();
pc(c);
flash.dwFlags = 0;
FlashWindowEx(&flash);
timer = SetTimer(NULL, NULL, 1000, tproc);
c = getch();
pc(c);
MSG msg;
int count = 0;
while(GetMessage(&msg, NULL, 0, 0))
{
/* ++count;
if(msg.message == WM_TIMER)
{
prnt("TIMERMSG!!!");
}
char txt[100];
sprintf(txt, "c:%d msg:%d\n", (long long int)count, msg.message);
prnt(txt);*/
HANDLE chand = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO inf;
inf.dwSize = 100;
inf.bVisible = FALSE;
SetConsoleCursorInfo(chand, &inf);
DispatchMessage(&msg);
}
/* while(1)
{
FlashWindow(wnd, 1);
Sleep(500);
FlashWindow(wnd, 1);
Sleep(500);
} */
KillTimer(NULL, timer);
return 0;
}
void prnt(const char* t)
{
long unsigned int wrt = 0;
HANDLE stdo = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(stdo, t, strlen(t), &wrt, NULL);
}
void pc(char c)
{
long unsigned int wrt = 0;
HANDLE stdo = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(stdo, &c, 1, &wrt, NULL);
}
void pi(long long int i)
{
char txt[100];
sprintf(txt, "%d", i);
prnt(txt);
}
char getch()
{
DWORD mode, cc;
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode( h, &mode );
SetConsoleMode( h, mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
char c = 0;
ReadConsole( h, &c, 1, &cc, NULL );
SetConsoleMode( h, mode );
//pi(mode);
return c;
}
void tproc(HWND p1, UINT p2, UINT_PTR p3, DWORD p4)
{
SetTimer(NULL, timer, 1000, tproc);
static char min, sec;
++sec;
if(sec >= 60)
{
sec = 0;
++min;
}
char t[6];
sprintf(t, "%02d:%02d", min, sec);
COORD xy;
xy.X = 0;
xy.Y = 1;
HANDLE oh = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(oh, xy);
prnt(t);
//SetConsoleCursorPosition(oh, xy);
}
DWORD WINAPI input_thread(LPVOID lp)
{
DWORD mode, cc;
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
HANDLE oh = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode( h, &mode );
SetConsoleMode( h, ENABLE_EXTENDED_FLAGS | ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT);
char c = 0;
INPUT_RECORD ir[128];
DWORD nread;
while(1)
{
//ReadConsole( h, &c, 1, &cc, NULL );
//prnt("IT FUKIN WORKZ*******");
ReadConsoleInput(h, ir, 128, &nread);
for(int i = 0; i < nread; ++i)
{
if(ir[i].EventType == MOUSE_EVENT)
{
const MOUSE_EVENT_RECORD* m = &ir[i].Event.MouseEvent;
if(m->dwButtonState == 0x1)
{
//prnt("PRESSSEEEEEED______LMB");
SetConsoleCursorPosition(oh, m->dwMousePosition);
//pc('#');
pc((unsigned char)219);
}
else if(m->dwButtonState == 0x2)
{
SetConsoleCursorPosition(oh, m->dwMousePosition);
pc(' ');
//prnt("PRESSSEEEEEED______RMB");
}
}
}
}
}