C++文本框字体

C++ textbox font

本文关键字:字体 文本 C++      更新时间:2023-10-16

我在C++(Win32)中制作了一个文本框现在我想更改文本框的形式和字体,因为它看起来很难看我是怎么做的?

这就是我创建文本框的方式

HWND WindowManager::textbox(int width, int height, int xPos, int yPos, LPCSTR content, bool edit_able)
{
    int type = (edit_able) ? (WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL) : (WS_CHILD|WS_VISIBLE|WS_HSCROLL|ES_AUTOHSCROLL);
    return CreateWindowEx(
        WS_EX_CLIENTEDGE,
        "EDIT",
        content,
        type,
        xPos,
        yPos,
        width,
        height,
        window,
        (HMENU)50,
        GetModuleHandle(NULL),
        NULL
    );
}

几个Windows控件都是用丑陋的系统字体初始化的——如果你想要好看的控件,你必须自己更改字体,如下所示:

// create the text box
HWND hTextBox = CreateWindowEx(...);
// initialize NONCLIENTMETRICS structure
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
// obtain non-client metrics
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
// create the new font
HFONT hNewFont = CreateFontIndirect(&ncm.lfMessageFont);
// set the new font
SendMessage(hTextBox, WM_SETFONT, (WPARAM)hNewFont, 0);

WM_SETFONT消息就是您要查找的。