It is currently Thu Dec 12, 2019 4:00 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Screen Capture
PostPosted: Wed Jan 30, 2002 4:39 am 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Code updated for 5.20+

Restored from previous forum. Originally posted by wayne1.


Code:
Procedure CaptureScreen(Left, Top, Width, Height)
  dm.DEVMODE ;structure for CreateDC()
  srcDC = CreateDC_("DISPLAY", "", "", dm)
  trgDC = CreateCompatibleDC_(srcDC)
  BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height)
  SelectObject_( trgDC, BMPHandle)
  BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY)
  OpenClipboard_(#Null)
  EmptyClipboard_()
  SetClipboardData_(2, BMPHandle)
  CloseClipboard_()
  DeleteDC_( trgDC)
  ReleaseDC_( BMPHandle, srcDC)
  ProcedureReturn
EndProcedure

CaptureScreen( 0, 0, 800, 600);set to desired(current) screen resolution 1024*768 640*480 etc.

MessageRequester("Message","OK, paste the current clipboard data to Microsoft Paint or whatever program you use to see the results of the screen capture.",#MB_ICONEXCLAMATION)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 30, 2002 12:33 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by PB.

Wayne's tip is useful for grabbing part of a screen, but if you're only interested
in the full screen or current active window, then it can be done shorter like so:

Code:
keybd_event_(#VK_SNAPSHOT,0,0,0) ; Snapshot of entire desktop.
keybd_event_(#VK_SNAPSHOT,1,0,0) ; Snapshot of current active window.



Note that the snapshot is stored in the clipboard like Wayne's example.


PB - Registered PureBasic Coder

Edited by - PB on 30 January 2002 12:34:34


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 15, 2003 8:37 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Jun 04, 2003 8:44 am
Posts: 168
Location: Switzerland
Hi there

Code:
keybd_event_(#VK_SNAPSHOT,0,0,0) ; Snapshot of entire desktop.


looks like it does not work for win 95/98, it needs to be:

Code:
keybd_event_(#VK_SNAPSHOT,1,0,0) ; Snapshot of entire desktop.


Anyone knows what about Win NT, Win 2000 or Win XP?

Cecil


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 15, 2003 9:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
You're correct, Cecil -- Win 9x needs 1,0,0 for the entire desktop.
On Windows 2000 you use 0,0,0 for desktop and 1,0,0 for window.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 08, 2004 2:38 am 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 07, 2004 8:47 am
Posts: 1857
Location: Argentina
And how do you capture an active window at Win 9x then?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 13, 2004 5:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed May 21, 2003 1:44 pm
Posts: 119
Location: Netherlands
@dagcrack, detect witch windows os the user has and apply..(if then...)
How would one save the screenshot?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 13, 2004 8:11 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
Code:
;capture a piece of screen
Procedure.l CaptureScreen(Left.l, Top.l, Width.l, Height.l)
    dm.DEVMODE
    BMPHandle.l
    srcDC = CreateDC_("DISPLAY", "", "", dm)
    trgDC = CreateCompatibleDC_(srcDC)
    BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height)
    SelectObject_( trgDC, BMPHandle)
    BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY)
    DeleteDC_( trgDC)
    ReleaseDC_( BMPHandle, srcDC)
    ProcedureReturn BMPHandle
EndProcedure

ScreenCaptureAddress = CaptureScreen(192, 112, 256, 256)

CreateImage(0, 256, 256)
StartDrawing(ImageOutput())
    DrawImage(ScreenCaptureAddress, 0, 0)
StopDrawing()
SaveImage(0, "Screenshot.bmp")

:)

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 14, 2004 5:28 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2004
Location: USA
I was trying to figure out how to capture the screen of a window, no matter what the position of the window is. I understand most of the procedure but what does the "DC" stand for?

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 14, 2004 6:47 am 
Offline
Moderator
Moderator

Joined: Sat Dec 27, 2003 3:55 am
Posts: 3321
Location: Great Southern Land
Good question.

I looked it up, and according to the sdk it is "Device Context".
Quote:
A device context is a structure that defines a set of graphic objects and their associated attributes, as well as the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 14, 2004 7:46 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2004
Location: USA
Thanks for looking that up. :D

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 14, 2004 2:39 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
Quote:
I was trying to figure out how to capture the screen of a window, no matter what the position of the window is

Code:
;capture a piece of screen
Procedure.l CaptureScreen(Left.l, Top.l, Width.l, Height.l)
    dm.DEVMODE
    BMPHandle.l
    srcDC = CreateDC_("DISPLAY", "", "", dm)
    trgDC = CreateCompatibleDC_(srcDC)
    BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height)
    SelectObject_( trgDC, BMPHandle)
    BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY)
    DeleteDC_( trgDC)
    ReleaseDC_( BMPHandle, srcDC)
    ProcedureReturn BMPHandle
EndProcedure

Procedure CaptureWindow(WindowName.s)
    WinHndl = FindWindow_(0, WindowName)
    If WinHndl
        WindowSize.RECT
        GetWindowRect_(WinHndl, @WindowSize)
        ScreenCaptureAddress = CaptureScreen(WindowSize\Left, WindowSize\Top, WindowSize\Right - WindowSize\Left, WindowSize\Bottom - WindowSize\Top)
        CreateImage(0, WindowSize\Right - WindowSize\Left, WindowSize\Bottom - WindowSize\Top)
        StartDrawing(ImageOutput())
            DrawImage(ScreenCaptureAddress, 0, 0)
        StopDrawing()
        SaveImage(0, "Screenshot.bmp")
    Else
        ProcedureReturn 0
    EndIf
    ProcedureReturn 1
EndProcedure

CaptureWindow("My Computer")

:D

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 14, 2004 11:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed May 21, 2003 1:44 pm
Posts: 119
Location: Netherlands
Greate Job!

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 15, 2004 12:47 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2004
Location: USA
Capturing by window name, nice work. :D

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 15, 2004 9:27 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Jan 24, 2004 6:56 pm
Posts: 768
o.k. Group, very nice work indeed.

And now for the next step... :D

What, if I wanted to be able to grab the contents of a window resp. control, but I'd like to use the resulting bitmap for publishing purposes. For the resulting bitmap, I'd need higher resolutions than the screen grab can deliver. Also, to be able to publish high quality pictures, I don't want to scale up an original screen resolution screen grab....

Ideas anyone...?

_________________
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 15, 2004 10:30 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jun 26, 2003 2:09 am
Posts: 744
Location: Spain (Galicia)
Quote:
I wanted to be able to grab the contents of a window resp. control,

What is window resp. control?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 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