DT_CALCRECT标志导致我的文字消失 [英] the DT_CALCRECT flag causes my text to dissappear

查看:112
本文介绍了DT_CALCRECT标志导致我的文字消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在winapi中使用DrawText()函数,以便当文本在矩形之外增长时该函数将自动插入一个分词符,并随着文本中的行数而垂直地增长和缩小.当我设置DT_WORDBREAK时,它可以正确执行工作,但是当我在其旁边设置DT_CALCRECT时,所有文本都会消失.任何帮助将不胜感激.

i''m trying to use the DrawText() function in winapi so that the function will automatically insert a word break when the text grows outside the rectangle, as well as grow and shrink vertically with the number of lines in my text. When i set DT_WORDBREAK, it does it''s job correctly, but when i set DT_CALCRECT next to it, all text disappears. any help would be appreciated.

LRESULT CALLBACK printout(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	static PAINTSTRUCT paint;
	static RECT textbox;
	static LPCTSTR blah = "this is a testing string with a bunch of insignifigant words that are for testing purposes only";

	switch(msg)
	{
		case WM_CLOSE:
		{
                        DestroyWindow(hwnd);
			break;
		}
                case WM_DESTROY:
		{
			PostQuitMessage(0);
			break;
		}
		case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &paint);

				SelectObject(hdc, hFont);
				SetRect(&textbox, 20, 20, 373, 60);
				DrawText(hdc, blah, strlen(blah), &textbox, DT_WORDBREAK | DT_CALCRECT );

			EndPaint(hwnd, &paint);
			break;
		}
		default:
                        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

推荐答案

您是否看到了以下讨论:http://www.codeguru.com/forum/archive/index.php/t-311264.html [
Did you see this discussion: http://www.codeguru.com/forum/archive/index.php/t-311264.html[^]? Looks like a known problem.

—SA


那是什么问题?传递DT_CALCRECT标志时,功能ISN''T应该实际绘制文本.它应该计算出显示它所需要的矩形-因此标记的隐名-DT_CALCRECT.

答案全在文档中,我建议您仔细看一下:
绘制文本功能(windows) [
So what''s the problem? When the DT_CALCRECT flag is passed, the function ISN''T supposed to actually draw the text. It''s supposed to er, calculate the rect that will be needed to display it in - hence the cryptic name of the flag - DT_CALCRECT.

The answer is all in the documentation, I''d suggest you take a closer look:
Draw Text function(windows)[^]


这篇关于DT_CALCRECT标志导致我的文字消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆