Unicode newline using TEXT macro?

Somehow I feel stupid for not being able to figure this out, but here goes:

I want to include a newline in a string literal that's being converted to Unicode inside a TEXT macro. The converted string gets passed to DrawText. I've tried a variety of different escape code literals (like \n, \r, \n\r, \0\n, etc.), and none have had the desired result. Anybody know the correct arcanity to solve this problem?

Thanks,

Barry

[440 byte] By [Dachannien] at [2007-12-25]
# 1
have you tried "\r\n"?
It will work
Sarath. at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2
The correct order of the line feed and carriage return control characters is "\r\n".
MariusBancila at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3
Unfortunately, \r\n runs into the same problem as the rest. Apparently, the problem is that DrawText is not properly interpreting the newline. This happens even with DT_WORDBREAK. Coincidentally (or perhaps not so), DrawText is also not breaking the line to prevent overflowing the bounding rectangle with DT_WORDBREAK specified.

This is for a Windows Mobile 5.0 project, by the way. Is it possible that DrawText doesn't support newlines at all on that platform? I was unable to find any reference at all to Windows Mobile support in the API docs, and I didn't find any documentation on the Windows Mobile implementation of the Win32 API even after considerable digging.

Dachannien at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 4

Windows mobile is a build of Windows CE, so that is the documentation you should be looking at. According to this though it supports multiple lines so the newline character sequence should work. What way are you trying to do \r\n, maybe that will shine some light on this problem.

An idea though, for the uFormat parameter, are you using DT_SINGLELINE as one of the formats? If you are then this will cause the line breaks not to work.

crescens2k at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 5
At one point in my code, I do this:

AddItem(TEXT("blah blah\r\nblah blah blah\r\nblah blah"));

Eventually this call works its way down so that a buffer of WCHARs is allocated and the string is copied into it, but that's not important. The buffer address is later passed into DrawText.

The TEXT macro converts the string appropriately, including the CR and LF (I looked at the string in hex after it got copied into the buffer).

Apparently, DrawText isn't handling it properly (it is using DrawTextW like it is supposed to - at least, the tooltip that comes up over DrawText indicates that it's macro defined that way). The only options specified are DT_CENTER | DT_VCENTER | DT_WORDBREAK, though I've tried it with and without DT_WORDBREAK with identical results.

Rather than putting a newline in the appropriate place, it instead puts the familiar box that characters look like when no real symbol is supposed to be associated with them. When I use \r\n rather than just \r or \n, it prints two boxes instead of one.

Dachannien at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 6

Well, DrawTextW works just fine under Windows XP using the format you specified. So there is something here not quite working right.

Have you tried a simple Windows program which just draws text. The windows prodecure of the test program I was using was just.

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hDc;
RECT rc = {5, 5, 100, 100};
switch(msg)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
DestroyWindow(hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
hDc = BeginPaint(hWnd, &ps);
DrawText(hDc, TEXT("Hello\r\nWorld...."), 16, &rc, 0);
EndPaint(hWnd, &ps);
return 0;
default:
return DefWindowProc(hWnd, msg, wparam, lparam);
}
}

So I am wondering if you can get a simple program like that running and check if it comes up with the same behaviour then it is the Windows CE DrawText function, otherwise you are experiencing problems somewhere else.

The two rectangles you say is in the text shows that it does have the \r\n in the string, its just something is blocking them using it properly. So we need to try and round out all possible options here.

crescens2k at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 7
As it turns out, apparently DrawText in Windows CE will print the text all on the same line if DT_VCENTER is specified. I was able to solve my own problem by calculating the height of the text to be printed, adjusting the rectangle size appropriately, and omitting the DT_VCENTER specifier from the call to DrawText.

Dachannien at 2007-10-8 > top of Msdn Tech,Visual C++,Visual C++ Language...