From d311529320ca311b69d44799c16213942d0c052d Mon Sep 17 00:00:00 2001 From: dmex Date: Tue, 20 Jun 2017 21:34:49 +1000 Subject: [PATCH] Move font functions to sdk --- ProcessHacker/appsup.c | 18 ---------- ProcessHacker/include/appsup.h | 5 --- ProcessHacker/include/phapp.h | 59 ++++++++++++++++++++++++++++++++ ProcessHacker/main.c | 28 ++------------- plugins/ToolStatus/customizesb.c | 2 +- plugins/ToolStatus/customizetb.c | 2 +- plugins/include/commonutil.h | 13 ------- 7 files changed, 63 insertions(+), 64 deletions(-) diff --git a/ProcessHacker/appsup.c b/ProcessHacker/appsup.c index 44c042089..4271dced7 100644 --- a/ProcessHacker/appsup.c +++ b/ProcessHacker/appsup.c @@ -1148,24 +1148,6 @@ BOOLEAN PhGetListViewContextMenuPoint( return FALSE; } -HFONT PhDuplicateFontWithNewWeight( - _In_ HFONT Font, - _In_ LONG NewWeight - ) -{ - LOGFONT logFont; - - if (GetObject(Font, sizeof(LOGFONT), &logFont)) - { - logFont.lfWeight = NewWeight; - return CreateFontIndirect(&logFont); - } - else - { - return NULL; - } -} - VOID PhSetWindowOpacity( _In_ HWND WindowHandle, _In_ ULONG OpacityPercent diff --git a/ProcessHacker/include/appsup.h b/ProcessHacker/include/appsup.h index db93af4c9..1843bae47 100644 --- a/ProcessHacker/include/appsup.h +++ b/ProcessHacker/include/appsup.h @@ -212,11 +212,6 @@ PhGetListViewContextMenuPoint( ); // end_phapppub -HFONT PhDuplicateFontWithNewWeight( - _In_ HFONT Font, - _In_ LONG NewWeight - ); - VOID PhSetWindowOpacity( _In_ HWND WindowHandle, _In_ ULONG OpacityPercent diff --git a/ProcessHacker/include/phapp.h b/ProcessHacker/include/phapp.h index c21344942..0237a4cb5 100644 --- a/ProcessHacker/include/phapp.h +++ b/ProcessHacker/include/phapp.h @@ -629,6 +629,32 @@ PhLoadPngImageFromResource( _In_ BOOLEAN RGBAImage ); +FORCEINLINE +HFONT +PhCreateFont( + _In_ PWSTR Name, + _In_ ULONG Size, + _In_ ULONG Weight + ) +{ + return CreateFont( + -(LONG)PhMultiplyDivide(Size, PhGlobalDpi, 72), + 0, + 0, + 0, + Weight, + FALSE, + FALSE, + FALSE, + ANSI_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + DEFAULT_PITCH, + Name + ); +} + FORCEINLINE HFONT PhCreateCommonFont( @@ -668,6 +694,39 @@ PhCreateCommonFont( return fontHandle; } + +FORCEINLINE +HFONT +PhDuplicateFont( + _In_ HFONT Font + ) +{ + LOGFONT logFont; + + if (GetObject(Font, sizeof(LOGFONT), &logFont)) + return CreateFontIndirect(&logFont); + + return NULL; +} + +FORCEINLINE +HFONT +PhDuplicateFontWithNewWeight( + _In_ HFONT Font, + _In_ LONG NewWeight + ) +{ + LOGFONT logFont; + + if (GetObject(Font, sizeof(LOGFONT), &logFont)) + { + logFont.lfWeight = NewWeight; + return CreateFontIndirect(&logFont); + } + + return NULL; +} + // end_phapppub // sessmsg diff --git a/ProcessHacker/main.c b/ProcessHacker/main.c index d972aac56..4aed3dd8f 100644 --- a/ProcessHacker/main.c +++ b/ProcessHacker/main.c @@ -488,30 +488,6 @@ VOID PhInitializeCommonControls( InitCommonControlsEx(&icex); } -HFONT PhpCreateFont( - _In_ PWSTR Name, - _In_ ULONG Size, - _In_ ULONG Weight - ) -{ - return CreateFont( - -(LONG)PhMultiplyDivide(Size, PhGlobalDpi, 72), - 0, - 0, - 0, - Weight, - FALSE, - FALSE, - FALSE, - ANSI_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - DEFAULT_PITCH, - Name - ); -} - VOID PhInitializeFont( _In_ HWND hWnd ) @@ -533,8 +509,8 @@ VOID PhInitializeFont( success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0); if ( - !(PhApplicationFont = PhpCreateFont(L"Microsoft Sans Serif", 8, FW_NORMAL)) && - !(PhApplicationFont = PhpCreateFont(L"Tahoma", 8, FW_NORMAL)) + !(PhApplicationFont = PhCreateFont(L"Microsoft Sans Serif", 8, FW_NORMAL)) && + !(PhApplicationFont = PhCreateFont(L"Tahoma", 8, FW_NORMAL)) ) { if (success) diff --git a/plugins/ToolStatus/customizesb.c b/plugins/ToolStatus/customizesb.c index cd4dbd290..e8ce99115 100644 --- a/plugins/ToolStatus/customizesb.c +++ b/plugins/ToolStatus/customizesb.c @@ -319,7 +319,7 @@ INT_PTR CALLBACK CustomizeStatusBarDialogProc( context->MoveDownButtonHandle = GetDlgItem(hwndDlg, IDC_MOVEDOWN); context->AddButtonHandle = GetDlgItem(hwndDlg, IDC_ADD); context->RemoveButtonHandle = GetDlgItem(hwndDlg, IDC_REMOVE); - context->FontHandle = CommonDuplicateFont((HFONT)SendMessage(StatusBarHandle, WM_GETFONT, 0, 0)); + context->FontHandle = PhDuplicateFont((HFONT)SendMessage(StatusBarHandle, WM_GETFONT, 0, 0)); ListBox_SetItemHeight(context->AvailableListHandle, 0, PH_SCALE_DPI(22)); // BitmapHeight ListBox_SetItemHeight(context->CurrentListHandle, 0, PH_SCALE_DPI(22)); // BitmapHeight diff --git a/plugins/ToolStatus/customizetb.c b/plugins/ToolStatus/customizetb.c index cef8fdffb..27330c0c7 100644 --- a/plugins/ToolStatus/customizetb.c +++ b/plugins/ToolStatus/customizetb.c @@ -523,7 +523,7 @@ INT_PTR CALLBACK CustomizeToolbarDialogProc( context->BrushNormal = GetSysColorBrush(COLOR_WINDOW); context->BrushHot = CreateSolidBrush(RGB(145, 201, 247)); context->BrushPushed = CreateSolidBrush(RGB(153, 209, 255)); - context->FontHandle = CommonDuplicateFont((HFONT)SendMessage(ToolBarHandle, WM_GETFONT, 0, 0)); + context->FontHandle = PhDuplicateFont((HFONT)SendMessage(ToolBarHandle, WM_GETFONT, 0, 0)); ListBox_SetItemHeight(context->AvailableListHandle, 0, context->CXWidth + 6); // BitmapHeight ListBox_SetItemHeight(context->CurrentListHandle, 0, context->CXWidth + 6); // BitmapHeight diff --git a/plugins/include/commonutil.h b/plugins/include/commonutil.h index a6e265992..c55114688 100644 --- a/plugins/include/commonutil.h +++ b/plugins/include/commonutil.h @@ -569,18 +569,5 @@ FormatAnsiString( return FormatAnsiString_V(Format, argptr); } -FORCEINLINE -HFONT -CommonDuplicateFont( - _In_ HFONT Font - ) -{ - LOGFONT logFont; - - if (GetObject(Font, sizeof(LOGFONT), &logFont)) - return CreateFontIndirect(&logFont); - else - return NULL; -} #endif \ No newline at end of file