Skip to content

Commit c64fdab

Browse files
committed
Improve searchbox darktheme banners and borders
1 parent 1ecc78c commit c64fdab

File tree

2 files changed

+96
-20
lines changed

2 files changed

+96
-20
lines changed

ProcessHacker/searchbox.c

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ typedef struct _EDIT_CONTEXT
4848
INT CXBorder;
4949
INT ImageWidth;
5050
INT ImageHeight;
51-
HWND WindowHandle;
5251
WNDPROC DefaultWindowProc;
5352
HFONT WindowFont;
5453
HIMAGELIST ImageListHandle;
54+
PPH_STRING CueBannerText;
5555
} EDIT_CONTEXT, *PEDIT_CONTEXT;
5656

5757
HICON PhpSearchBitmapToIcon(
@@ -68,17 +68,19 @@ VOID PhpSearchFreeTheme(
6868
}
6969

7070
VOID PhpSearchInitializeFont(
71-
_Inout_ PEDIT_CONTEXT Context
71+
_Inout_ PEDIT_CONTEXT Context,
72+
_In_ HWND WindowHandle
7273
)
7374
{
7475
if (Context->WindowFont)
7576
DeleteFont(Context->WindowFont);
7677

77-
Context->WindowFont = PhCreateCommonFont(10, FW_MEDIUM, Context->WindowHandle);
78+
Context->WindowFont = PhCreateCommonFont(10, FW_MEDIUM, WindowHandle);
7879
}
7980

8081
VOID PhpSearchInitializeTheme(
81-
_Inout_ PEDIT_CONTEXT Context
82+
_Inout_ PEDIT_CONTEXT Context,
83+
_In_ HWND WindowHandle
8284
)
8385
{
8486
Context->CXWidth = PH_SCALE_DPI(20);
@@ -88,7 +90,7 @@ VOID PhpSearchInitializeTheme(
8890
{
8991
HTHEME themeDataHandle;
9092

91-
if (themeDataHandle = OpenThemeData(Context->WindowHandle, VSCLASS_EDIT))
93+
if (themeDataHandle = OpenThemeData(WindowHandle, VSCLASS_EDIT))
9294
{
9395
//IsThemePartDefined_I(themeDataHandle, EP_EDITBORDER_NOSCROLL, EPSHV_NORMAL);
9496

@@ -167,14 +169,15 @@ VOID PhpSearchGetButtonRect(
167169

168170
VOID PhpSearchDrawButton(
169171
_Inout_ PEDIT_CONTEXT Context,
172+
_In_ HWND WindowHandle,
170173
_In_ HDC Hdc,
171174
_In_ RECT WindowRect,
172175
_In_ RECT ButtonRect
173176
)
174177
{
175178
if (Context->ThemeSupport) // HACK
176179
{
177-
if (GetFocus() == Context->WindowHandle)
180+
if (GetFocus() == WindowHandle)
178181
{
179182
//switch (Context->ColorMode)
180183
//{
@@ -255,7 +258,7 @@ VOID PhpSearchDrawButton(
255258
FillRect(Hdc, &ButtonRect, GetStockBrush(DC_BRUSH));
256259
break;
257260
case 1: // Old colors
258-
SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
261+
//SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
259262
SetDCBrushColor(Hdc, RGB(99, 99, 99));
260263
FillRect(Hdc, &ButtonRect, GetStockBrush(DC_BRUSH));
261264
break;
@@ -279,7 +282,7 @@ VOID PhpSearchDrawButton(
279282
FillRect(Hdc, &ButtonRect, GetStockBrush(DC_BRUSH));
280283
break;
281284
case 1: // Old colors
282-
SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
285+
//SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
283286
SetDCBrushColor(Hdc, RGB(78, 78, 78));
284287
FillRect(Hdc, &ButtonRect, GetStockBrush(DC_BRUSH));
285288
break;
@@ -302,7 +305,7 @@ VOID PhpSearchDrawButton(
302305
FillRect(Hdc, &ButtonRect, GetSysColorBrush(COLOR_WINDOW));
303306
break;
304307
case 1: // Old colors
305-
SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
308+
//SetTextColor(Hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
306309
SetDCBrushColor(Hdc, RGB(60, 60, 60));
307310
FillRect(Hdc, &ButtonRect, GetStockBrush(DC_BRUSH));
308311
break;
@@ -315,7 +318,7 @@ VOID PhpSearchDrawButton(
315318
}
316319
}
317320

318-
if (Edit_GetTextLength(Context->WindowHandle) > 0)
321+
if (Edit_GetTextLength(WindowHandle) > 0)
319322
{
320323
PhImageListDrawIcon(
321324
Context->ImageListHandle,
@@ -372,6 +375,12 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
372375
context->ImageListHandle = NULL;
373376
}
374377

378+
if (context->CueBannerText)
379+
{
380+
PhDereferenceObject(context->CueBannerText);
381+
context->CueBannerText = NULL;
382+
}
383+
375384
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc);
376385
PhRemoveWindowContext(hWnd, SHRT_MAX);
377386
PhFree(context);
@@ -451,11 +460,12 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
451460
{
452461
if (context->ThemeSupport)
453462
{
454-
FrameRect(bufferDc, &windowRect, GetSysColorBrush(COLOR_WINDOWFRAME));
463+
SetDCBrushColor(bufferDc, RGB(0x8f, 0x8f, 0x8f));
464+
FrameRect(bufferDc, &windowRect, GetStockBrush(DC_BRUSH));
455465
}
456466
else
457467
{
458-
SetDCBrushColor(bufferDc, RGB(0, 0, 0)); // RGB(65, 65, 65)
468+
SetDCBrushColor(bufferDc, RGB(43, 43, 43));
459469
FrameRect(bufferDc, &windowRect, GetStockBrush(DC_BRUSH));
460470
}
461471

@@ -466,8 +476,8 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
466476
{
467477
if (context->ThemeSupport)
468478
{
469-
SetDCBrushColor(bufferDc, RGB(0, 0, 0)); // RGB(65, 65, 65)
470-
FrameRect(bufferDc, &windowRect, GetStockBrush(DC_BRUSH));
479+
//SetDCBrushColor(bufferDc, RGB(43, 43, 43));
480+
FrameRect(bufferDc, &windowRect, GetSysColorBrush(COLOR_WINDOWFRAME));
471481
}
472482
else
473483
{
@@ -479,7 +489,7 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
479489
}
480490

481491
// Draw the button.
482-
PhpSearchDrawButton(context, bufferDc, windowRect, buttonRect);
492+
PhpSearchDrawButton(context, hWnd, bufferDc, windowRect, buttonRect);
483493

484494
BitBlt(hdc, bufferRect.left, bufferRect.top, bufferRect.right, bufferRect.bottom, bufferDc, 0, 0, SRCCOPY);
485495
SelectBitmap(bufferDc, oldBufferBitmap);
@@ -586,8 +596,8 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
586596
case WM_THEMECHANGED:
587597
{
588598
PhpSearchFreeTheme(context);
589-
PhpSearchInitializeTheme(context);
590-
PhpSearchInitializeFont(context);
599+
PhpSearchInitializeTheme(context, hWnd);
600+
PhpSearchInitializeFont(context, hWnd);
591601

592602
// Reset the client area margins.
593603
SendMessage(hWnd, EM_SETMARGINS, EC_LEFTMARGIN, MAKELPARAM(0, 0));
@@ -663,6 +673,73 @@ LRESULT CALLBACK PhpSearchWndSubclassProc(
663673
RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
664674
}
665675
break;
676+
case WM_PAINT:
677+
{
678+
if (
679+
PhIsNullOrEmptyString(context->CueBannerText) ||
680+
GetFocus() == hWnd ||
681+
Edit_GetTextLength(hWnd) > 0
682+
)
683+
{
684+
return CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam);
685+
}
686+
687+
HDC hdc = (HDC)wParam ? (HDC)wParam : GetDC(hWnd);
688+
689+
if (hdc)
690+
{
691+
HDC bufferDc;
692+
RECT clientRect;
693+
HFONT oldFont;
694+
HBITMAP bufferBitmap;
695+
HBITMAP oldBufferBitmap;
696+
697+
GetClientRect(hWnd, &clientRect);
698+
699+
bufferDc = CreateCompatibleDC(hdc);
700+
bufferBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom);
701+
oldBufferBitmap = SelectBitmap(bufferDc, bufferBitmap);
702+
703+
SetBkMode(bufferDc, TRANSPARENT);
704+
705+
if (context->ThemeSupport)
706+
{
707+
SetTextColor(bufferDc, RGB(170, 170, 170));
708+
SetDCBrushColor(bufferDc, RGB(60, 60, 60));
709+
FillRect(bufferDc, &clientRect, GetStockBrush(DC_BRUSH));
710+
}
711+
else
712+
{
713+
SetTextColor(bufferDc, GetSysColor(COLOR_GRAYTEXT));
714+
FillRect(bufferDc, &clientRect, GetSysColorBrush(COLOR_WINDOW));
715+
}
716+
717+
oldFont = SelectFont(bufferDc, GetWindowFont(hWnd));
718+
clientRect.left += 2;
719+
DrawText(
720+
bufferDc,
721+
context->CueBannerText->Buffer,
722+
(UINT)context->CueBannerText->Length / 2,
723+
&clientRect,
724+
DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP
725+
);
726+
clientRect.left -= 2;
727+
SelectFont(bufferDc, oldFont);
728+
729+
BitBlt(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, bufferDc, 0, 0, SRCCOPY);
730+
SelectBitmap(bufferDc, oldBufferBitmap);
731+
DeleteBitmap(bufferBitmap);
732+
DeleteDC(bufferDc);
733+
734+
if (!(HDC)wParam)
735+
{
736+
ReleaseDC(hWnd, hdc);
737+
}
738+
}
739+
740+
return DefWindowProc(hWnd, uMsg, wParam, lParam);
741+
}
742+
break;
666743
}
667744

668745
return CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam);
@@ -703,7 +780,6 @@ VOID PhCreateSearchControl(
703780
PEDIT_CONTEXT context;
704781

705782
context = PhAllocateZero(sizeof(EDIT_CONTEXT));
706-
context->WindowHandle = WindowHandle;
707783
context->ThemeSupport = !!PhGetIntegerSetting(L"EnableThemeSupport"); // HACK
708784
context->ColorMode = PhGetIntegerSetting(L"GraphColorMode");
709785

@@ -712,7 +788,7 @@ VOID PhCreateSearchControl(
712788

713789
// Set initial text
714790
if (BannerText)
715-
Edit_SetCueBannerText(WindowHandle, BannerText);
791+
context->CueBannerText = PhCreateString(BannerText);
716792

717793
// Subclass the Edit control window procedure.
718794
context->DefaultWindowProc = (WNDPROC)GetWindowLongPtr(WindowHandle, GWLP_WNDPROC);

phlib/theme.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ VOID PhInitializeThemeWindowEditControl(
510510

511511
// HACK: The searchbox control does its own themed drawing and it uses the
512512
// same window context value so we know when to ignore theming.
513-
if (PhGetWindowContext(EditControlHandle, LONG_MAX))
513+
if (PhGetWindowContext(EditControlHandle, SHRT_MAX))
514514
return;
515515

516516
editControlWindowProc = (WNDPROC)GetWindowLongPtr(EditControlHandle, GWLP_WNDPROC);

0 commit comments

Comments
 (0)