jeudi 17 avril 2014

c# capture le contenu de la fenêtre sans frontières - Stack Overflow


I have to capture content and only content of one window. Like that:



(captured by ScreenCaptor)


But my program captures that:



I use this code:


IntPtr ParenthWnd = GetForegroundWindow();
if (!ParenthWnd.Equals(IntPtr.Zero))
{
IntPtr prevChild = IntPtr.Zero;
IntPtr currChild = IntPtr.Zero;
while (true)
{
currChild = FindWindowEx(ParenthWnd, prevChild, null, null);
if (currChild == IntPtr.Zero) break;
result.Add(currChild);
label3.Text += currChild.ToString() + " _ ";
prevChild = currChild;
}
}

then I choose my child window, e.g:


handle = result[0];

and finally capture screenshot:


RECT rect = new RECT();
GetWindowRect(handle, ref rect);

Bitmap image = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top);

using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hDC = graphics.GetHdc();
PrintWindow(new HandleRef(graphics, handle), hDC, 0);
graphics.ReleaseHdc(hDC);
}

of course I cannot crop captured image, because don't know size of each 'border'


thanks in advance



I have to capture content and only content of one window. Like that:



(captured by ScreenCaptor)


But my program captures that:



I use this code:


IntPtr ParenthWnd = GetForegroundWindow();
if (!ParenthWnd.Equals(IntPtr.Zero))
{
IntPtr prevChild = IntPtr.Zero;
IntPtr currChild = IntPtr.Zero;
while (true)
{
currChild = FindWindowEx(ParenthWnd, prevChild, null, null);
if (currChild == IntPtr.Zero) break;
result.Add(currChild);
label3.Text += currChild.ToString() + " _ ";
prevChild = currChild;
}
}

then I choose my child window, e.g:


handle = result[0];

and finally capture screenshot:


RECT rect = new RECT();
GetWindowRect(handle, ref rect);

Bitmap image = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top);

using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hDC = graphics.GetHdc();
PrintWindow(new HandleRef(graphics, handle), hDC, 0);
graphics.ReleaseHdc(hDC);
}

of course I cannot crop captured image, because don't know size of each 'border'


thanks in advance


0 commentaires:

Enregistrer un commentaire