【问题标题】:C++ textbox fontC++ 文本框字体
【发布时间】:2012-08-31 19:09:35
【问题描述】:

我用 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
    );
}

【问题讨论】:

标签: c++ winapi


【解决方案1】:

一些 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);

【讨论】:

  • אליהו בסה:在调用SystemParametersInfo 之后和调用CreateFontIndirect 之前,修改结构ncm.lfMessageFont 的值?
【解决方案2】:

WM_SETFONT 消息就是您要查找的内容。

【讨论】:

    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 2012-01-23
    • 2018-10-23
    • 1970-01-01
    相关资源
    最近更新 更多