-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTabTimers.c
More file actions
187 lines (164 loc) · 4.93 KB
/
TabTimers.c
File metadata and controls
187 lines (164 loc) · 4.93 KB
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
#include "TabTimers.h"
static HFONT hFont;
static HWND hWndTimersDataGrid;
static short * T_timer_old;
static short * T_set;
static short * T_cur;
static short * T_orig;
DWORD WINAPI AddRemainingTimers(int rtm)
{
char temp[3][32];
int i;
Sleep(250);
for (int tm = rtm; tm < TM_MAX; ++tm)
{
strcpy_s(temp[0], 32, T_code[tm]);
sprintf_s(temp[1], 32, "%d", T_max[tm]);
sprintf_s(temp[2], 32, "%d", T_timer[tm]);
DataGridView_AddRow(hWndTimersDataGrid, (LPSTR)temp, 3);
}
return 0;
}
LRESULT CALLBACK WindowProcTabTimers(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect, irect;
char temp[3][32];
int i, row, col;
switch (uMsg)
{
case WM_CREATE:
GetClientRect(hWnd, &rect);
hWndTimersDataGrid = CreateWindowEx((DWORD)NULL, "DGridVwClass",
"Timers",
WS_CHILD, rect.left, rect.top, rect.right - rect.left - 6, rect.bottom - 6, hWnd, NULL, hMainInstance, tabTM_ischanged);
DataGridView_AddColumn(hWndTimersDataGrid, 1, 150, (LPSTR)"Timers");
DataGridView_AddColumn(hWndTimersDataGrid, 2, 75, (LPSTR)"Instelling");
DataGridView_AddColumn(hWndTimersDataGrid, 3, 75, (LPSTR)"Actueel");
T_timer_old = malloc(sizeof(short) * TM_MAX);
T_set = malloc(sizeof(short) * TM_MAX);
T_cur = malloc(sizeof(short) * TM_MAX);
T_orig = malloc(sizeof(short) * TM_MAX);
int tm = 0;
for (tm = 0; tm < TM_MAX; ++tm)
{
T_set[tm] = 0;
T_cur[tm] = T_orig[tm] = T_max[tm];
}
for (tm = 0; tm < TM_MAX; ++tm)
{
strcpy_s(temp[0], 32, T_code[tm]);
sprintf_s(temp[1], 32, "%d", T_max[tm]);
sprintf_s(temp[2], 32, "%d", T_timer[tm]);
DataGridView_AddRow(hWndTimersDataGrid, (LPSTR)temp, 3);
ListView_GetItemRect(hWndTimersDataGrid, tm, &irect, LVIR_BOUNDS);
if (irect.bottom >= rect.bottom - 6) break;
}
CreateThread(
NULL, // default security attributes
0, // use default stack size
AddRemainingTimers, // thread function name
tm + 1, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier
ShowWindow(hWndTimersDataGrid, SW_SHOW);
DataGridView_DisplayRowHeaders(hWndTimersDataGrid, TRUE);
DataGridView_ExtendLastColumn(hWndTimersDataGrid, TRUE, 400, 100);
DataGridView_SetResizableHeader(hWndTimersDataGrid, 1);
return 0;
case WM_SIZE:
GetClientRect(hMainTab, &rect);
TabCtrl_AdjustRect(hMainTab, 0, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
SetWindowPos(hWnd, HWND_TOP, rect.left, rect.top, width, height, SWP_NOACTIVATE);
GetClientRect(hWnd, &rect);
if (hWndTimersDataGrid)
{
SendMessage(hWndTimersDataGrid, WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.right - rect.left - 6, rect.bottom - rect.top - 6));
InvalidateRect(hMainTab, &rect, TRUE);
}
break;
case MIRMSG_TABCHANGE:
switch (wParam)
{
case SW_SHOW:
ShowWindow(hWndTimersDataGrid, SW_SHOW);
break;
}
return 0;
case WM_COMMAND:
switch (HIWORD(wParam))
{
case DGVM_ENDEDIT:
col = HIWORD(lParam);
row = LOWORD(lParam);
if (col != 1) return 1;
DataGridView_GetCellValue(hWndTimersDataGrid, row, col, temp[0], 32);
for (i = 0; i < strlen(temp[0]); i++)
{
if (temp[0][i] >= 0 && temp[0][i] <= 255 && !isdigit(temp[0][i]))
{
T_set[row] = 2;
return 1;
}
}
T_cur[row] = T_max[row] = atoi(temp[0]);
T_set[row] = (atoi(temp[0]) != T_orig[row]) ? 1 : 0;
return 1;
}
break;
case WM_DESTROY:
free(T_set);
free(T_orig);
free(T_cur);
free(T_timer_old);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void TabTimersUpdate()
{
char ctemp[8];
RECT rect, wrect, irect;
if (!hWndTimersDataGrid) return;
//int c1 = ListView_GetColumnWidth(hWndTimersDataGrid, 0);
//int c2 = ListView_GetColumnWidth(hWndTimersDataGrid, 1);
int top = ListView_GetTopIndex(hWndTimersDataGrid);
ListView_GetItemRect(hWndTimersDataGrid, top, &rect, LVIR_BOUNDS);
GetWindowRect(hWndTimersDataGrid, &wrect);
for (int tm = top; tm < TM_MAX; ++tm)
{
if (T_timer[tm] != T_timer_old[tm])
{
ListView_GetItemRect(hWndTimersDataGrid, tm, &irect, LVIR_BOUNDS);
if (irect.bottom - rect.top <= wrect.bottom + 20)
{
sprintf_s(ctemp, 8, "%d", T_timer[tm]);
DataGridView_SetCellValue(hWndTimersDataGrid, tm, 2, ctemp);
ListView_GetItemRect(hWndTimersDataGrid, tm, &rect, LVIR_BOUNDS);
InvalidateRect(hWndTimersDataGrid, &rect, TRUE);
}
}
}
for (int tm = 0; tm < TM_MAX; ++tm)
{
if (T_max[tm] != T_cur[tm])
{
char temp[32];
T_cur[tm] = T_max[tm];
T_set[tm] = (T_max[tm] != T_orig[tm]) ? 1 : 0;
sprintf_s(temp, 32, "%d", T_max[tm]);
DataGridView_SetCellValue(hWndTimersDataGrid, tm, 1, temp);
ListView_GetItemRect(hWndTimersDataGrid, tm, &rect, LVIR_BOUNDS);
InvalidateRect(hWndTimersDataGrid, &rect, TRUE);
}
T_timer_old[tm] = T_timer[tm];
}
}
void TabTimersReset()
{
}
short CALLBACK tabTM_ischanged(int tm)
{
return T_set[tm];
}