I tried to use a code snipped by idle:
viewtopic.php?f=13&t=70444&start=28
Code: Select all
EnableExplicit
Enumeration
#Win1
#Win2
EndEnumeration
Enumeration
#ImgG1
#ImgG2
EndEnumeration
Enumeration
#cImg1
#cImg2
EndEnumeration
#CAPTUREBLT = $40000000
Define Event, Quit
Procedure CapWindow(Win)
; Screenshot by idle
; https://www.purebasic.fr/english/viewtopic.php?f=13&t=70444&start=28
Protected Rect.rect
Protected SrcDc, DestDc, Result, W, H, hwnd
Debug "Enter CapWindow("+Win+")"
hwnd=WindowID(Win):Debug "hwnd="+hwnd
If hwnd
SrcDc = GetDC_(0):Debug "SrcDC="+SrcDc
If SrcDc
GetWindowRect_(Hwnd,@Rect)
W = Rect\Right-Rect\Left :Debug "W="+w
H = Rect\Bottom - Rect\Top :Debug "H="+h
If W And H
CreateImage(#cImg1,W,H, 32)
If IsImage(#cImg1) :Debug "#Img1 created"
DestDc = StartDrawing(ImageOutput(#cImg1)):Debug "DestDC="+DestDc
If DestDc
Result = BitBlt_(DestDc,0,0,W,H,Srcdc,Rect\Left,Rect\Top,#SRCCOPY | #CAPTUREBLT):Debug "Result="+Result
If Result
Debug "GrabImage="+GrabImage(#cImg1, #cImg2, 0, 0, W, H); fails
; Debug "CopyImage="+CopyImage(#cImg1, #cImg2); fails too
ProcedureReturn IsImage(#cImg2)
EndIf
StopDrawing()
EndIf
EndIf
EndIf
EndIf
EndIf
EndProcedure
Procedure Key()
Debug "Enter Key()"
If CapWindow(#Win1)
SetGadgetState(#ImgG2, ImageID(#cImg2))
SetClipboardImage(#cImg2)
ShowLibraryViewer("Image",#ImgG2)
EndIf
EndProcedure
Procedure MakeImg1()
CreateImage(#cImg1, 640, 480, 32)
StartDrawing(ImageOutput(#cImg1))
Circle(320, 240, 100, $0000FF)
StopDrawing()
SetGadgetState(#Win1, ImageID(#cImg1))
EndProcedure
ClearClipboard()
OpenWindow(#Win1, 10, 10, 640, 480, "W1")
ImageGadget(#ImgG1, 0, 0, WindowWidth(#Win1), WindowHeight(#Win1), 0)
OpenWindow(#Win2, 640, 480, 640, 480, "W2")
ImageGadget(#ImgG2, 0, 0, WindowWidth(#Win2), WindowHeight(#Win2), 0)
SetActiveWindow(#Win1)
AddKeyboardShortcut(#Win1, #PB_Shortcut_Alt|#PB_Shortcut_P, 1)
BindEvent(#PB_Event_Menu, @Key(), #Win1)
MakeImg1()
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
#cImg1 is present and valid as seen with ShowLibrary() but #cImg2 is not.
I always got an empty image as #cImg2 back.
What is going on here?