JovianGhost
23rd March 2010, 03:11
I'm experimenting with direct painting to device contexts using WINAPI. Here's what my widget's paintEvent function looks like:
void ShotView::paintEvent(QPaintEvent *event)
{
qDebug() << "Start paint function";
HDC hdc = this->getDC();
if (hdc == NULL)
{
qDebug() << "HDC error";
return;
}
qDebug() << "Start painting";
HPEN hPen = CreatePen(PS_SOLID, 4, RGB(0, 255, 0));
if (hPen == NULL)
qDebug() << "CreatePen error";
if (SelectObject(hdc, hPen) == HGDI_ERROR)
qDebug() << "SelectObject error";
if (MoveToEx(hdc, 0, 0, NULL) == 0)
qDebug() << "MoveToEx error";
if (LineTo(hdc, 200, 200) == 0)
qDebug() << "LineTo error";
qDebug() << "End painting";
this->releaseDC(hdc);
qDebug() << "End paint function";
}
When I run the program, I don't see a solid red line appearing as I should. The console output seems correct:
Start paint function
Start painting
End painting
End paint function
so it looks like everything in the function is getting called properly, but I don't see an output. It's been a while since I've done WINAPI stuff, but I think I have it right. Can anyone offer any insight?
void ShotView::paintEvent(QPaintEvent *event)
{
qDebug() << "Start paint function";
HDC hdc = this->getDC();
if (hdc == NULL)
{
qDebug() << "HDC error";
return;
}
qDebug() << "Start painting";
HPEN hPen = CreatePen(PS_SOLID, 4, RGB(0, 255, 0));
if (hPen == NULL)
qDebug() << "CreatePen error";
if (SelectObject(hdc, hPen) == HGDI_ERROR)
qDebug() << "SelectObject error";
if (MoveToEx(hdc, 0, 0, NULL) == 0)
qDebug() << "MoveToEx error";
if (LineTo(hdc, 200, 200) == 0)
qDebug() << "LineTo error";
qDebug() << "End painting";
this->releaseDC(hdc);
qDebug() << "End paint function";
}
When I run the program, I don't see a solid red line appearing as I should. The console output seems correct:
Start paint function
Start painting
End painting
End paint function
so it looks like everything in the function is getting called properly, but I don't see an output. It's been a while since I've done WINAPI stuff, but I think I have it right. Can anyone offer any insight?