ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnView1.IO.CaptureFromScreen
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Aug 27 2012 :  13:32:46  Show Profile  Reply
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

w2m

USA
1990 Posts

Posted - Aug 30 2012 :  08:29:25  Show Profile  Reply
No one has any ideas?

William Miller
Go to Top of Page

ehkhalid

27 Posts

Posted - Aug 31 2012 :  00:23:10  Show Profile  Reply
I use another way to detect if a page is blank, I calculcate "standard deviation" it give you if pixels variation is uniform or not, so if it's uniform, it mean image's pixels has the same color.

Hope this help
Go to Top of Page

Uwe

284 Posts

Posted - Aug 31 2012 :  10:23:42  Show Profile  Reply
William, does this help?

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633505%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599%28v=vs.85%29.aspx#foreground

Quote:
"To check if your application window is the foreground window, compare the handle returned by GetForegroundWindow to that of your application window."

Uwe
Go to Top of Page

w2m

USA
1990 Posts

Posted - Aug 31 2012 :  14:13:05  Show Profile  Reply
Uwe,

I am not sure if this will help because I think you have to click on the window to get the correct foreground window.... will investigate this more.

William Miller
Go to Top of Page

fab

1310 Posts

Posted - Sep 03 2012 :  13:39:52  Show Profile  Reply
Hi Bill,
I don't know if this helps. When there isn't a foreground window then GetForegroundWindow should return the same value of GetShellWindow, so you could try:

if GetForegroundWindow() = GetShellWindow() then
...there is no foreground....
Go to Top of Page

w2m

USA
1990 Posts

Posted - Sep 04 2012 :  11:24:59  Show Profile  Reply
Hi Fabrizio,

With Windows 7, GetForegroundWindow = 263058 and GetShellWindow = 65866 when there are no visible windows on the deskup... so the test fails. I think you have to click on the desktop for this to work, but when capturing a clientwindow with ImageEnView1.IO.CaptureFromScreen(iecsForegroundWindow) there is no API to force a mouseclick on the desktop is there?


William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

fab

1310 Posts

Posted - Sep 05 2012 :  10:12:41  Show Profile  Reply
To what window GetForegroundWindow refers returning 263058? Is that "minimized"? In this case you could check the window status (minimized, hided, etc...).
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: