the following code should find a windows handle by its window title. Then the program get the DC from this window via GetWindowDC_(hWnd). After this the programm copies a part of the window bitmap of the determined window into a image and display it in a window.
So far so good, but my problem is, that the BitBlt_() function grabs simply what is seen on Desktop. That means, if the desired window is overlaped by another window, then the bitmap of the other windows ist still part of the screenshot. It looks like a 'desktop-screenshot'.
On Windows 7 this works like expected. There I get a screenshot of the desired window, even if it's complete in background and overlapped by other windows.
This drives me crazy. I have no idea what is the reason for the failure on Windows XP SP3 - 32 bits.
Does anyone have an idea?
Code: Select all
EnableExplicit
Structure GrabWindow
sWindowTitle.s
iWindowHandle.i
EndStructure
Global stBrowserWindow.GrabWindow
Global.i iWindow, iCanvas_Screenshot
Procedure.i Settings_FindWindowHandleEnumProc(iWindowHandle.i, lParameter.l)
; +-----------------------------------------------------------------
; |Description : EnumProceduere für Settings_GetWindowHandle()
; |Arguments : lWindowHandle: Enthält das Windowhandle des aktuell enumerierten Fensters
; | : lParameter : Muss die Speicheradresse der Parameter-Struktur enthalten
; |Results : 0, wenn die enumeration gestoppt werden soll, sonst 1
; |Remarks : Siehe auch: https://msdn.microsoft.com/de-de/library/windows/desktop/ms633497(v=vs.85).aspx
; +-----------------------------------------------------------------
Protected.s sTitle=Space(32)
GetWindowText_(iWindowHandle, sTitle, 32)
If FindString(sTitle, stBrowserWindow\sWindowTitle) <> 0
stBrowserWindow\iWindowHandle = iWindowHandle
; Das gesuchte Fenster wurde gefunden, EnumProc nicht weiter aufrufen
ProcedureReturn 0
Else
; Weitere Fenster durchsuchen, EnumProc weiter aufrufen
ProcedureReturn 1
EndIf
EndProcedure
Procedure.l Settings_GetWindowHandle(sWindowTitle.s)
; +-----------------------------------------------------------------
; |Description : Ermittelt das Windowhandle eines Fensters anhand des Fenstertitels
; |Arguments : sWindowTitle: Titel des zu suchenden Fensters
; |Results : Das gesuchte Windowhandle oder 0, wenn das Fenster nicht gefunden wurde
; |Remarks : Es reicht aus, wenn der linke Teil des Fenstertitels angegeben wird.
; | : Z.B.: "PureBasi" -< findet auch das Fenster mit dem Titel "PureBasic 5.50 (x86)"
; +-----------------------------------------------------------------
stBrowserWindow\sWindowTitle = sWindowTitle
If EnumWindows_(@Settings_FindWindowHandleEnumProc(), @stBrowserWindow) = 1
ProcedureReturn 0
Else
ProcedureReturn stBrowserWindow\iWindowHandle
EndIf
EndProcedure
Procedure Grab(sWindowTitle.s)
; +-----------------------------------------------------------------
; |Description : -
; |Arguments : -
; |Results : -
; |Remarks : -
; +-----------------------------------------------------------------
Protected.i iBrowserWindowHandle, iBrowserDC, iCanvasDC
iBrowserWindowHandle = Settings_GetWindowHandle(sWindowTitle)
If iBrowserWindowHandle > 0
iCanvasDC = StartDrawing(CanvasOutput(iCanvas_Screenshot))
If iCanvasDC
iBrowserDC = GetWindowDC_(iBrowserWindowHandle)
If iBrowserDC > 0
BitBlt_(iCanvasDC, 0, 0, 300, 300, iBrowserDC, 0, 0, #SRCCOPY)
ReleaseDC_(iBrowserWindowHandle, iBrowserDC)
EndIf
StopDrawing()
EndIf
EndIf
EndProcedure
iWindow = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 320, 320, "", #PB_Window_SystemMenu|#PB_Window_TitleBar)
If iWindow
iCanvas_Screenshot = CanvasGadget(#PB_Any, 10, 10, 300, 300)
Grab("Neuer Tab") ; <<<---- Type in here the titel of the desired Window
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow