Why does this TextOut() sometimes hang up?
I tried to make the equivalent of a simple ProgressBar by
displaying a count in the window of the outermost one of
several nested loops. This process is very CPU intensive so
I have to force screen updates. The count works correctly
unless I move the window, and then the window is no longer
updated. What is causing this, and how can I fix it?
// The TextOut() display code inside a very tight loop
ClientArea.TextOut(0, 0, String, strlen(String));
MainWin->InvalidateRect(NULL);
MainWin->UpdateWindow();
// Window member data
CDC ClientArea; // virtual window device context
CBitmap m_bmp; // virtual window bitmap
// Window Constructor
MainWindow::MainWindow()
{
ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
Create(NULL, "SeeScreen the Screen Recognizer",
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, rectDefault,
NULL, "TextMenu");
CClientDC DC(this);
// Create bitmap for virtual window
ClientArea.CreateCompatibleDC(&DC);
m_bmp.CreateCompatibleBitmap(&DC, ScreenWidth,
ScreenHeight);
ClientArea.SelectObject(&m_bmp);
// use standard background
MainBrush.CreateStockObject(WHITE_BRUSH);
ClientArea.SelectObject(&MainBrush);
// paint background of virtual window
ClientArea.PatBlt(0, 0, ScreenWidth, ScreenHeight,
PATCOPY);
}
// Update screen using contents of virtual window.
afx_msg void MainWindow::OnPaint()
{
CPaintDC DC(this);
DC.BitBlt(0, 0, ScreenWidth, ScreenHeight, &ClientArea, 0,
0, SRCCOPY);
}