Skip to content

Commit 930cfe7

Browse files
committed
Add reset button to settings dialog
1 parent 5dfe10b commit 930cfe7

File tree

4 files changed

+81
-54
lines changed

4 files changed

+81
-54
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
- Improve method for spy window selection
55
- Investigate VirusTotal results for installer
66
- Add auto-tray option: when created, when minimized, both
7-
- Add reset button to settings dialog
87
- Add option to make tray icons persistent even when window is restored
98
- Find a way to properly minimize UWP app windows
109
- Fix handling of elevated windows

src/Finestray.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ BEGIN
107107

108108
PUSHBUTTON "Help", IDC_HELP_PAGE, 10, 278, 50, 14
109109
PUSHBUTTON "About", IDC_ABOUT, 64, 278, 50, 14
110-
PUSHBUTTON "Exit", IDC_EXIT, 118, 278, 50, 14
110+
PUSHBUTTON "Reset", IDC_RESET, 118, 278, 50, 14
111+
PUSHBUTTON "Exit", IDC_EXIT, 172, 278, 50, 14
111112
PUSHBUTTON "Cancel", IDCANCEL, 305, 278, 50, 14
112113
DEFPUSHBUTTON "OK", IDOK, 359, 278, 50, 14
113114
END

src/Resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define IDC_AUTO_TRAY_ITEM_SPY 1019
8181
#define IDC_HELP_PAGE 1020
8282
#define IDC_ABOUT 1021
83-
#define IDC_EXIT 1022
83+
#define IDC_RESET 1022
84+
#define IDC_EXIT 1023
8485

8586
// clang-format on

src/SettingsDialog.cpp

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ INT_PTR settingsDialogFunc(HWND dialogHwnd, UINT message, WPARAM wParam, LPARAM
170170
if (!SetDlgItemTextA(dialogHwnd, IDC_POLL_INTERVAL, std::to_string(settings_.pollInterval_).c_str())) {
171171
WARNING_PRINTF("SetDlgItemText failed: %s\n", StringUtility::lastErrorString().c_str());
172172
}
173+
if (!SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_EXECUTABLE, "")) {
174+
WARNING_PRINTF("SetWindowTextA failed: %s\n", StringUtility::lastErrorString().c_str());
175+
}
176+
if (!SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWCLASS, "")) {
177+
WARNING_PRINTF("SetWindowTextA failed: %s\n", StringUtility::lastErrorString().c_str());
178+
}
179+
if (!SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWTITLE, "")) {
180+
WARNING_PRINTF("SetWindowTextA failed: %s\n", StringUtility::lastErrorString().c_str());
181+
}
173182

174183
autoTrayListViewInit(dialogHwnd);
175184

@@ -251,6 +260,12 @@ INT_PTR settingsDialogFunc(HWND dialogHwnd, UINT message, WPARAM wParam, LPARAM
251260
break;
252261
}
253262

263+
case IDC_RESET: {
264+
settings_ = Settings();
265+
SendMessageA(dialogHwnd, WM_INITDIALOG, 0, 0);
266+
break;
267+
}
268+
254269
case IDC_EXIT:
255270
case IDOK: {
256271
INFO_PRINTF("Settings dialog done, updating settings\n");
@@ -310,55 +325,66 @@ void autoTrayListViewInit(HWND dialogHwnd)
310325
{
311326
autoTrayListViewHwnd_ = GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_LIST);
312327

313-
unsigned int styles = LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES;
314-
if (SendMessageA(autoTrayListViewHwnd_, LVM_SETEXTENDEDLISTVIEWSTYLE, styles, styles) == -1) {
315-
std::string lastErrorString = StringUtility::lastErrorString();
316-
WARNING_PRINTF("SendMessage LVM_SETEXTENDEDLISTVIEWSTYLE failed: %s\n", lastErrorString.c_str());
317-
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
318-
return;
319-
}
328+
HWND hWndHdr = (HWND)::SendMessage(autoTrayListViewHwnd_, LVM_GETHEADER, 0, 0);
329+
int count = (int)::SendMessage(hWndHdr, HDM_GETITEMCOUNT, 0, 0L);
330+
if (count < 3) {
331+
unsigned int styles = LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES;
332+
if (SendMessageA(autoTrayListViewHwnd_, LVM_SETEXTENDEDLISTVIEWSTYLE, styles, styles) == -1) {
333+
std::string lastErrorString = StringUtility::lastErrorString();
334+
WARNING_PRINTF("SendMessage LVM_SETEXTENDEDLISTVIEWSTYLE failed: %s\n", lastErrorString.c_str());
335+
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
336+
return;
337+
}
320338

321-
RECT rect;
322-
GetWindowRect(autoTrayListViewHwnd_, &rect);
323-
int width = rect.right - rect.left;
324-
int columnWidth = (width - 18) / (int)AutoTrayListViewColumn::Count;
339+
RECT rect;
340+
GetWindowRect(autoTrayListViewHwnd_, &rect);
341+
int width = rect.right - rect.left;
342+
int columnWidth = (width - 18) / (int)AutoTrayListViewColumn::Count;
325343

326-
LVCOLUMNA listViewColumn;
327-
memset(&listViewColumn, 0, sizeof(listViewColumn));
328-
listViewColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
329-
listViewColumn.fmt = LVCFMT_LEFT;
330-
listViewColumn.cx = columnWidth;
344+
LVCOLUMNA listViewColumn;
345+
memset(&listViewColumn, 0, sizeof(listViewColumn));
346+
listViewColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
347+
listViewColumn.fmt = LVCFMT_LEFT;
348+
listViewColumn.cx = columnWidth;
331349

332-
std::string str;
350+
std::string str;
333351

334-
listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::Executable);
335-
str = getResourceString(IDS_COLUMN_EXECUTABLE);
336-
listViewColumn.pszText = (LPSTR)str.c_str();
337-
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) == -1) {
338-
std::string lastErrorString = StringUtility::lastErrorString();
339-
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
340-
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
341-
return;
342-
}
352+
listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::Executable);
353+
str = getResourceString(IDS_COLUMN_EXECUTABLE);
354+
listViewColumn.pszText = (LPSTR)str.c_str();
355+
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) ==
356+
-1) {
357+
std::string lastErrorString = StringUtility::lastErrorString();
358+
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
359+
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
360+
return;
361+
}
343362

344-
++listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::WindowClass);
345-
str = getResourceString(IDS_COLUMN_WINDOW_CLASS);
346-
listViewColumn.pszText = (LPSTR)str.c_str();
347-
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) == -1) {
348-
std::string lastErrorString = StringUtility::lastErrorString();
349-
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
350-
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
351-
return;
363+
++listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::WindowClass);
364+
str = getResourceString(IDS_COLUMN_WINDOW_CLASS);
365+
listViewColumn.pszText = (LPSTR)str.c_str();
366+
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) ==
367+
-1) {
368+
std::string lastErrorString = StringUtility::lastErrorString();
369+
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
370+
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
371+
return;
372+
}
373+
374+
listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::WindowTitle);
375+
str = getResourceString(IDS_COLUMN_WINDOW_TITLE);
376+
listViewColumn.pszText = (LPSTR)str.c_str();
377+
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) ==
378+
-1) {
379+
std::string lastErrorString = StringUtility::lastErrorString();
380+
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
381+
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
382+
return;
383+
}
352384
}
353385

354-
listViewColumn.iSubItem = static_cast<int>(AutoTrayListViewColumn::WindowTitle);
355-
str = getResourceString(IDS_COLUMN_WINDOW_TITLE);
356-
listViewColumn.pszText = (LPSTR)str.c_str();
357-
if (SendMessageA(autoTrayListViewHwnd_, LVM_INSERTCOLUMNA, listViewColumn.iSubItem, (LPARAM)&listViewColumn) == -1) {
358-
std::string lastErrorString = StringUtility::lastErrorString();
359-
WARNING_PRINTF("SendMessage LVM_INSERTCOLUMNA failed: %s\n", lastErrorString.c_str());
360-
errorMessage(ErrorContext(IDS_ERROR_CREATE_DIALOG, lastErrorString));
361-
return;
386+
if (!SendMessageA(autoTrayListViewHwnd_, LVM_DELETEALLITEMS, 0, 0)) {
387+
WARNING_PRINTF("SendMessage LVM_DELETEALLITEMS failed: %s\n", StringUtility::lastErrorString().c_str());
362388
}
363389

364390
if (SendMessageA(autoTrayListViewHwnd_, LVM_SETITEMCOUNT, (WPARAM)settings_.autoTrays_.size(), 0) == -1) {
@@ -655,21 +681,21 @@ void autoTrayListViewItemEdit(HWND dialogHwnd, int item)
655681

656682
if ((item < 0) || (item >= itemCount)) {
657683
WARNING_PRINTF("Item %d out of range\n", item);
658-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_EXECUTABLE), "");
659-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWCLASS), "");
660-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWTITLE), "");
684+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_EXECUTABLE, "");
685+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWCLASS, "");
686+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWTITLE, "");
661687
autoTrayListViewActiveItem_ = -1;
662688
} else {
663689
std::string executable = getListViewItemText(autoTrayListViewHwnd_, item, (int)AutoTrayListViewColumn::Executable);
664-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_EXECUTABLE), executable.c_str());
690+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_EXECUTABLE, executable.c_str());
665691

666692
std::string windowClass =
667693
getListViewItemText(autoTrayListViewHwnd_, item, (int)AutoTrayListViewColumn::WindowClass);
668-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWCLASS), windowClass.c_str());
694+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWCLASS, windowClass.c_str());
669695

670696
std::string windowTitle =
671697
getListViewItemText(autoTrayListViewHwnd_, item, (int)AutoTrayListViewColumn::WindowTitle);
672-
SetWindowTextA(GetDlgItem(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWTITLE), windowTitle.c_str());
698+
SetDlgItemTextA(dialogHwnd, IDC_AUTO_TRAY_EDIT_WINDOWTITLE, windowTitle.c_str());
673699

674700
autoTrayListViewActiveItem_ = item;
675701
}
@@ -801,9 +827,9 @@ void spySelectWindowAtPoint(const POINT & point)
801827
std::string title = getWindowText(rootHwnd);
802828
DEBUG_PRINTF("Title: '%s'\n", title.c_str());
803829

804-
SetWindowTextA(GetDlgItem(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_EXECUTABLE), executableFullPath);
805-
SetWindowTextA(GetDlgItem(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_WINDOWCLASS), className.c_str());
806-
SetWindowTextA(GetDlgItem(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_WINDOWTITLE), title.c_str());
830+
SetDlgItemTextA(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_EXECUTABLE, executableFullPath);
831+
SetDlgItemTextA(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_WINDOWCLASS, className.c_str());
832+
SetDlgItemTextA(spuModeHwnd_, IDC_AUTO_TRAY_EDIT_WINDOWTITLE, title.c_str());
807833

808834
ShowWindow(spuModeHwnd_, SW_SHOW);
809835
SetForegroundWindow(spuModeHwnd_);

0 commit comments

Comments
 (0)