I need to wrap text on a button. It is for a question bank, in which the answer is displayed on buttons for the user to select. The problem starts when the length of the string is longer than the button is wide, and needs to start a new line. I have looked in the search, but not pinpointed antything exactly specific.
I could do this counting characters and inserting hard line breaks "\n", but with all those WIN API messages available, I thought there might be one available already.
Any help, please? Thanks in advance....
(some rough code to set the picture of what I am up to)...
// Window Procedure......
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
loadfile(hWnd); // This function call just loads the strings, no big deal...
Here is where I make a button. The problem is;
I cannot seem to get the text to wrap and start a new line if it
is wider than the button.
HWND hwndButton0 = CreateWindowEx(
MyFile.c_str(), // Text on the button
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, // | BS_PUSHBUTTON ,
if (newtext == true)
newtext = false;
newtext = true;
p += 10;
HWND hwndButton0 = GetDlgItem(hWnd, ID_BUT0);
//SetWindowText(hwndButton0, "Try now"); // This works...
SendMessage(hwndButton0, WM_SETTEXT, 0, (LPARAM)"Another way");
// This SendMessage() is another way to do it, too.
// Take your pick, I think (?).
//HDC hdcBut0 = GetDCEx(hwndButton0, NULL, DCX_WINDOW);
//TextOut(hdcBut0, 10,10, "HELLO", strlen("HELLO"));
/* This does NOT work. I don't understand the "range" bit in GetDCEx()....
However, the thing is NONE of this allows me, apparently, to
be able to wrap the text effectively
return DefWindowProc(hWnd, Msg, wParam, lParam);