#include <Windows.h>
|
#include <cstdio>
|
|
VOID PrintHex(PBYTE Data, ULONG dwBytes) {
|
for (ULONG i = 0; i < dwBytes; i += 16) {
|
printf("%.8x: ", i);
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes) {
|
printf("%.2x ", Data[i + j]);
|
} else {
|
printf("?? ");
|
}
|
}
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes && Data[i + j] >= 0x20 && Data[i + j] <= 0x7e) {
|
printf("%c", Data[i + j]);
|
} else {
|
printf(".");
|
}
|
}
|
|
printf("\n");
|
}
|
}
|
|
int main() {
|
// Create a Device Context.
|
HDC hdc = CreateCompatibleDC(NULL);
|
|
// Create a TrueType font.
|
HFONT hfont = CreateFont(10, // nHeight
|
10, // nWidth
|
0, // nEscapement
|
0, // nOrientation
|
FW_DONTCARE, // fnWeight
|
FALSE, // fdwItalic
|
FALSE, // fdwUnderline
|
FALSE, // fdwStrikeOut
|
ANSI_CHARSET, // fdwCharSet
|
OUT_DEFAULT_PRECIS, // fdwOutputPrecision
|
CLIP_DEFAULT_PRECIS, // fdwClipPrecision
|
DEFAULT_QUALITY, // fdwQuality
|
FF_DONTCARE, // fdwPitchAndFamily
|
L"Times New Roman");
|
|
// Select the font into the DC.
|
SelectObject(hdc, hfont);
|
|
// Get the number of bytes the text metrics consume.
|
UINT MetricsLength = GetOutlineTextMetrics(hdc, 0, NULL);
|
|
// Obtain the metrics descriptor and dump it on the screen.
|
PBYTE OutputBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MetricsLength);
|
GetOutlineTextMetrics(hdc, MetricsLength, (LPOUTLINETEXTMETRICW)OutputBuffer);
|
|
PrintHex(&OutputBuffer[0], MetricsLength);
|
|
// Free resources.
|
HeapFree(GetProcessHeap(), 0, OutputBuffer);
|
DeleteObject(hfont);
|
DeleteDC(hdc);
|
|
return 0;
|
}
|