Seite 1 von 1

Screenshot vom Fenster

Verfasst: 27.09.2009 02:57
von Programie
Hi,

Wie kann man von einem Fenster, von welchem ich die WindowID habe, ein Screenshot machen?
Mit den Funktionen vom CodeArchiv auf PureArea.net hab ich es schon versucht, aber da fehlt immer die Titelleiste und das Menü. /:->

Kennt jemand eine bessere Lösung?

Re: Screenshot vom Fenster

Verfasst: 27.09.2009 09:10
von Kai
Hier mal meine Procedure mit der du entweder vom gesamten Desktop oder vom aktuellen Fenster ein Screenshot machen kannst.
Musst du ja nicht viel anpassen.

Code: Alles auswählen

Procedure DesktopScreenshot(ImagePath$, Curr = 0, Format = #PB_ImagePlugin_BMP)
  Protected iImage.i, iDC.i, iDesktopDC.i, iForegroundWin, R.RECT, iResult.i
  Protected X.i, Y.i, Width.i, Height.i
  
  If Curr
    iForegroundWin = GetForegroundWindow_()
    If GetWindowRect_(iForegroundWin, @R)
      X      = R\left
      Y      = R\top
      Width  = R\right - R\left
      Height = R\bottom - R\top
    EndIf
    If X < 0 Or Y < 0
      X = 0
      Y = 0
      Width  = GetSystemMetrics_(#SM_CXSCREEN)
      Height = GetSystemMetrics_(#SM_CYSCREEN)
    EndIf
  Else
    X      = 0
    Y      = 0
    Width  = GetSystemMetrics_(#SM_CXSCREEN)
    Height = GetSystemMetrics_(#SM_CYSCREEN)
  EndIf
  
  If Trim(ImagePath$) <> ""
    iImage = CreateImage(#PB_Any, Width, Height)
    If iImage <> 0
      iDC = StartDrawing(ImageOutput(iImage))
      If iDC
        iDesktopDC = GetDC_(GetDesktopWindow_())
        BitBlt_(iDC, 0, 0, Width, Height, iDesktopDC, X, Y, #SRCCOPY)
        StopDrawing()
        ReleaseDC_(GetDesktopWindow_(), iDesktopDC)
      EndIf
      If SaveImage(iImage, ImagePath$, Format)
        iResult = 1
      EndIf
    Else
      iResult = -1
    EndIf
  Else
    iResult = 0
  EndIf
  
  ProcedureReturn iResult
EndProcedure 

Re: Screenshot vom Fenster

Verfasst: 27.09.2009 13:11
von Programie
Danke das funktioniert (fast). ;)

Es gibt aber ein kleines Problem: Bei maximierten Fenstern sieht man auch die Taskleiste.

Re: Screenshot vom Fenster

Verfasst: 27.09.2009 20:21
von Kai

Code: Alles auswählen

Procedure Window_Screenshot(Window, ImagePath$)
  If IsWindow(Window) Or IsWindow_(Window) And ImagePath$
    If IsWindow(Window)
      Window = WindowID(Window)
    EndIf
    
    Protected iDesktopDC.i, iDC.i
    Protected iImage.i
    Protected R.RECT
    
    GetWindowRect_(Window, @R)
    
    If R\left < 0
      R\right + R\left
      R\left = 0
    EndIf
    If R\top < 0
      R\bottom + R\top
      R\top = 0
    EndIf
    
    iImage = CreateImage(#PB_Any, R\right - R\left, R\bottom - R\top)
    If iImage
      
      iDC = StartDrawing(ImageOutput(iImage))
      If iDC
        iDesktopDC = GetDC_(GetDesktopWindow_())
        BitBlt_(iDC, 0, 0, R\right - R\left, R\bottom - R\top, iDesktopDC, R\left, R\top, #SRCCOPY)
        StopDrawing()
        ReleaseDC_(GetDesktopWindow_(), iDesktopDC)
      EndIf
      
      SaveImage(iImage, ImagePath$)
    EndIf
  EndIf
EndProcedure