2017-10-08 1 views
0

알림 아이콘에서 풍선 도움말로 찍은 스크린 샷을 자동화하여 응용 프로그램에서 지원하는 다양한 언어의 모양을 쉽게 검증 할 수있었습니다. 문제는 풍선 도움말이 Windows 7의 화면에 표시 되더라도 스크린 샷에 없다는 것입니다.BaloonTip을 포함하는 캡쳐 화면

나는 Capture screenshot of active window?에서 해결책을 시도했습니다.

// From http://www.developerfusion.com/code/4630/capture-a-screen-shot/ 
var sc = new ScreenCapture(); 
trayIcon.ShowBalloonTip(10000, "My Title", "My message", ToolTipIcon.Info); 
Thread.Sleep(2000); // Just to make sure that the balloon tip is shown 
sc.CaptureScreenToFile("MyScreenshot.png", ImageFormat.Png); 

Rectangle bounds = Screen.GetBounds(Point.Empty); 
using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) 
{ 
    using(Graphics g = Graphics.FromImage(bitmap)) 
    { 
     trayIcon.ShowBalloonTip(10000, "My Title", "My message", ToolTipIcon.Info); 
     Thread.Sleep(2000); // Just to make sure that the balloon tip is shown 
     g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); 
    } 
    bitmap.Save("MyScreenshot.png", ImageFormat.Png); 
} 

그러나 모두는 풍선 팁을 표시하지 않고 스크린 샷을 걸릴. 풍선 도움말이 포함 된 스크린 샷을 프로그래밍 방식으로 가져 오는 방법이 있습니까?

보너스 정보 : Windows 10에서 풍선 도움말은 정상적인 알림 시스템에 강제로 들어가고 예상대로이 스크린 샷을 찍습니다.

+1

계층화 된 창. –

+0

@HansPassant 그게 효과가! 귀하의 제안으로이 문제를 해결할 수있는 https://stackoverflow.com/questions/3072349/capture-screenshot-including-semitransparent-windows-in-net 답변을 찾을 수있었습니다. –

답변

1

한스 패전트 (Hans Passant)가 질문에 답하는대로 CopyPixelOperation.CaptureBlt을 사용하는 것이 솔루션의 핵심입니다.

내가 이미 시도한 솔루션에서 작동하지 않았기 때문에 반투명 창을 처리하는 유사한 질문 Capture screenshot Including Semitransparent windows in .NET을 발견했습니다.

모든 -에 - 모든 솔루션 알림 아이콘에서 풍선 팁을 포함 스크린 샷을 날 수 있도록 다음과 같습니다

: 당신은 또한 캡처 할 수 있습니다 있도록 CopyPixelOperation.CaptureBlt를 추가 할 필요가

class ScreenCapture 
{ 
    public void CaptureScreenToFile(string fileName) 
    { 
     Size sz = Screen.PrimaryScreen.Bounds.Size; 
     IntPtr hDesk = GetDesktopWindow(); 
     IntPtr hSrce = GetWindowDC(hDesk); 
     IntPtr hDest = CreateCompatibleDC(hSrce); 
     IntPtr hBmp = CreateCompatibleBitmap(hSrce, sz.Width, sz.Height); 
     IntPtr hOldBmp = SelectObject(hDest, hBmp); 
     bool b = BitBlt(hDest, 0, 0, sz.Width, sz.Height, hSrce, 0, 0, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt); 
     Bitmap bmp = Bitmap.FromHbitmap(hBmp); 
     SelectObject(hDest, hOldBmp); 
     DeleteObject(hBmp); 
     DeleteDC(hDest); 
     ReleaseDC(hDesk, hSrce); 
     bmp.Save(fileName); 
     bmp.Dispose(); 
    } 

    // P/Invoke declarations 
    [DllImport("gdi32.dll")] 
    static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int 
     wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop); 
    [DllImport("user32.dll")] 
    static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc); 
    [DllImport("gdi32.dll")] 
    static extern IntPtr DeleteDC(IntPtr hDc); 
    [DllImport("gdi32.dll")] 
    static extern IntPtr DeleteObject(IntPtr hDc); 
    [DllImport("gdi32.dll")] 
    static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight); 
    [DllImport("gdi32.dll")] 
    static extern IntPtr CreateCompatibleDC(IntPtr hdc); 
    [DllImport("gdi32.dll")] 
    static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp); 
    [DllImport("user32.dll")] 
    public static extern IntPtr GetDesktopWindow(); 
    [DllImport("user32.dll")] 
    public static extern IntPtr GetWindowDC(IntPtr ptr); 
}