1

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
    );
}
Maxwe11
  • 486
  • 4
  • 12
  • possible duplicate of [Why my edit control looks odd in my win32 c++ application using no MFC?](http://stackoverflow.com/questions/8695185/why-my-edit-control-looks-odd-in-my-win32-c-application-using-no-mfc) – tenfour Sep 06 '12 at 22:05
  • I voted to close as a dupe of that question but actually it doesn't have a clear answer. But this one does: http://stackoverflow.com/questions/1955806/how-do-i-dynamically-create-controls-with-the-same-visual-style-as-their-parent – tenfour Sep 06 '12 at 22:06

2 Answers2

1

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);
beerboy
  • 1,304
  • 12
  • 12
  • אליהו בסה: After you call `SystemParametersInfo` and before you call `CreateFontIndirect`, modify the values of the struct `ncm.lfMessageFont`? – beerboy Oct 11 '12 at 20:34
0

The WM_SETFONT message is what you're looking for.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79