Files
systeminformer/plugins/include/commonutil.h
T
2016-11-14 20:51:41 +11:00

136 lines
2.4 KiB
C

#ifndef _COMMONUTIL_H
#define _COMMONUTIL_H
/**
* Creates a Ansi string using format specifiers.
*
* \param Format The format-control string.
* \param ArgPtr A pointer to the list of arguments.
*/
FORCEINLINE
PPH_BYTES
FormatAnsiString_V(
_In_ _Printf_format_string_ PSTR Format,
_In_ va_list ArgPtr
)
{
PPH_BYTES string;
int length;
length = _vscprintf(Format, ArgPtr);
if (length == -1)
return NULL;
string = PhCreateBytesEx(NULL, length * sizeof(CHAR));
_vsnprintf(
string->Buffer,
length,
Format, ArgPtr
);
return string;
}
/**
* Creates a Ansi string using format specifiers.
*
* \param Format The format-control string.
*/
FORCEINLINE
PPH_BYTES
FormatAnsiString(
_In_ _Printf_format_string_ PSTR Format,
...
)
{
va_list argptr;
va_start(argptr, Format);
return FormatAnsiString_V(Format, argptr);
}
FORCEINLINE
HFONT
CommonCreateFont(
_In_ LONG Size,
_In_ HWND hwnd
)
{
LOGFONT logFont;
// Create the font handle
if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &logFont, 0))
{
HFONT fontHandle = CreateFont(
-PhMultiplyDivideSigned(Size, PhGlobalDpi, 72),
0,
0,
0,
FW_MEDIUM,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY | ANTIALIASED_QUALITY,
DEFAULT_PITCH,
logFont.lfFaceName
);
SendMessage(hwnd, WM_SETFONT, (WPARAM)fontHandle, TRUE);
return fontHandle;
}
return NULL;
}
FORCEINLINE
HFONT
CommonDuplicateFont(
_In_ HFONT Font
)
{
LOGFONT logFont;
if (GetObject(Font, sizeof(LOGFONT), &logFont))
return CreateFontIndirect(&logFont);
else
return NULL;
}
FORCEINLINE
HICON
CommonBitmapToIcon(
_In_ HBITMAP BitmapHandle,
_In_ INT Width,
_In_ INT Height
)
{
HICON icon;
HDC screenDc;
HBITMAP screenBitmap;
ICONINFO iconInfo = { 0 };
screenDc = CreateIC(L"DISPLAY", NULL, NULL, NULL);
screenBitmap = CreateCompatibleBitmap(screenDc, Width, Height);
iconInfo.fIcon = TRUE;
iconInfo.hbmColor = BitmapHandle;
iconInfo.hbmMask = screenBitmap;
icon = CreateIconIndirect(&iconInfo);
DeleteObject(screenBitmap);
DeleteDC(screenDc);
return icon;
}
#endif