EDN Admin
Well-known member
Hi
I have some codes to capture screen. These codes basically capture some portion of the image (e.g. height and width) instead of capturing the whole image. My program is basically would like to capture security message. For instance, a dialogue box of "File
Download - Security Warning" (Header) and its context. These codes able to capture the dialogue box without its content. Everytime the program capture the security message (Dialogue box type), it will not be able to capture the header or title of it. I
am not sure how can I amend these codes to ensure that It will be able to capture the dialog box as a whole. Please if anyone could guide me on this.
Thank you so much for your help!
Please refer to the codes
<div style="color:black; background-color:white
<pre><span style="color:blue #region Public Class Functions
<span style="color:blue public <span style="color:blue static Bitmap GetDesktopImage(IntPtr handler)
{
SIZE size;
RECT rect;
IntPtr hBitmap;
<span style="color:green //Here we get the handle to the desktop device context.
<span style="color:green //IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow());
IntPtr hDC = PlatformInvokeUSER32.GetDC(handler);
<span style="color:green //Here we make a compatible device context in memory for screen device context.
IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);
<span style="color:blue bool isSized = PlatformInvokeUSER32.GetWindowRect(handler, <span style="color:blue out rect);
<span style="color:green //if (!isSized) MessageBox.Show("Didnt get rect");
<span style="color:green //We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen.
size.cx = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CXSCREEN);
<span style="color:green //size.cx = rect.right-rect.left;
<span style="color:green //We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen.
size.cy = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CYSCREEN);
<span style="color:green //size.cy = rect.bottom-rect.top;
MessageBox.Show(<span style="color:#a31515 "Handler"+handler.ToString()+<span style="color:#a31515 " Width:"+size.cx.ToString()+<span style="color:#a31515 " Height:"+size.cy.ToString());
<span style="color:green //We create a compatible bitmap of screen size using screen device context.
hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, size.cx, size.cy);
<span style="color:blue if (hBitmap!=IntPtr.Zero)
{
IntPtr hOld = (IntPtr) PlatformInvokeGDI32.SelectObject(hMemDC, hBitmap);
<span style="color:green .
PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY);
PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
PlatformInvokeGDI32.DeleteDC(hMemDC);
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetDesktopWindow(), hDC);
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
PlatformInvokeGDI32.DeleteObject(hBitmap);
GC.Collect();
<span style="color:blue return bmp;
}
<span style="color:blue return <span style="color:blue null;
}
<span style="color:blue #endregion
[/code]
<br/>
<br/>
<
zafi<br/>
View the full article
I have some codes to capture screen. These codes basically capture some portion of the image (e.g. height and width) instead of capturing the whole image. My program is basically would like to capture security message. For instance, a dialogue box of "File
Download - Security Warning" (Header) and its context. These codes able to capture the dialogue box without its content. Everytime the program capture the security message (Dialogue box type), it will not be able to capture the header or title of it. I
am not sure how can I amend these codes to ensure that It will be able to capture the dialog box as a whole. Please if anyone could guide me on this.
Thank you so much for your help!
Please refer to the codes
<div style="color:black; background-color:white
<pre><span style="color:blue #region Public Class Functions
<span style="color:blue public <span style="color:blue static Bitmap GetDesktopImage(IntPtr handler)
{
SIZE size;
RECT rect;
IntPtr hBitmap;
<span style="color:green //Here we get the handle to the desktop device context.
<span style="color:green //IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow());
IntPtr hDC = PlatformInvokeUSER32.GetDC(handler);
<span style="color:green //Here we make a compatible device context in memory for screen device context.
IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);
<span style="color:blue bool isSized = PlatformInvokeUSER32.GetWindowRect(handler, <span style="color:blue out rect);
<span style="color:green //if (!isSized) MessageBox.Show("Didnt get rect");
<span style="color:green //We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen.
size.cx = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CXSCREEN);
<span style="color:green //size.cx = rect.right-rect.left;
<span style="color:green //We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen.
size.cy = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CYSCREEN);
<span style="color:green //size.cy = rect.bottom-rect.top;
MessageBox.Show(<span style="color:#a31515 "Handler"+handler.ToString()+<span style="color:#a31515 " Width:"+size.cx.ToString()+<span style="color:#a31515 " Height:"+size.cy.ToString());
<span style="color:green //We create a compatible bitmap of screen size using screen device context.
hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, size.cx, size.cy);
<span style="color:blue if (hBitmap!=IntPtr.Zero)
{
IntPtr hOld = (IntPtr) PlatformInvokeGDI32.SelectObject(hMemDC, hBitmap);
<span style="color:green .
PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY);
PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
PlatformInvokeGDI32.DeleteDC(hMemDC);
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetDesktopWindow(), hDC);
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
PlatformInvokeGDI32.DeleteObject(hBitmap);
GC.Collect();
<span style="color:blue return bmp;
}
<span style="color:blue return <span style="color:blue null;
}
<span style="color:blue #endregion
[/code]
<br/>
<br/>
<
zafi<br/>
View the full article