This code demonstrates how to capture windows, and also inactive windows on windowsXP.
Best regards
Wolf
Code: Select all
; PureBasic-Lounge.de
; Author: Hroudtwolf
; Date: 04. November 2007
; OS: Windows
; Demo: No
Prototype.l pPrintWindow(hWnd.l, hDc.l, lFlags.l)
Define .l hLib = OpenLibrary(#PB_Any , "user32.dll")
Define .pPrintWindow PrintWindow_ = GetFunction(hLib , "PrintWindow")
Procedure CreateWndSnapshot (hWnd.l)
Protected hdc .l = GetWindowDC_(hWnd)
Protected RC .RECT
Protected hBitmap .l
Shared PrintWindow_
If Not hdc
ProcedureReturn #Null
EndIf
hdcMem = CreateCompatibleDC_(hdc)
If Not hdcMem
ProcedureReturn #Null
EndIf
GetWindowRect_(hWnd, RC)
hBitmap = CreateCompatibleBitmap_(hdc, RC\right , RC\bottom)
If Not hBitmap
ProcedureReturn #Null
EndIf
SelectObject_(hdcMem, hBitmap)
PrintWindow_(hwnd, hdcMem, 0)
DeleteObject_(hdcMem)
ProcedureReturn hBitmap
EndProcedure
If OpenWindow(0, 0, 0, 1024 , 30, "Window in a box", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
ImageGadget(0, 0, 0, 1024 , 30, CreateWndSnapshot (FindWindow_("Shell_TrayWnd", #Null)))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf