Skip to content

Commit a94c034

Browse files
committed
Keyboard support for GUI
1 parent 8f794c8 commit a94c034

File tree

2 files changed

+106
-13
lines changed

2 files changed

+106
-13
lines changed

ExplorerPatcher/GUI.c

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
113113
DWORD dwTextFlags = DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
114114
RECT rcText;
115115
DWORD dwCL = 0;
116+
BOOL bTabOrderHit = FALSE;
116117

117118
HDC hdcPaint = NULL;
118119
BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
@@ -126,7 +127,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
126127
wchar_t* text = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
127128
wchar_t* name = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
128129
wchar_t* section = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
129-
size_t bufsiz = 0, numChRd = 0;
130+
size_t bufsiz = 0, numChRd = 0, tabOrder = 1;
130131
while ((numChRd = getline(&line, &bufsiz, f)) != -1)
131132
{
132133
if (strcmp(line, "Windows Registry Editor Version 5.00\r\n") && strcmp(line, "\r\n"))
@@ -213,6 +214,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
213214
}
214215
if (hDC)
215216
{
217+
if (!strncmp(line, ";u ", 3) && tabOrder == _this->tabOrder)
218+
{
219+
bTabOrderHit = TRUE;
220+
DttOpts.crText = GUI_TEXTCOLOR_SELECTED;
221+
}
216222
DrawThemeTextEx(
217223
_this->hTheme,
218224
hdcPaint,
@@ -224,6 +230,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
224230
&rcText,
225231
&DttOpts
226232
);
233+
if (!strncmp(line, ";u ", 3) && tabOrder == _this->tabOrder)
234+
{
235+
DttOpts.crText = GUI_TEXTCOLOR;
236+
}
227237
}
228238
else
229239
{
@@ -237,7 +247,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
237247
DT_CALCRECT
238248
);
239249
rcTemp.bottom = rcText.bottom;
240-
if (!strncmp(line, ";u ", 3) && PtInRect(&rcTemp, pt))
250+
if (!strncmp(line, ";u ", 3) && (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder)))
241251
{
242252
numChRd = getline(&line, &bufsiz, f);
243253
char* p = strchr(line, '\r');
@@ -414,6 +424,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
414424
}
415425
}
416426
dwCL += dwLineHeight * dy;
427+
if (!strncmp(line, ";u ", 3))
428+
{
429+
tabOrder++;
430+
}
417431
}
418432
else if (!strncmp(line, ";l ", 3) || !strncmp(line, ";c ", 3) || !strncmp(line, ";b ", 3) || !strncmp(line, ";i ", 3) || !strncmp(line, ";d ", 3) || !strncmp(line, ";v ", 3))
419433
{
@@ -609,7 +623,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
609623
DT_CALCRECT
610624
);
611625
rcTemp.bottom = rcText.bottom;
612-
if (!hDC && PtInRect(&rcTemp, pt))
626+
if (!hDC && (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder)))
613627
{
614628
if (bJustCheck)
615629
{
@@ -723,7 +737,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
723737
);
724738
rcTemp.bottom = rcText.bottom;
725739
//printf("%d %d %d %d %d %d %d %d\n", rcText.left, rcText.top, rcText.right, rcText.bottom, rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom);
726-
if (PtInRect(&rcTemp, pt))
740+
if (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder))
727741
{
728742
numChRd = getline(&line, &bufsiz, f);
729743
char* p = strchr(line, '\r');
@@ -742,6 +756,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
742756
}
743757
if (hDC)
744758
{
759+
if (tabOrder == _this->tabOrder)
760+
{
761+
bTabOrderHit = TRUE;
762+
DttOpts.crText = GUI_TEXTCOLOR_SELECTED;
763+
}
745764
DrawThemeTextEx(
746765
_this->hTheme,
747766
hdcPaint,
@@ -753,8 +772,13 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
753772
&rcText,
754773
&DttOpts
755774
);
775+
if (tabOrder == _this->tabOrder)
776+
{
777+
DttOpts.crText = GUI_TEXTCOLOR;
778+
}
756779
}
757780
dwCL += dwLineHeight * dy;
781+
tabOrder++;
758782
}
759783
}
760784
}
@@ -767,6 +791,14 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
767791
DeleteObject(hFontTitle);
768792
DeleteObject(hFontUnderline);
769793
DeleteObject(hFontCaption);
794+
if (_this->tabOrder == GUI_MAX_TABORDER)
795+
{
796+
_this->tabOrder = tabOrder;
797+
}
798+
else if (!bTabOrderHit)
799+
{
800+
_this->tabOrder = 0;
801+
}
770802
}
771803
EndBufferedPaint(hBufferedPaint, TRUE);
772804
}
@@ -825,6 +857,39 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
825857
PostQuitMessage(0);
826858
return 0;
827859
}
860+
else if (uMsg == WM_KEYDOWN)
861+
{
862+
if (wParam == VK_ESCAPE)
863+
{
864+
PostMessage(hWnd, WM_CLOSE, 0, 0);
865+
return 0;
866+
}
867+
else if (wParam == VK_TAB)
868+
{
869+
if (GetKeyState(VK_SHIFT) & 0x8000)
870+
{
871+
_this->tabOrder--;
872+
if (_this->tabOrder == 0)
873+
{
874+
_this->tabOrder = GUI_MAX_TABORDER;
875+
}
876+
}
877+
else
878+
{
879+
_this->tabOrder++;
880+
}
881+
InvalidateRect(hWnd, NULL, FALSE);
882+
return 0;
883+
}
884+
else if (wParam == VK_SPACE)
885+
{
886+
POINT pt;
887+
pt.x = 0;
888+
pt.y = 0;
889+
GUI_Build(0, hWnd, pt);
890+
return 0;
891+
}
892+
}
828893
else if (uMsg == WM_NCHITTEST)
829894
{
830895
POINT pt;
@@ -883,16 +948,40 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
883948

884949
__declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow)
885950
{
886-
/*
887-
FILE* conout;
888-
AllocConsole();
889-
freopen_s(
890-
&conout,
891-
"CONOUT$",
892-
"w",
893-
stdout
951+
HKEY hKey;
952+
DWORD dwDisposition;
953+
DWORD dwSize = sizeof(DWORD);
954+
RegCreateKeyExW(
955+
HKEY_CURRENT_USER,
956+
TEXT(REGPATH),
957+
0,
958+
NULL,
959+
REG_OPTION_NON_VOLATILE,
960+
KEY_READ,
961+
NULL,
962+
&hKey,
963+
&dwDisposition
894964
);
895-
*/
965+
DWORD bAllocConsole = FALSE;
966+
RegQueryValueExW(
967+
hKey,
968+
TEXT("AllocConsole"),
969+
0,
970+
NULL,
971+
&bAllocConsole,
972+
&dwSize
973+
);
974+
if (bAllocConsole)
975+
{
976+
FILE* conout;
977+
AllocConsole();
978+
freopen_s(
979+
&conout,
980+
"CONOUT$",
981+
"w",
982+
stdout
983+
);
984+
}
896985

897986
printf("Started \"GUI\" thread.\n");
898987

@@ -909,6 +998,7 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
909998
_this.padding.top = GUI_PADDING_TOP;
910999
_this.padding.bottom = GUI_PADDING_BOTTOM;
9111000
_this.hTheme = OpenThemeData(NULL, TEXT(GUI_WINDOWSWITCHER_THEME_CLASS));
1001+
_this.tabOrder = 0;
9121002

9131003
WNDCLASS wc = { 0 };
9141004
ZeroMemory(&wc, sizeof(WNDCLASSW));

ExplorerPatcher/GUI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern HMODULE hModule;
3535
#define GUI_LINE_HEIGHT 26
3636
#define GUI_CAPTION_LINE_HEIGHT 42
3737
#define GUI_TEXTCOLOR RGB(0, 0, 0)
38+
#define GUI_TEXTCOLOR_SELECTED RGB(255, 0, 0)
39+
#define GUI_MAX_TABORDER 9999
3840
#define GUI_PADDING 5
3941
#define GUI_PADDING_LEFT GUI_PADDING * 3
4042
#define GUI_PADDING_RIGHT GUI_PADDING * 3
@@ -49,6 +51,7 @@ typedef struct _GUI
4951
HTHEME hTheme;
5052
POINT dpi;
5153
MARGINS extent;
54+
UINT tabOrder;
5255
} GUI;
5356

5457
static HRESULT GUI_AboutProc(

0 commit comments

Comments
 (0)