How to determine if Form is obscured.
How to determine if Form is obscured.
(OP)
Hi
I am developing an application in C# .NET which needs to create a bitmap image of a Windows Form, save it to disk and then do some OCR recognition on parts of that screen shot. This is fine and I can do it.
If the window is obscured by another one, then my screen shot may be invalid for the OCR recognition process.
I need to find a way therefore, to determine if some of the window is obscured by another.
I know the Window Handle (IntPtr), its location on the desktop (x,y) and the window size (as RECT)
Any help or inspiration would be gratefully received.
regards
RogerDodge
I am developing an application in C# .NET which needs to create a bitmap image of a Windows Form, save it to disk and then do some OCR recognition on parts of that screen shot. This is fine and I can do it.
If the window is obscured by another one, then my screen shot may be invalid for the OCR recognition process.
I need to find a way therefore, to determine if some of the window is obscured by another.
I know the Window Handle (IntPtr), its location on the desktop (x,y) and the window size (as RECT)
Any help or inspiration would be gratefully received.
regards
RogerDodge
RE: How to determine if Form is obscured.
http://msd
RE: How to determine if Form is obscured.
If so how are you creating the bitmap of the form (and I assume, it's controls)?
HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman
Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers: How to get the best answers before post
RE: How to determine if Form is obscured.
How are you doing that?
RE: How to determine if Form is obscured.
Essentially, I am trying to "scrape" information from the form to then do some look-ups in a database from predetermined areas (fields) on the form.
I have set up some code within a "dummy" form, so when I click a button, I call this code which then gets the handle of itself and then captures the screen from its position, this works fine.
CODE
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
private void cmdOptions_Click(object sender, EventArgs e)
{
RECT rct;
HandleRef lcHnd = new HandleRef(this, this.Handle);
if (!GetWindowRect((IntPtr)lcHnd, out rct))
{
MessageBox.Show("ERROR");
}
else
{
int windowWidth = System.Math.Abs(rct.Right - rct.Left);
int windowHeight = System.Math.Abs(rct.Bottom - rct.Top);
System.Drawing.Bitmap currBMP = new Bitmap(windowWidth, windowHeight);
currBMP = CaptureClip(rct.Left,rct.Top, windowWidth, windowHeight);
currBMP.Save("C:\\OCRSDK\\CaptBMP.bmp");
}
}
The CaptureClip function just "grabs" the defined area from the screen.
I have been exploring the possibilities of using "WindowFromPoint" and "PtInRect" API functions to try to figure something out.
RogerDodge
RE: How to determine if Form is obscured.
RE: How to determine if Form is obscured.
It is how the grabbing is being done that I was asking about. Unfortunately what you have posted show this. And I am not familiar with the CaptureClip function. Is this something that you wrote? And if so, can we see it please?
RE: How to determine if Form is obscured.
strongm - here's the code (for clarity's sake)
(thanks to Danny Battison)
CODE
{
System.Drawing.Bitmap BMP = new Bitmap(width, height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
GFX.CopyFromScreen (x, y, 0, 0, new Size(width, height),
System.Drawing.CopyPixelOperation.SourceCopy);
return BMP;
}
I'm sure I can tidy this code up a bit, but for the moment I just need the principles to work.
My main issue at the moment is to capture the hidden window (normally it wont be hidden but I cant be certain so I need to either trap it or not care - hopefully the PrintWindow will solve it.
RE: How to determine if Form is obscured.
Mike Gagnon
If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.
ReFox XI (www.mcrgsoftware.com)
RE: How to determine if Form is obscured.
RE: How to determine if Form is obscured.
The application(s) which I am trying to "screen scrape" have all (as far as I can make out) been developed with Foxpro9. As a consequence, it seems that I am unable to enumerate any objects on the child forms. In some applications, the relevant information which I am trying to obtain, ie client reference number, is present on the main window title text - I can then just use this information to do a lookup of the appropriate database record.
I will be interested to hear from you.
RE: How to determine if Form is obscured.
Because your CaptureClip-function use the graphic handle of the console-screen (I actually more guess it then I known) I should make/force the window as Top-Level-Window during the capture period.
Or:
I would try to give a repaint-command of the window that you like to capture, but to the canvas of an bitmap instead of those of the Form.