我正在尝试在 Rad Studio Seatle CBuilder 10 中编译以下代码片段。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HPEN hpen, hpenOld;
HBRUSH hbrush, hbrushOld;
HDC hdc = this->Canvas->Handle;
// Red pen for the border
hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
// Blue brush for the interior.
hbrush = CreateSolidBrush(RGB(0, 0, 255));
// Select the new pen and brush then draw a rectangle.
hpenOld = SelectObject(hdc, hpen);
hbrushOld = SelectObject(hdc, hbrush);
Rectangle(hdc, 100,100, 400,250);
// After using your objects, delete them and restore the originals
SelectObject(hdc, hpenOld);
DeleteObject(hpen);
SelectObject(hdc, hbrushOld);
DeleteObject(hbrush);
}
但无法编译该行并显示错误消息。
hpenOld = SelectObject(hdc, hpen);
[bcc32 错误] Unit1.cpp(132):E2034 无法将“void *”转换为“HPEN__ *”完整解析器上下文 Unit1.cpp(121):解析:void _fastcall TForm1::Button1Click(TObject *)
我可以在“c++ builder 6”中成功编译这个源代码。
我还检查了 CBuilder 6 和 Cbuilder 10 中的 SelectObject 函数声明
CBuilder 6 声明(wingdi.h)
WINGDIAPI HGDIOBJ WINAPI SelectObject(IN HDC, IN HGDIOBJ);
CBuilder 10 声明(wingdi.h)
WINGDIAPI HGDIOBJ WINAPI SelectObject(_In_ HDC hdc, _In_ HGDIOBJ h);
我没看到有什么不同。
我有什么问题。
谢谢。