다음 코드를 사용하여 WM_PAINT 메시지 처리기에 많은 선을 그릴 수 있습니다.WM_PAINT에서 드로잉 (너무 느림)으로 인해 깜박임이 발생합니까?
//DrawLine with double buffering
LRESULT CALLBACK CMyDoc::OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
std::vector<Gdiplus::Point> points;
std::vector<Gdiplus::Point>::iterator iter1, iter2;
HDC hdc, hdcMem;
HBITMAP hbmScreen, hbmOldBitmap;
PAINTSTRUCT ps;
RECT rect;
hdc = BeginPaint(hWnd, &ps);
//Create memory dc
hdcMem = CreateCompatibleDC(hdc);
GetClientRect(hWnd, &rect);
hbmScreen = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
hbmOldBitmap = (HBITMAP)SelectObject(hdcMem, hbmScreen);
//Fill the rect with white
FillRect(hdcMem, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
//Draw the lines
Gdiplus::Graphics graphics(hdcMem);
Gdiplus::Pen blackPen(Gdiplus::Color(255, 0, 0));
points = m_pPolyLine->GetPoints();
for (iter1 = points.begin(); iter1 != points.end(); iter1++) {
for (iter2 = iter1 + 1; iter2 != points.end(); iter2++)
graphics.DrawLine(&blackPen, *iter1, *iter2);
}
//Copy the bitmap from memory dc to the real dc
BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);
//Clean up
SelectObject(hdcMem, hbmOldBitmap);
DeleteObject(hbmScreen);
DeleteDC(hdcMem);
EndPaint(hWnd, &ps);
return 0;
}
그러나 포인트의 크기가 20을 초과하면 클라이언트는 단지 깜박입니다. 이유는 Gdiplus :: DrawLines가 너무 느리다는 것입니다.
깜박임 문제를 해결할 방법이 있습니까? 감사합니다. .
는 그것은 hdcMem가 HDC에 직접 연결되지 않는 한, 최종 비트 블리트로 인해 선을 그릴의 "속도"와 관련해서는 안됩니다. 아마도 뭔가 다른 것이있을 것입니다. (예 : BitBlt에서 "눈물") –