capture gadget; 64bit;

Windows specific forum
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

capture gadget; 64bit;

Post 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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: capture gadget; 64bit;

Post by Dude »

[Deleted, can't do what I planned]
Last edited by Dude on Wed May 23, 2018 8:28 am, edited 1 time in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: capture gadget; 64bit;

Post 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
Image
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: capture gadget; 64bit;

Post 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

Egypt my love
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: capture gadget; 64bit;

Post 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!!!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: capture gadget; 64bit;

Post by Kwai chang caine »

A very good way for clone false button :lol:
Image

Thanks to HanPBF and RASHAD 8)
ImageThe happiness is a road...
Not a destination
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: capture gadget; 64bit;

Post 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

Code: Select all

var x
var y
var w
var h
Ok, of course I would prefer:

Code: Select all

protected ;(or local or var)
  x
  y
  w
  h
endProtected ;(or endLocal or endVar)
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: capture gadget; 64bit;

Post 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
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: capture gadget; 64bit;

Post by RSBasic »

@HanPBF
Thank you very much for information.
Image
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: capture gadget; 64bit;

Post 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
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: capture gadget; 64bit;

Post 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

Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: capture gadget; 64bit;

Post 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 
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: capture gadget; 64bit;

Post 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 
Egypt my love
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: capture gadget; 64bit;

Post 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)

Code: Select all

Define x,
       y,
       z
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)
Post Reply