Yet another button question!
Hi all,
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)...
Code:
// Window Procedure......
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
{
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(
WS_EX_CLIENTEDGE,
"BUTTON",
MyFile[0].c_str(), // Text on the button
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, // | BS_PUSHBUTTON ,
10,
10,
100,
100,
hWnd,
(HMENU)ID_BUT0,
//(HINSTANCE)GetWindowLong(*****),
(HINSTANCE)GetModuleHandle(NULL),
NULL);
}
break;
case WM_PAINT:
if (newtext == true)
{
showfile(hWnd);
newtext = false;
}
break;
case WM_MOVE:
newtext = true;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_BUT0:
{
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"));
//ReleaseDC(hwndButton0, hdcBut0);
/* 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
*/
EndDialog(hwndButton0, NULL);
break;
}
//break;
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}