It is currently Mon Jul 06, 2020 5:23 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 7:34 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 541
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 8:17 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
[Deleted, can't do what I planned]


Last edited by Dude on Wed May 23, 2018 8:28 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 8:21 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1112
Location: Gernsbach (Germany)
HanPBF wrote:
Code:
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

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 8:39 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3640
Hi HanPBF
Try
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 9:11 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 541
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!!!


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 9:48 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4692
Location: Lyon - France
A very good way for clone false button :lol:
Image

Thanks to HanPBF and RASHAD 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 12:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 541
Quote:
"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:
protected x
protected y
protected w
protected h


I use
Code:
var x
var y
var w
var h


Ok, of course I would prefer:
Code:
protected ;(or local or var)
  x
  y
  w
  h
endProtected ;(or endLocal or endVar)


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 12:23 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1127
And here RASHAD's procedure to use it also in other codes ;)

Code:
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 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 12:38 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1112
Location: Gernsbach (Germany)
@HanPBF
Thank you very much for information.

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Wed May 23, 2018 12:38 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3640
Hi guys
Add to collection :)
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Fri Feb 08, 2019 2:24 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3640
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Fri Feb 08, 2019 5:00 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3640
Hi again
Very simple and direct
What is inside the Container will be captured to the image
You decide

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Fri Feb 08, 2019 7:09 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3640
Quote:
a solution to correctly draw SpinGadget with WM_PRINT


Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: capture gadget; 64bit;
PostPosted: Mon Feb 11, 2019 1:51 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 297
Location: Germany
HanPBF wrote:

Ok, of course I would prefer:
Code:
protected ;(or local or var)
  x
  y
  w
  h
endProtected ;(or endLocal or endVar)



Code:
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:
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)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye