在C ++中使用FillRect() [英] Using FillRect() in C++
本文介绍了在C ++中使用FillRect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是在Visual C ++中使用图形的新手。我只是想做一个填充颜色的矩形。需要帮助来解决这个问题...
RECT rect;
HDC hdc;
hdc = CreateDC(TEXT(DISPLAY),NULL,NULL,NULL);
rect.left = 30;
rect.right = 100;
rect.top = 50;
rect.bottom = 200;
FillRect(hdc,& rect,(HBRUSH)(RGB(40,151,151)));
错误是:
ERROR:变量'rect'正在被使用而未被初始化。
解决方案
这通常是一个警告,而不是一个错误。在这种情况下,它似乎也是虚假的。
如果您初始化它,可能会更好:
HDC hdc = CreateDC(TEXT(DISPLAY),NULL,NULL,NULL);
RECT rect = {30,50,100,200};
HBRUSH brush = CreateSolidBrush(RGB(50,151,151));
FillRect(hdc,&rect,brush);
DeleteObject(brush);
请注意使用 CreateSolidBrush
- 将颜色投射到HBRUSH似乎不太可能。
I am new to using Graphics in Visual C++. I am just trying to make a rectangle filled with a color. Need help to correct this...
RECT rect;
HDC hdc;
hdc=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
rect.left=30;
rect.right=100;
rect.top=50;
rect.bottom=200;
FillRect(hdc,&rect,(HBRUSH)(RGB(40,151,151)));
The error is:
ERROR: The variable 'rect' is being used without being initialized.
解决方案
This will normally be a warning, not an error. In this case, it also appears to be spurious.
It might work better if you initialize it something like:
HDC hdc=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
RECT rect = {30, 50, 100, 200};
HBRUSH brush = CreateSolidBrush(RGB(50, 151, 151));
FillRect(hdc, &rect, brush);
DeleteObject(brush);
Do note the use of CreateSolidBrush
-- casting a color to an HBRUSH seems unlikely to work.
这篇关于在C ++中使用FillRect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文