Before calling ImageEnView1.IO.CaptureFromScreen(iecsForegroundWindow) is there any API to determine if there is a foreground window?
A question posted at StackOverflow failed to produce any code that works.
I created a work-around for the problem that seems to work, but some windows API would be better.
If you call ImageEnView1.IO.CaptureFromScreen(iecsForegroundWindow) and there is no foreground window a large completely black bitmap is returned. The work-around uses imageen to determine if the dominantcolor of the capturedimage is 100%. If the dominantcolor is 100 then you can display an error message and blank the image.
iPercentage := ImageEnView1.Proc.GetDominantColor(iColor);
//the image is all one color!
if iPercentage = 100 then
begin
ImageEnView1.Blank;
MessageBox(0, 'There is no foreground window.' + #10#13 + 'Make a window the foreground window, then try again.', 'No Active Window', MB_ICONWARNING or MB_OK);
end;
It is also interesting that if there is no foreground window, the ImageEnView1.IO.CaptureFromScreen(iecsForegroundWindowClient) returns a bitmap of the start button on the taskbar.
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html