Page 1 of 1
capture gadget; 64bit;
Posted: Wed May 23, 2018 7:34 am
by HanPBF
Hello!
Due to the antivirus problem, I've switched to PureBasic 64bit which does not trigger false positive at my site.
This code does not work anymore:
Code: Select all
procedure captureGadget(Gadget)
var listrect .RECT
var width
var height
var hdc
GetWindowRect_(GadgetID(Gadget), @listrect.RECT)
width = listrect\right - listrect\left
height = listrect\bottom - listrect\top
CreateImage(0, width, height, 24)
hdc = StartDrawing(ImageOutput(0))
PrintWindow_(GadgetID(Gadget), hdc, #Null)
StopDrawing()
endProcedure
The function PrintWindow_ is not found; it's called "Win32" for a reason...
What can I do?
Really apreciate any hint!
Thanks a lot!
Regards
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 8:17 am
by Dude
[Deleted, can't do what I planned]
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 8:21 am
by RSBasic
HanPBF wrote:Code: Select all
ar listrect .RECT
var width
var height
var hdc
"var" for variable definition? Do you use a macro? And why?
HanPBF wrote:This code does not work anymore:
It works with this code:
https://www.rsbasic.de/aktualisierung/w ... stellen.pb
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 8:39 am
by RASHAD
Hi HanPBF
Try
Code: Select all
Procedure captureGadget(Gadget)
; var listrect .RECT
; var width
; var height
; var hdc
GetWindowRect_(GadgetID(Gadget), @listrect.RECT)
width = listrect\right - listrect\left
height = listrect\bottom - listrect\top
CreateImage(0, width, height, 24)
hdc = StartDrawing(ImageOutput(0))
;PrintWindow(GadgetID(Gadget), hdc, #Null)
SendMessage_(GadgetID(Gadget),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
StopDrawing()
EndProcedure
OpenWindow(1, 0, 0, 200, 200, "Capture Gadget", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ButtonGadget(1,10,10,60,60,"TEST")
captureGadget(1)
ImageGadget(2, 10, 100, 60,60,ImageID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 9:11 am
by HanPBF
Damned! Did not check the source.
Yes, var is a macro for protected; I have as resident in PureBasic directory.
Thanks a lot for the sources and the link!!!
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 9:48 am
by Kwai chang caine
A very good way for clone false button
Thanks to HanPBF and RASHAD
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 12:19 pm
by HanPBF
"var" for variable definition? Do you use a macro? And why?
I also use ret for procedureReturn.
When using auto complete, names get upper case, so ProcedureReturn instead of as I like procedureReturn.
Not very important, but annoying.
As I like one variable per line this is very much source
Code: Select all
protected x
protected y
protected w
protected h
I use
Ok, of course I would prefer:
Code: Select all
protected ;(or local or var)
x
y
w
h
endProtected ;(or endLocal or endVar)
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 12:23 pm
by Bisonte
And here RASHAD's procedure to use it also in other codes
Code: Select all
Procedure CaptureGadgetImage(Gadget, Image = #PB_Any)
Protected ID, Width, Height, hDC, hWnd, rect.RECT
If IsGadget(Gadget)
hWnd = GadgetID(Gadget)
GetWindowRect_(hWnd, @rect)
Width = rect\right - rect\left
Height = rect\bottom - rect\top
ID = CreateImage(Image, Width, height, 24)
If Image = #PB_Any : Image = ID : EndIf
If IsImage(Image)
hDC = StartDrawing(ImageOutput(Image))
If hDC
SendMessage_(hWnd, #WM_PRINT, hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
StopDrawing()
EndIf
EndIf
EndIf
ProcedureReturn ID
EndProcedure
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 12:38 pm
by RSBasic
@HanPBF
Thank you very much for information.
Re: capture gadget; 64bit;
Posted: Wed May 23, 2018 12:38 pm
by RASHAD
Hi guys
Add to collection
Code: Select all
Procedure CaptureGadget(par)
GetWindowRect_(GadgetID(par), @listrect.RECT)
width = listrect\right-listrect\left
height = listrect\bottom-listrect\top
CreateImage(0, width, height, 24)
hdc = StartDrawing(ImageOutput(0))
BitBlt_(hdc,0,0,width,height, GetDC_(0),listrect\left,listrect\top,#SRCCOPY)
StopDrawing()
SetGadgetState(2,ImageID(0))
;ClearClipboard()
;SetClipboardImage(0)
EndProcedure
If OpenWindow(0,0,0,400,400,"Window",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ListIconGadget(1,10,10,WindowWidth(0)-20,100,"Spalte 1",240,0)
AddGadgetColumn(1,1,"Spalte 2",220)
AddGadgetItem(1,-1,"Item 1"+Chr(10)+"Item 1",0,0)
AddGadgetItem(1,-1,"Item 2"+Chr(10)+"Item 2",0,0)
AddGadgetItem(1,-1,"Item 3"+Chr(10)+"Item 3",0,0)
ImageGadget(2,10,200,0,0,0,0)
Delay(200)
CreateThread(@CaptureGadget(), 1)
Repeat
EventID=WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
End
EndIf
ForEver
EndIf
Re: capture gadget; 64bit;
Posted: Fri Feb 08, 2019 2:24 pm
by RASHAD
Hi mohsen
The WM_PRINT message is sent To a window To request that it draw itself in the specified device context,most commonly in a printer device context.
The BitBlt function performs a bit-block transfer of the color Data corresponding To a rectangle of pixels from the specified source device context into a destination device context.
Code: Select all
Procedure captureGadget(Gadget)
GetWindowRect_(GadgetID(Gadget), @listrect.RECT)
width = listrect\right - listrect\left
height = listrect\bottom - listrect\top
CreateImage(0, width,height, 24)
hdc = StartDrawing(ImageOutput(0))
ResizeGadget(3,10,10,10,10)
SetWindowLongPtr_( GadgetID(3), #GWL_HWNDPARENT,GadgetID(1))
SendMessage_(GadgetID(1),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
SetWindowLongPtr_( GadgetID(3), #GWL_HWNDPARENT,WindowID(1))
ResizeGadget(3,20,20,10,10)
UpdateWindow_(GadgetID(1))
StopDrawing()
SetGadgetState(2,ImageID(0))
EndProcedure
Procedure CaptureGadget1(par)
CreateImage(50, 60, 60, 24)
hdc = StartDrawing(ImageOutput(50))
BitBlt_(hdc,0,0,60,60, GetDC_(GadgetID(par)),0,0,#SRCCOPY)
StopDrawing()
SetGadgetState(4,ImageID(50))
EndProcedure
OpenWindow(1, 0, 0, 200, 200, "Capture Gadget", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ButtonGadget(1,10,10,60,60,"TEST")
CanvasGadget(3,20,20,10,10)
ImageGadget(2, 10, 100, 60,60,0)
ImageGadget(4, 100, 100, 60,60,0)
SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) | #WS_CLIPSIBLINGS)
SetWindowPos_(GadgetID(1), #HWND_BOTTOM, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
captureGadget(1)
CaptureGadget1(1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: capture gadget; 64bit;
Posted: Fri Feb 08, 2019 5:00 pm
by RASHAD
Hi again
Very simple and direct
What is inside the Container will be captured to the image
You decide
Code: Select all
Procedure captureGadget(gadget,output)
CreateImage(0, GadgetWidth(gadget),GadgetHeight(gadget), 24)
hdc = StartDrawing(ImageOutput(0))
hwnd = GetWindow_(GadgetID(gadget),#GW_HWNDFIRST)
SendMessage_(GadgetID(gadget),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
StopDrawing()
SetGadgetState(output,ImageID(0))
EndProcedure
OpenWindow(0, 0, 0, 400, 300, "SpinGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ContainerGadget(0,10,10,60,24,#PB_Container_BorderLess)
SpinGadget(1,0,0,60,24,0,10,#PB_Spin_Numeric )
SetGadgetState(1,5)
CloseGadgetList()
ContainerGadget(10,200,10,60,60,#PB_Container_BorderLess)
ButtonGadget(11,0,0,60,60,"TEST",#WS_CLIPSIBLINGS)
CanvasGadget(12,10,10,10,10)
CloseGadgetList()
ImageGadget(100, 10, 200, 60,24,0)
captureGadget(0,100)
ImageGadget(200, 200, 200, 60,60,0)
captureGadget(10,200)
SetWindowLong_(GadgetID(11), #GWL_STYLE, GetWindowLong_(GadgetID(11), #GWL_STYLE) | #WS_CLIPSIBLINGS)
SetWindowPos_(GadgetID(11), #HWND_BOTTOM, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
End
Re: capture gadget; 64bit;
Posted: Fri Feb 08, 2019 7:09 pm
by RASHAD
a solution to correctly draw SpinGadget with WM_PRINT
Code: Select all
Procedure capturespin(gadget,output)
CreateImage(0, GadgetWidth(gadget),GadgetHeight(gadget), 24)
hdc = StartDrawing(ImageOutput(0))
hSpin = FindWindowEx_(GetParent_(GadgetID(0)), GadgetID(0), 0, 0)
SendMessage_(hSpin,#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
GrabDrawingImage(10, 0,0,15,25)
SendMessage_(GadgetID(0),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
DrawImage(ImageID(10),44,0)
StopDrawing()
FreeImage(10)
SetGadgetState(output,ImageID(0))
EndProcedure
OpenWindow(0, 0, 0, 200, 100, "SpinGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SpinGadget (0, 20, 15, 60, 20, 1, 100, #PB_Spin_Numeric)
SetGadgetState(0,50)
ImageGadget(100, 20, 60, 60,20,0)
capturespin(0,100)
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
End
Re: capture gadget; 64bit;
Posted: Mon Feb 11, 2019 1:51 pm
by Derren
HanPBF wrote:
Ok, of course I would prefer:
Code: Select all
protected ;(or local or var)
x
y
w
h
endProtected ;(or endLocal or endVar)
This works.
The first var needs to be in the same line as "Define" (or Protected), though.
If you don't like it, you can still Define a dummy variable and use a macro.
Code: Select all
Macro var
Define mydummvar
EndMacro
var,
x,
y,
z
Okay, now you need a comma after the "var keyword" and you need to add indentation yourself in the settings (any yet another dummy macro to end indentation)