Click here to Skip to main content
15,860,859 members
Home / Discussions / C#
   

C#

 
GeneralRe: Filter HTML Content Before Displaying in WebBrowser Pin
John Hurrell24-Sep-02 4:59
John Hurrell24-Sep-02 4:59 
GeneralRe: Filter HTML Content Before Displaying in WebBrowser Pin
Stephane Rodriguez.24-Sep-02 5:43
Stephane Rodriguez.24-Sep-02 5:43 
GeneralComponents Pin
Jinwah24-Sep-02 2:45
Jinwah24-Sep-02 2:45 
GeneralRe: Components Pin
Nick Parker24-Sep-02 2:50
protectorNick Parker24-Sep-02 2:50 
GeneralRe: Components Pin
Paul Riley24-Sep-02 3:09
Paul Riley24-Sep-02 3:09 
QuestionDoes anyone know how to capture screen in C#? Pin
Li-kai Liu (Angus)24-Sep-02 2:19
Li-kai Liu (Angus)24-Sep-02 2:19 
AnswerRe: Does anyone know how to capture screen in C#? Pin
leppie24-Sep-02 3:53
leppie24-Sep-02 3:53 
AnswerRe: Does anyone know how to capture screen in C#? Pin
Philip Fitzsimons24-Sep-02 3:54
Philip Fitzsimons24-Sep-02 3:54 
try this...
  public Bitmap CaptureWindow(string windowTitle)<br />
  {<br />
   RECT rect = new RECT();<br />
   IntPtr windowDC;<br />
   IntPtr dc1;<br />
   IntPtr hWnd;<br />
<br />
   // get the window device context for drawing<br />
   if (windowTitle == null)<br />
   {<br />
    hWnd = FindWindow(null, "DISPLAY");<br />
    // get Win32 handle - must be free'ed later<br />
    windowDC = GetWindowDC(hWnd);<br />
    // window is size of screen<br />
    rect.right = Screen.PrimaryScreen.Bounds.Width;<br />
    rect.bottom = Screen.PrimaryScreen.Bounds.Height;<br />
   }<br />
   else<br />
   {<br />
    hWnd = FindWindow(null, windowTitle);<br />
    // get Win32 handle - must be free'ed later<br />
    windowDC = GetWindowDC(hWnd);<br />
    // work out size of window<br />
    int returnCode = GetWindowRgnBox(hWnd, ref rect);<br />
   }<br />
<br />
   // create a bitmap to hold the picture<br />
   Graphics g1 = Graphics.FromHdc(windowDC);<br />
   Bitmap MyImage = new Bitmap(rect.right, rect.bottom, g1);<br />
   Graphics g2 = Graphics.FromImage(MyImage);<br />
<br />
   // get the device contexts<br />
   dc1 = g1.GetHdc();<br />
   IntPtr dc2 = g2.GetHdc();<br />
<br />
   // ask Win32 to copy the bitmap on the screen to our bitmap<br />
   BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376);<br />
<br />
   // give back the handles<br />
   g1.ReleaseHdc(dc1);<br />
   g2.ReleaseHdc(dc2);<br />
  <br />
   // free up Win32 handle<br />
   ReleaseDC(hWnd, windowDC);<br />
<br />
   return MyImage;<br />
  }<br />
<br />
  [DllImportAttribute("gdi32.dll")]<br />
  private static extern bool BitBlt(<br />
   IntPtr hdcDest, // handle to destination DC<br />
   int nXDest,  // x-coord of destination upper-left corner<br />
   int nYDest,  // y-coord of destination upper-left corner<br />
   int nWidth,  // width of destination rectangle<br />
   int nHeight, // height of destination rectangle<br />
   IntPtr hdcSrc,  // handle to source DC<br />
   int nXSrc,   // x-coordinate of source upper-left corner<br />
   int nYSrc,   // y-coordinate of source upper-left corner<br />
   System.Int32 dwRop  // raster operation code<br />
   );<br />
<br />
  [DllImportAttribute("gdi32.dll")]<br />
  private static extern IntPtr  CreateDC(<br />
   string lpszDriver,        // driver name<br />
   string lpszDevice,        // device name<br />
   string lpszOutput,        // not used; should be NULL<br />
   IntPtr lpInitData // optional printer data<br />
   );<br />
<br />
  [DllImportAttribute("User32.dll")]<br />
  private static extern IntPtr  FindWindow(<br />
   string lpClassName,        // class name<br />
   string lpWindowName        // window name<br />
   );<br />
<br />
  [DllImportAttribute("User32.dll")]<br />
  private static extern IntPtr  GetWindowDC(<br />
   IntPtr hWnd  // handle to window<br />
   );<br />
  <br />
  [DllImportAttribute("User32.dll")]<br />
  private static extern IntPtr  ReleaseDC(<br />
   IntPtr hWnd,  // handle to window<br />
   IntPtr hdc   // handle to the DC<br />
   );<br />
<br />
  [StructLayout(LayoutKind.Sequential)]<br />
  struct RECT<br />
  {<br />
   public Int32 left; <br />
   public Int32 top; <br />
   public Int32 right; <br />
   public Int32 bottom; <br />
  }<br />
<br />
  [System.Runtime.InteropServices.DllImportAttribute("User32.dll")]<br />
  private static extern int  GetWindowRgnBox(<br />
   IntPtr hWnd,  // handle to window<br />
   ref RECT rect // rectangle<br />
   );






"When the only tool you have is a hammer, a sore thumb you will have."

GeneralRe: Does anyone know how to capture screen in C#? Pin
leppie24-Sep-02 4:06
leppie24-Sep-02 4:06 
GeneralRe: Does anyone know how to capture screen in C#? Pin
Philip Fitzsimons24-Sep-02 4:34
Philip Fitzsimons24-Sep-02 4:34 
GeneralRe: Does anyone know how to capture screen in C#? Pin
leppie24-Sep-02 6:37
leppie24-Sep-02 6:37 
GeneralRe: Does anyone know how to capture screen in C#? Pin
Li-kai Liu (Angus)24-Sep-02 11:45
Li-kai Liu (Angus)24-Sep-02 11:45 
GeneralRe: Does anyone know how to capture screen in C#? Pin
leppie24-Sep-02 13:42
leppie24-Sep-02 13:42 
GeneralRe: Does anyone know how to capture screen in C#? Pin
Li-kai Liu (Angus)24-Sep-02 11:41
Li-kai Liu (Angus)24-Sep-02 11:41 
GeneralRe: Does anyone know how to capture screen in C#? Pin
Li-kai Liu (Angus)24-Sep-02 15:16
Li-kai Liu (Angus)24-Sep-02 15:16 
GeneralRe: Does anyone know how to capture screen in C#? Pin
Philip Fitzsimons24-Sep-02 23:19
Philip Fitzsimons24-Sep-02 23:19 
GeneralRe: Filter HTML Content Before Displaying in WebBrowser Pin
John Hurrell24-Sep-02 5:52
John Hurrell24-Sep-02 5:52 
GeneralRe: Filter HTML Content Before Displaying in WebBrowser Pin
Stephane Rodriguez.24-Sep-02 6:00
Stephane Rodriguez.24-Sep-02 6:00 
GeneralWhen to define interfaces Pin
afronaut23-Sep-02 9:02
afronaut23-Sep-02 9:02 
GeneralRe: When to define interfaces Pin
Stephane Rodriguez.23-Sep-02 9:22
Stephane Rodriguez.23-Sep-02 9:22 
GeneralRe: When to define interfaces Pin
jan larsen24-Sep-02 0:55
jan larsen24-Sep-02 0:55 
GeneralRe: When to define interfaces Pin
John Burton24-Sep-02 3:48
John Burton24-Sep-02 3:48 
GeneralRe: When to define interfaces Pin
leppie24-Sep-02 4:01
leppie24-Sep-02 4:01 
GeneralRe: When to define interfaces Pin
Paul Riley24-Sep-02 4:18
Paul Riley24-Sep-02 4:18 
GeneralRe: When to define interfaces Pin
Paul Riley24-Sep-02 4:12
Paul Riley24-Sep-02 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.