Screen capture causes short mouse freeze
Posted on 2002-03-17
I'm having trouble doing a screen capture on Win 2000. (I have not tried Win 98, etc.) I need to do several captures at half-second intervals, but each capture involves the mouse cursor pausing or freezing for a fraction of a second.
I orginally did something like this:
hScreen := GetDC(0);
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, hScreen, 0, 0, SRCCOPY);
The above code causes the mouse to freeze for a fraction of a second. After playing around a bit, I tried the following:
hScrDC := CreateDC('DISPLAY', nil, nil, nil);
hMemDC := CreateCompatibleDC(hScrDC);
hBmp := CreateCompatibleBitmap(hScrDC, Screen.Width, Screen.Height);
hOldBmp := SelectObject(hMemDC, hBmp);
BitBlt(hMemDC, 0, 0, Screen.Width, Screen.Height, hScrDC, 0, 0, SRCCOPY);
hBmp := SelectObject(hMemDC, hOldBmp);
Bmp.Handle := hBmp;
Surprise! No mouse-freeze. But for my application I need the bitmap in both 8- and 24-bit color. As soon as I do Bmp.PixelFormat := pf8bit (or pf24bit) the mouse pauses briefly while the conversion is being done. The pause is short (< 100ms) when converting to 8-bit, and longer (around 300ms) when converting to 24-bit. I find that when converting to a JPEG or calling Bmp.SaveToFile that the mouse also pauses - might be related to PixelFormat???
Therefore, my question is: Does anyone know how to do both 8-bit and 24-bit screen captures on Win 2000, including saving the BMP to disk, WITHOUT the mouse "freezing" briefly?
(P.S. I'm running 16-bit color.)