简体   繁体   中英

C++ textbox font

I made a textbox in C++ (Win32) Now I want change the textbox form and font because it's look ugly How I do it?

It's how I create the textbox

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

Several Windows controls are initialized with the ugly System font - if you want nice looking controls, you have to change the font yourself like so:

// 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消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM