2012-09-08 3 views
0

가능한 중복 : 나는 WINAPI에 작은 데스크탑 프로그램 일하고
Programmatically get screenshot of pageWindows 응용 프로그램은

  1. 내가 원하는 응용 프로그램이다 일부 버튼이있는 텍스트 상자가 있습니다. 사용자는 텍스트 상자에 문자열을 입력하고 검색 버튼을 누를 수 있습니다.

  2. 그 프로그램은 google에서 해당 문자열을 검색하고 검색 결과 페이지를 이미지 파일로 저장합니다.이 작업은 백그라운드에서 새 창이 열리지 않고 수행됩니다.

그리고 이것은 VB와 같은 다른 프로그래밍 언어로 쉽게 할 또는 할 수있는 경우 의견을주십시오 C# 또는 MFC

+0

http://stackoverflow.com/questions/1981670/programmatically-get-screenshot -of-page – aiodintsov

답변

0
string filename = Application.StartupPath + "\\abc.Png"; 
     int width = -1; 
     int height = -1; 

     WebBrowser wb = new WebBrowser(); 
     wb.ScriptErrorsSuppressed = true; 
     wb.Navigate("http://www.google.com/search?q=" + txtSearch.Text); 
     while (wb.ReadyState != WebBrowserReadyState.Complete) 
     { 
      Application.DoEvents(); 
     } 


     // Set the size of the WebBrowser control 
     wb.Width = width; 
     wb.Height = height; 

     if (width == -1) 
     { 
      // Take Screenshot of the web pages full width 
      wb.Width = wb.Document.Body.ScrollRectangle.Width; 
     } 

     if (height == -1) 
     { 
      // Take Screenshot of the web pages full height 
      wb.Height = wb.Document.Body.ScrollRectangle.Height; 
     } 

     // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control 
     Bitmap bitmap = new Bitmap(wb.Width, wb.Height); 
     wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); 
     wb.Dispose(); 

     bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png); 
     MessageBox.Show("Image Saved");