Windows에서 알 수없는 "Blah"라는 글꼴 이름을 사용하는 "FamilyName"을 알고 싶습니다. 아래에서 볼 수 있듯이GetOutlineTextMetrics() 함수가 존재하지 않는 글꼴 facename에 대해 0을 반환하는 이유는 무엇입니까?
, 폰트가 정상적으로 생성 (WM_PAINT 함수 GetOutlineTextMetric()
의 반환 값을 인쇄하는 데 사용
#include <windows.h>
#include <iostream>
LRESULT CALLBACK WndProc(HWND, UINT, UINT, LONG);
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int nCmdShow)
{
WNDCLASSEX wndclassx;
wndclassx.cbSize = sizeof(WNDCLASSEX);
wndclassx.style = CS_HREDRAW | CS_VREDRAW;
wndclassx.lpfnWndProc = WndProc;
wndclassx.cbClsExtra = 0;
wndclassx.cbWndExtra = 0;
wndclassx.hInstance = hInstance;
wndclassx.hIcon = nullptr;
wndclassx.hCursor = LoadCursor(nullptr, IDC_ARROW);
wndclassx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclassx.lpszMenuName = nullptr;
wndclassx.lpszClassName = L"WndProc";
wndclassx.hIconSm = nullptr;
if(!RegisterClassEx(&wndclassx)) return 0;
HWND hWnd = CreateWindow(L"WndProc", nullptr, WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInstance, nullptr);
ShowWindow(hWnd, SW_NORMAL);
UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Retorna msg.wParam
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
static HFONT s_hFont;
static int s_int = -1;
static TEXTMETRIC s_tm;
switch (message)
{
case WM_CREATE:
{
HDC hDC;
if(!(hDC = CreateIC(L"Display", nullptr, nullptr, nullptr))) return -1;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Blah");
if(!(s_hFont = CreateFontIndirect(&lf)))
{
DeleteDC(hDC);
return -1;
}
s_hFont = (HFONT)SelectObject(hDC, s_hFont);
GetTextMetrics(hDC, &s_tm);
// Call GetOutlineTextMetrics() with a null buffer address, to get the size of the buffer.
s_int = GetOutlineTextMetrics(hDC, 0, nullptr);
s_hFont = (HFONT)SelectObject(hDC, s_hFont);
DeleteDC(hDC);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
s_hFont = (HFONT)SelectObject(ps.hdc, s_hFont);
TextOut(ps.hdc, 20, 20, L"Value returned by GetOutlineTextMetrics() function", 50);
wchar_t buffer[4];
swprintf(buffer, 4, L"%3d", s_int);
TextOut(ps.hdc, 20 + 55 * s_tm.tmAveCharWidth, 20, buffer, 3);
EndPaint(hwnd, &ps);
}
break;
case WM_DESTROY:
DeleteObject(s_hFont);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
출력
편집 :.이 내가 수정 한 코드에서 오류가 발생했습니다. 대신 WM_CREATE
에 s_hFont = (HFONT)SelectObject(hDC, s_hFont)
이 있어야합니다. 출력을 변경하지 않았습니다. 그래도. 그러나 최종 결과는 동일합니다. GetOutlineTextMetrics() 함수는 0을 계속 반환합니다.
두 답변을 모두 수락했을 것입니다. 그러나 다른 하나가 먼저왔다. 답장을 보내 주셔서 감사합니다. – WaldB