-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.cpp
259 lines (219 loc) · 9.15 KB
/
options.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//**********************************************************************
// Copyright (c) 2009-2021 Daniel D Miller
// derbar.exe - Another WinBar application
// derbar.cpp: main interface functions
//
// Written by: Daniel D. Miller
//**********************************************************************
#include <windows.h>
#include <time.h>
#include <tchar.h>
#ifdef _lint
#include <stdlib.h>
#endif
#include "resource.h"
#include "common.h"
#include "derbar.h"
#include "winmsgs.h"
#include "tooltips.h"
bool show_winmsgs = false ;
bool keep_on_top = false ;
bool use_logon_time_for_uptime = false ;
bool show_seconds_for_uptime = true ;
static HWND hwndEditFgnd ;
static HWND hwndEditBgnd ;
extern void update_keep_on_top(void);
//****************************************************************************
// Options dialog tooltips
//****************************************************************************
static tooltip_data_t const options_tooltips[] = {
{ IDS_CLR_FGND, _T("Select foreground color of data fields")},
{ IDC_EDIT_FGND, _T("Select foreground color of data fields")},
{ IDC_CLR_FGND, _T("View color selector for foreground color" )},
{ IDS_CLR_BGND, _T("Select background color of data fields")},
{ IDC_EDIT_BGND, _T("Select background color of data fields")},
{ IDC_CLR_BGND, _T("View color selector for background color" )},
{ IDM_ONTOP, _T("Keep main dialog on top of other applications" )},
{ IDM_LOGIN_UPTIME, _T("Show login label vs uptime, as appropriate" )},
{ IDM_LOGIN_SECONDS, _T("Show/hide seconds in uptime/login field" )},
{ IDM_WINMSGS, _T("Show WinAPI debug messages in DebugView" )},
{ IDS_MIN_FREEMEM, _T("Display minimum observed free memory (debug)" )},
{ IDC_MIN_FREEMEM, _T("Display minimum observed free memory (debug)" )},
{ IDC_CLR_MIN_FMEM, _T("Reset low-memory indicators (debug)" )},
{ IDOK, _T("Close this dialog and accept changes" )},
// This is how to enter multi-line tooltips:
// { IDS_CP_SERNUM, _T("The SEND CMD button will send COMMAND to the device with")
// _T("this Serial Number. If Serial Number is 0, COMMAND is sent ")
// _T("to the broadcast address on the current port.") },
{ 0, NULL }} ;
// low-memory indicators
extern u64 min_freemem ;
extern bool isMemoryLow ;
//*******************************************************************
// show minimum free memory
//*******************************************************************
static void show_min_free_memory(HWND hwnd)
{
char msgstr[81] ;
u64 min_free_mb = min_freemem / (1024 * 1024);
convert_to_commas(min_free_mb, msgstr);
SetWindowText(GetDlgItem(hwnd, IDC_MIN_FREEMEM), msgstr);
}
//*******************************************************************
static void reset_low_memory_indicators(HWND hwnd)
{
isMemoryLow = false ;
min_freemem = 0 ;
show_min_free_memory(hwnd);
}
//******************************************************************
static INT_PTR CALLBACK OptionsProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
uint tempEditLength ;
char msgstr[81] ;
//***************************************************
// debug: log all windows messages
//***************************************************
if (show_winmsgs) {
switch (msg) {
// list messages to be ignored
case WM_NCHITTEST:
case WM_SETCURSOR:
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
break;
default:
syslog("Opt [%s]\n", lookup_winmsg_name(msg)) ;
break;
}
}
//********************************************************************
// Windows message handler for this dialog
//********************************************************************
switch(msg) {
case WM_INITDIALOG:
// #ifdef __x86_64__
#ifdef _WIN64
SetClassLongPtr(hwnd, GCLP_HICON, (LONG_PTR)LoadIcon(g_hinst, (LPCTSTR)IDI_MAINICON));
SetClassLongPtr(hwnd, GCLP_HICONSM, (LONG_PTR)LoadIcon(g_hinst, (LPCTSTR)IDI_MAINICON));
#else
SetClassLong(hwnd, GCL_HICON, (LONG)LoadIcon(g_hinst, (LPCTSTR)IDI_MAINICON));
SetClassLong(hwnd, GCL_HICONSM, (LONG)LoadIcon(g_hinst, (LPCTSTR)IDI_MAINICON));
#endif
// label the dialog
hwndEditFgnd = GetDlgItem(hwnd, IDC_EDIT_FGND) ; // EDITTEXT
hwndEditBgnd = GetDlgItem(hwnd, IDC_EDIT_BGND) ; // EDITTEXT
wsprintf(msgstr, " 0x%06X", fgnd_edit) ;
SetWindowText(hwndEditFgnd, msgstr);
wsprintf(msgstr, " 0x%06X", bgnd_edit) ;
SetWindowText(hwndEditBgnd, msgstr);
PostMessage(GetDlgItem(hwnd, IDM_WINMSGS), BM_SETCHECK, show_winmsgs, 0) ;
PostMessage(GetDlgItem(hwnd, IDM_ONTOP), BM_SETCHECK, keep_on_top, 0) ;
PostMessage(GetDlgItem(hwnd, IDM_LOGIN_UPTIME), BM_SETCHECK, use_logon_time_for_uptime, 0) ;
PostMessage(GetDlgItem(hwnd, IDM_LOGIN_SECONDS), BM_SETCHECK, show_seconds_for_uptime, 0) ;
show_min_free_memory(hwnd) ;
create_and_add_tooltips(hwnd, 150, 100, 10000, options_tooltips);
return TRUE ;
//********************************************************************
// menu/control messages
//********************************************************************
case WM_COMMAND:
if (HIWORD (wParam) == BN_CLICKED) {
char *tptr ;
COLORREF temp_attr ;
bool changed ;
switch(LOWORD(wParam)) {
case IDM_WINMSGS:
show_winmsgs = (show_winmsgs) ? false : true ;
return TRUE;
case IDM_ONTOP:
keep_on_top = (keep_on_top) ? false : true ;
update_keep_on_top() ;
return TRUE;
case IDM_LOGIN_UPTIME:
use_logon_time_for_uptime = (use_logon_time_for_uptime) ? false : true ;
return TRUE;
case IDM_LOGIN_SECONDS:
show_seconds_for_uptime = (show_seconds_for_uptime) ? false : true ;
return TRUE;
case IDC_CLR_MIN_FMEM:
reset_low_memory_indicators(hwnd) ;
return TRUE;
case IDC_CLR_FGND:
temp_attr = select_color(fgnd_edit) ;
// if user cancels color entry, stick with
// existing color selection.
if (temp_attr != 0) {
wsprintf(msgstr, " 0x%06X", temp_attr) ;
SetWindowText(hwndEditFgnd, msgstr);
}
return TRUE;
case IDC_CLR_BGND:
temp_attr = select_color(bgnd_edit) ;
// if user cancels color entry, stick with
// existing color selection.
if (temp_attr != 0) {
wsprintf(msgstr, " 0x%06X", temp_attr) ;
SetWindowText(hwndEditBgnd, msgstr);
}
return TRUE;
case IDOK: // take the new settings
changed = false ;
tempEditLength = GetWindowTextLength (hwndEditFgnd);
GetWindowText (hwndEditFgnd, msgstr, tempEditLength + 1);
msgstr[tempEditLength] = 0;
tptr = strip_leading_spaces(msgstr) ;
temp_attr = (uint) strtoul(tptr, 0, 0) ;
if (temp_attr != fgnd_edit) {
fgnd_edit = temp_attr ;
changed = true ;
wsprintf(msgstr, " 0x%06X", fgnd_edit) ;
SetWindowText(hwndEditFgnd, msgstr);
}
tempEditLength = GetWindowTextLength (hwndEditBgnd);
GetWindowText (hwndEditBgnd, msgstr, tempEditLength + 1);
msgstr[tempEditLength] = 0;
tptr = strip_leading_spaces(msgstr) ;
temp_attr = (uint) strtoul(tptr, 0, 0) ;
if (temp_attr != fgnd_edit) {
bgnd_edit = temp_attr ;
changed = true ;
hbEdit = CreateSolidBrush(bgnd_edit) ;
wsprintf(msgstr, " 0x%06X", bgnd_edit) ;
SetWindowText(hwndEditBgnd, msgstr);
}
// sel = SendMessageA(hwndIpIface, CB_GETCURSEL, 0, 0);
// if (ip_iface_idx != sel) {
// ip_iface_idx = sel ;
// changed = TRUE ;
// }
update_uptime_label();
if (changed)
save_cfg_file() ;
DestroyWindow(hwnd);
return TRUE ;
case IDCANCEL: // discard all changes
// send_commands(this_port) ;
DestroyWindow(hwnd);
return TRUE ;
default:
return FALSE;
}
}
return FALSE;
case WM_CLOSE:
DestroyWindow(hwnd);
return TRUE ;
case WM_DESTROY:
return TRUE ;
default:
return FALSE;
}
return FALSE; //lint !e527
} //lint !e715
//****************************************************************************
void open_options_dialog(HWND hwnd)
{
// DialogBox(g_hinst, MAKEINTRESOURCE(IDD_OPTIONS), hwnd, OptionsProc) ;
DialogBox(g_hinst, MAKEINTRESOURCE(IDD_OPTIONS), 0, OptionsProc) ;
} //lint !e715 hwnd