+ -
当前位置:首页 → 问答吧 → 如何输出系统字体

如何输出系统字体

时间:2011-12-22

来源:互联网

正在看《windows程序设计》。他有个输出系统字体的代码,但不是我想要的。下图是书上例子代码输出结果(截取PDF书的图)




下面是VB6视频教程的代码,这个是我想要的结果。怎么才能达到这个效果?




作者: xiaoyuanyuan2009   发布时间: 2011-12-22

两个功能是不一样的,《Windows程序设计》上只是输出指定的几个字体的前256个字符而已,而VB则是枚举字体名称

作者: pgplay   发布时间: 2011-12-22

枚举系统字体?
EnumFontFamiliesEx

作者: VisualEleven   发布时间: 2011-12-22

C/C++ code
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT("winTest");
    HWND        hwnd;
    MSG         msg;
    WNDCLASSEX  wndclass;

    wndclass.cbSize         = sizeof(wndclass);
    wndclass.style          = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc    = WndProc;
    wndclass.cbClsExtra     = 0;
    wndclass.cbWndExtra     = 0;
    wndclass.hInstance      = hInstance;
    wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszClassName  = szAppName;
    wndclass.lpszMenuName   = NULL;

    RegisterClassEx(&wndclass);

    hwnd = CreateWindow(szAppName, TEXT("Test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

int CALLBACK EnumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
    ::SendMessage((HWND)lpData, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
    return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    HWND hComboBox;
 
    switch(message)
    {
    case WM_CREATE:
        hdc = GetDC(hwnd);
        hComboBox = CreateWindow(TEXT("ComboBox"), NULL, WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD, 0, 0, 150, 180, hwnd, (HMENU)0, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
        EnumFonts(hdc, NULL, EnumFontsProc, (LPARAM)hComboBox);
        ReleaseDC(hwnd, hdc);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
        return DefWindowProc(hwnd, message, wParam, lParam);
}

作者: pgplay   发布时间: 2011-12-22