26 static VOID NcAreaFreeTheme(
30 if (Context->BrushNormal)
31 DeleteObject(Context->BrushNormal);
33 if (Context->BrushHot)
34 DeleteObject(Context->BrushHot);
36 if (Context->BrushFocused)
37 DeleteObject(Context->BrushFocused);
39 if (Context->BrushFill)
40 DeleteObject(Context->BrushFill);
42 if (Context->WindowFont)
43 DeleteObject(Context->WindowFont);
46 static VOID NcAreaInitializeFont(
50 NONCLIENTMETRICS metrics = {
sizeof(NONCLIENTMETRICS) };
53 if (Context->WindowFont)
54 DeleteObject(Context->WindowFont);
56 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0))
58 metrics.lfMessageFont.lfHeight = -11;
60 Context->WindowFont = CreateFontIndirect(&metrics.lfMessageFont);
66 GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),
sizeof(LOGFONT), &font);
70 Context->WindowFont = CreateFontIndirect(&font);
73 SendMessage(Context->WindowHandle, WM_SETFONT, (WPARAM)Context->WindowFont,
TRUE);
76 static VOID NcAreaInitializeTheme(
80 Context->CXBorder = GetSystemMetrics(SM_CXBORDER) * 2;
83 Context->BackgroundColorRef = GetSysColor(COLOR_WINDOW);
84 Context->BrushFill = GetSysColorBrush(COLOR_WINDOW);
85 Context->BrushNormal = GetStockBrush(BLACK_BRUSH);
90 static VOID NcAreaInitializeImageList(
94 HBITMAP bitmapActive = NULL;
95 HBITMAP bitmapInactive = NULL;
97 Context->ImageWidth = 23;
98 Context->ImageHeight = 20;
99 Context->ImageList = ImageList_Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 0);
101 ImageList_SetBkColor(Context->ImageList, Context->BackgroundColorRef);
102 ImageList_SetImageCount(Context->ImageList, 2);
107 ImageList_Replace(Context->ImageList, 0, bitmapActive, NULL);
108 DeleteObject(bitmapActive);
117 ImageList_Replace(Context->ImageList, 1, bitmapInactive, NULL);
118 DeleteObject(bitmapInactive);
126 static VOID NcAreaGetButtonRect(
128 _Inout_ PRECT ButtonRect
131 ButtonRect->left = (ButtonRect->right - Context->cxImgSize) - Context->CXBorder;
132 ButtonRect->bottom -= 2;
133 ButtonRect->right -= 2;
134 ButtonRect->top += 2;
137 static VOID NcAreaDrawButton(
144 if (!(hdc = GetWindowDC(Context->WindowHandle)))
147 SetBkMode(hdc, TRANSPARENT);
149 FillRect(hdc, &ButtonRect, Context->BrushFill);
175 ButtonRect.top + ((ButtonRect.bottom - ButtonRect.top) - Context->ImageHeight) / 2,
178 Context->BackgroundColorRef,
179 Context->BackgroundColorRef,
180 ILD_NORMAL | ILD_TRANSPARENT
190 ButtonRect.top + ((ButtonRect.bottom - ButtonRect.top) - (Context->ImageHeight - 1)) / 2,
193 Context->BackgroundColorRef,
194 Context->BackgroundColorRef,
195 ILD_NORMAL | ILD_TRANSPARENT
199 ReleaseDC(Context->WindowHandle, hdc);
202 static LRESULT CALLBACK NcAreaWndSubclassProc(
207 _In_ UINT_PTR uIdSubclass,
208 _In_ ULONG_PTR dwRefData
213 context = (
PEDIT_CONTEXT)GetProp(hwndDlg, L
"EditSubclassContext");
219 NcAreaFreeTheme(context);
224 RemoveWindowSubclass(hwndDlg, NcAreaWndSubclassProc, uIdSubclass);
225 RemoveProp(hwndDlg, L
"EditSubclassContext");
233 LPNCCALCSIZE_PARAMS ncCalcSize = (NCCALCSIZE_PARAMS*)lParam;
236 DefSubclassProc(hwndDlg, uMsg, wParam, lParam);
239 ncCalcSize->rgrc[0].right -= context->
cxImgSize;
247 DefSubclassProc(hwndDlg, uMsg, wParam, lParam);
250 GetWindowRect(hwndDlg, &windowRect);
253 OffsetRect(&windowRect, -windowRect.left, -windowRect.top);
256 NcAreaGetButtonRect(context, &windowRect);
259 NcAreaDrawButton(context, windowRect);
268 windowPoint.x = GET_X_LPARAM(lParam);
269 windowPoint.y = GET_Y_LPARAM(lParam);
272 GetWindowRect(hwndDlg, &windowRect);
273 NcAreaGetButtonRect(context, &windowRect);
276 if (PtInRect(&windowRect, windowPoint))
282 case WM_NCLBUTTONDOWN:
288 windowPoint.x = GET_X_LPARAM(lParam);
289 windowPoint.y = GET_Y_LPARAM(lParam);
292 GetWindowRect(hwndDlg, &windowRect);
293 NcAreaGetButtonRect(context, &windowRect);
296 if (PtInRect(&windowRect, windowPoint))
300 RedrawWindow(hwndDlg, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
310 windowPoint.x = GET_X_LPARAM(lParam);
311 windowPoint.y = GET_Y_LPARAM(lParam);
314 GetWindowRect(hwndDlg, &windowRect);
317 OffsetRect(&windowRect, -windowRect.left, -windowRect.top);
320 NcAreaGetButtonRect(context, &windowRect);
323 if (PtInRect(&windowRect, windowPoint))
329 if (GetCapture() == hwndDlg)
334 RedrawWindow(hwndDlg, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
339 if (wParam ==
'\t' || wParam ==
'\r')
374 Edit_SetSel(hwndDlg, 0, -1);
380 if (wParam ==
'\t' || wParam ==
'\r')
391 RedrawWindow(hwndDlg, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
393 case WM_SETTINGCHANGE:
394 case WM_SYSCOLORCHANGE:
395 case WM_THEMECHANGED:
397 NcAreaFreeTheme(context);
398 NcAreaInitializeTheme(context);
399 NcAreaInitializeFont(context);
402 SendMessage(hwndDlg, EM_SETMARGINS, EC_LEFTMARGIN, MAKELPARAM(0, 0));
405 RedrawWindow(hwndDlg, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
419 return DefSubclassProc(hwndDlg, uMsg, wParam, lParam);
431 BOOLEAN isSuccess =
FALSE;
432 ULONG resourceLength = 0;
433 HGLOBAL resourceHandle = NULL;
434 HRSRC resourceHandleSource = NULL;
435 WICInProcPointer resourceBuffer = NULL;
437 BITMAPINFO bitmapInfo = { 0 };
438 HBITMAP bitmapHandle = NULL;
439 PBYTE bitmapBuffer = NULL;
441 IWICStream* wicStream = NULL;
442 IWICBitmapSource* wicBitmapSource = NULL;
443 IWICBitmapDecoder* wicDecoder = NULL;
444 IWICBitmapFrameDecode* wicFrame = NULL;
445 IWICImagingFactory* wicFactory = NULL;
446 IWICBitmapScaler* wicScaler = NULL;
447 WICPixelFormatGUID pixelFormat;
449 WICRect rect = { 0, 0, Width, Height };
454 if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, &wicFactory)))
468 if ((resourceBuffer = (WICInProcPointer)LockResource(resourceHandle)) == NULL)
472 if (FAILED(IWICImagingFactory_CreateStream(wicFactory, &wicStream)))
476 if (FAILED(IWICStream_InitializeFromMemory(wicStream, resourceBuffer, resourceLength)))
479 if (FAILED(IWICImagingFactory_CreateDecoder(wicFactory, &GUID_ContainerFormatPng, NULL, &wicDecoder)))
482 if (FAILED(IWICBitmapDecoder_Initialize(wicDecoder, (IStream*)wicStream, WICDecodeMetadataCacheOnLoad)))
486 if (FAILED(IWICBitmapDecoder_GetFrameCount(wicDecoder, &frameCount)) || frameCount < 1)
490 if (FAILED(IWICBitmapDecoder_GetFrame(wicDecoder, 0, &wicFrame)))
494 if (FAILED(IWICBitmapFrameDecode_GetPixelFormat(wicFrame, &pixelFormat)))
498 if (IsEqualGUID(&pixelFormat, &GUID_WICPixelFormat32bppPBGRA))
500 wicBitmapSource = (IWICBitmapSource*)wicFrame;
505 if (FAILED(WICConvertBitmapSource(&GUID_WICPixelFormat32bppPBGRA, (IWICBitmapSource*)wicFrame, &wicBitmapSource)))
508 IWICBitmapFrameDecode_Release(wicFrame);
511 bitmapInfo.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
512 bitmapInfo.bmiHeader.biWidth = rect.Width;
513 bitmapInfo.bmiHeader.biHeight = -((
LONG)rect.Height);
514 bitmapInfo.bmiHeader.biPlanes = 1;
515 bitmapInfo.bmiHeader.biBitCount = 32;
516 bitmapInfo.bmiHeader.biCompression = BI_RGB;
518 HDC hdc = CreateCompatibleDC(NULL);
519 bitmapHandle = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, (PVOID*)&bitmapBuffer, NULL, 0);
520 ReleaseDC(NULL, hdc);
524 if (FAILED(IWICImagingFactory_CreateBitmapScaler(wicFactory, &wicScaler)))
526 if (FAILED(IWICBitmapScaler_Initialize(wicScaler, wicBitmapSource, rect.Width, rect.Height, WICBitmapInterpolationModeFant)))
528 if (FAILED(IWICBitmapScaler_CopyPixels(wicScaler, &rect, rect.Width * 4, rect.Width * rect.Height * 4, bitmapBuffer)))
537 IWICBitmapScaler_Release(wicScaler);
542 IWICBitmapSource_Release(wicBitmapSource);
547 IWICStream_Release(wicStream);
552 IWICBitmapDecoder_Release(wicDecoder);
557 IWICImagingFactory_Release(wicFactory);
562 FreeResource(resourceHandle);
587 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
594 NcAreaInitializeTheme(context);
595 NcAreaInitializeImageList(context);
598 Edit_SetCueBannerText(context->
WindowHandle, L
"Search Processes (Ctrl+K)");
601 SetProp(context->
WindowHandle, L
"EditSubclassContext", (HANDLE)context);
604 SetWindowSubclass(context->WindowHandle, NcAreaWndSubclassProc, 0, (ULONG_PTR)context);
607 SendMessage(context->WindowHandle, WM_THEMECHANGED, 0, 0);
609 return context->WindowHandle;