Okay so I wont to output text onto my win32 program. I read somewhere that TextOut() is the function i need but it is not as good as DrawText(); Ive been trying to use DrawText() but i get stuck at the 4 parameter asking for a RECT. Any help ? im Using VS2010

void paintWindow(HWND hWnd) {
	HDC hdc = GetDC(hWnd);
    char szSize[100];
    char szTitle[] = "These are the dimensions of your client area:";

    SetTextColor(hdc, COLORREF RGB (20, 13, 20));

	LPRECT rect;
	GetClientRect(hWnd, rect);

    DrawText(hdc, (LPCWSTR) szTitle, -1, /*NEED HELP HERE*/, DT_WORDBREAK);
}

Recommended Answers

All 5 Replies

The reference for the DrawText function says it's a pointer to a RECT structure,
http://msdn.microsoft.com/en-us/library/dd162498%28v=vs.85%29.aspx

The reference for the RECT structure says it's four LONG variables,
http://msdn.microsoft.com/en-us/library/dd162897%28v=vs.85%29.aspx

So you can make a RECT like this:

RECT drawingArea;
memset(&drawingArea, 0, sizeof(RECT));
drawingArea.top = 0;
drawingArea.left = 0;
drawingArea.right = 150;
drawingArea.bottom = 150;

then use a rectangle with the function like this:

DrawText( hdc, (LPCWSTR) szTitle, -1, &drawingArea, DT_WORDBREAK );

You must pass 'rect' by reference at line 9.

GetClientRect (hwnd,&rect);

The parameter is a pointer, so send it either a pointer to a valid RECT or the address of an automatic variable.

HEy thanks guys it works. but now i got annoying screen flickers. Whats up with that? Oh and if i do (LPCWSTR) i get chinese letters
=.=

That is the Unicode equivalent of char wchar_t. Use LPSTR for ASCII.And post some more code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.