Page 1 of 1

Deal with Screenshots ... can it be done?

Posted: Sat Mar 19, 2005 6:20 pm
by b1be
Oks.. since i'm new at PureBasic... i have one little question (or let's say Problem)

1. I want to run a PB code (LOL)
2. Within this code Launch a "Game or App or something" (but mainly a GAME)
3. Set a "DELAY" let-s say 20-30 seconds
4. While The "Game" runs Take a Screenshot and save it to .jpg mainly

Posted: Sat Mar 19, 2005 6:55 pm
by Bonne_den_kule
It's possible

:D.. Thanks ... :D

Posted: Sat Mar 19, 2005 7:20 pm
by b1be
Oks.. Thanks.. I Got this one... :D, but can anyone share one bit (or two) of Code on this matter ? :?: .. Just Started PureBasic "TODAY" ... and startin' to "LOVE IT" ... :D ... (again, a piece of code WILL HELP VERRY MUCH, Thanks)

Posted: Sat Mar 19, 2005 7:40 pm
by Kale
This should get you started :) :

Code: Select all

;===========================================================================
;-CONSTANTS
;===========================================================================

#APP_NAME = "Delayed Screenshot taker v1.0"

Enumeration
    #WINDOW_ROOT
    #STRING_EXE
    #BUTTON_SELECTEXE
    #SPIN_TIME
    #TEXT_SECONDS
    #BUTTON_LAUNCH
    #TIMER_MAIN
EndEnumeration

;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================

Global ExeName.s

;===========================================================================
;-PROCEDURES
;===========================================================================

;Handle an error
Procedure HandleError(Result, Text.s)
    If Result = 0 : MessageRequester("Error", Text, #PB_MessageRequester_Ok) : End : EndIf
EndProcedure

;capture the screen
Procedure.l CaptureScreen()
    ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
    ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN)
    dm.DEVMODE
    BMPHandle.l
    srcDC = CreateDC_("DISPLAY", "", "", dm)
    trgDC = CreateCompatibleDC_(srcDC)
    BMPHandle = CreateCompatibleBitmap_(srcDC, ScreenWidth, ScreenHeight)
    SelectObject_( trgDC, BMPHandle)
    BitBlt_(trgDC, 0, 0, ScreenWidth, ScreenHeight, srcDC, 0, 0, #SRCCOPY)
    DeleteDC_(trgDC)
    ReleaseDC_(BMPHandle, srcDC)
    CreateImage(0, ScreenWidth, ScreenHeight)
    StartDrawing(ImageOutput())
        DrawImage(BMPHandle, 0, 0)
    StopDrawing()
    UseJPEGImageEncoder()
    SaveImage(0, "Screenshot.jpg", #PB_ImagePlugin_JPEG)
    End
EndProcedure

;===========================================================================
;-GEOMETRY
;===========================================================================

HandleError(OpenWindow(#WINDOW_ROOT, 0, 0, 400, 55, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, #APP_NAME), "Main window could not be created.")
HandleError(CreateGadgetList(WindowID(#WINDOW_ROOT)), "Gadget list for the main window could not be created.")
StringGadget(#STRING_EXE, 5, 5, 285, 21, "")
ButtonGadget(#BUTTON_SELECTEXE, 295, 5, 100, 21, "Select Program...")
SpinGadget(#SPIN_TIME, 5, 30, 50, 21, 1, 1000)
SetGadgetState(#SPIN_TIME, 60) : SetGadgetText(#SPIN_TIME,"60")
TextGadget(#TEXT_SECONDS, 60, 33, 140, 21, "Seconds until screenshot.")
ButtonGadget(#BUTTON_LAUNCH, 295, 30, 100, 21, "Launch")

;===========================================================================
;-MAIN LOOP
;===========================================================================

Repeat
    EventID.l = WaitWindowEvent()
    Select EventID
        Case #PB_EventGadget
            Select EventGadgetID()
                Case #BUTTON_LAUNCH
                    RunProgram(ExeName)
                    Delay(GetGadgetState(#SPIN_TIME) * 1000)
                    CaptureScreen()
                Case #BUTTON_SELECTEXE
                    ExeName = OpenFileRequester(#APP_NAME, "", "Executable (*.exe) | *.exe", 0)
                    SetGadgetText(#STRING_EXE, ExeName)
                Case #SPIN_TIME
                    SetGadgetText(#SPIN_TIME, Str(GetGadgetState(#SPIN_TIME)))
            EndSelect
    EndSelect
Until EventID = #PB_Event_CloseWindow
End

Posted: Sat Mar 19, 2005 8:14 pm
by dagcrack
But if he started programming today then that will be hebrew for him :lol:

I would help you but I only help when I know the purpose of the application :P (dont blame me). Whats the deal with automatic screenies? I would write a burst-mode screenshooter so when theres good action I press a key and it takes a sequence, that sounds more interesting for a client.

Now for server-side via client, I would use this for checking if they are using some sort of hack (wallhack, ballhack, whitewalls, etc etc etc) so once the screenshot is in memory send it to the server and store it among some useful data. (date, client ip, uid, etc).

or what? :?

Posted: Sat Mar 19, 2005 8:19 pm
by Kale
But if he started programming today then that will be hebrew for him
If you wanna learn to swim, you gotta jump in the water! :wink:

Re: Deal with Screenshots ... can it be done?

Posted: Sat Mar 19, 2005 11:03 pm
by thefool
b1be wrote:Oks.. since i'm new at PureBasic... i have one little question (or let's say Problem)

1. I want to run a PB code (LOL)
2. Within this code Launch a "Game or App or something" (but mainly a GAME)
3. Set a "DELAY" let-s say 20-30 seconds
4. While The "Game" runs Take a Screenshot and save it to .jpg mainly
well kale's method probaly works but is very advanced heh
If the game has any key to press on keyboard to grab picture, then it would be easier just to make a program that:

1. Launch game
2. Wait 20 seconds
3. Send the screenshotkey to game/program [to grap all just send print screen and grap image from memory..] Well kale's method will only capture the window wich you cant do with the printscreen

4. If the game has ingame screenshot-key and its used then copy the pic
from wherever game holds image to wherever you want the image to be and convert it to JPG if not already.


i know kale's method is better but this is far simpler to program and understand for a beginner :)

Posted: Sun Mar 20, 2005 1:11 pm
by b1be
1st part

:D ... ok ... I Just started with PureBasic ... :D ... but i have some experience in old Spectrum BASIC .. :D,Visual Basic, BlitzBasic(Lacks of features btw), a little Old PASCAL and DELPHI, ... dunno' verry little C, ....

2nd part
it will be a kind of LAN Chat with MULTIFEATURES ....

i saw the sendfile command and others that will improve my work greatley .. (i started this project in BLITZ .. but... memoryhungry prog and loads of workarounds .... lacks in features)

in BLITZ .... i could make the screenshot of the desktop and Opengl, but if it was D3D->black screen ... :( ... (didn't try the code yet ... (when i'm writing this...)

delay ... what really should happen is when someone sends a //TAKE SCREENSHOT// command over chat i need to see what that people's doing ... :P ...
server sends takescreenshot .. client makes screenshot.. saves to jpeg... sends to server... server views the screenshot...
(bad english i know... but you may get the point) - if he's playing a game or whatever ... "I NEVER SAW THIS IN A CHAT PORG.." ...
or depending in "HOW MUCH MEMORY WILL TAKE" this may be set to auto (if it doesnt take so much ... like 10-20 secs let's say) ...

Thank you .... for the code... :D

Posted: Sun Mar 20, 2005 1:20 pm
by b1be
Works like a CHARM ... :D ... thank you for your support..

Posted: Tue Aug 22, 2006 3:32 pm
by dracflamloc
This code doesn't appear to work in 4.0 anymore... =(

Posted: Tue Aug 22, 2006 3:45 pm
by srod
Works okay here with the usual PB 4 adjustments.

Code: Select all

;=========================================================================== 
;-CONSTANTS 
;=========================================================================== 

#APP_NAME = "Delayed Screenshot taker v1.0" 

Enumeration 
    #WINDOW_ROOT 
    #STRING_EXE 
    #BUTTON_SELECTEXE 
    #SPIN_TIME 
    #TEXT_SECONDS 
    #BUTTON_LAUNCH 
    #TIMER_MAIN 
EndEnumeration 

;=========================================================================== 
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS 
;=========================================================================== 

Global ExeName.s 

;=========================================================================== 
;-PROCEDURES 
;=========================================================================== 

;Handle an error 
Procedure HandleError(Result, Text.s) 
    If Result = 0 : MessageRequester("Error", Text, #PB_MessageRequester_Ok) : End : EndIf 
EndProcedure 

;capture the screen 
Procedure.l CaptureScreen() 
    ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN) 
    ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN) 
    dm.DEVMODE 
    BMPHandle.l 
    srcDC = CreateDC_("DISPLAY", "", "", dm) 
    trgDC = CreateCompatibleDC_(srcDC) 
    BMPHandle = CreateCompatibleBitmap_(srcDC, ScreenWidth, ScreenHeight) 
    SelectObject_( trgDC, BMPHandle) 
    BitBlt_(trgDC, 0, 0, ScreenWidth, ScreenHeight, srcDC, 0, 0, #SRCCOPY) 
    DeleteDC_(trgDC) 
    ReleaseDC_(BMPHandle, srcDC) 
    CreateImage(0, ScreenWidth, ScreenHeight) 
    StartDrawing(ImageOutput(0)) 
        DrawImage(BMPHandle, 0, 0) 
    StopDrawing() 
    UseJPEGImageEncoder() 
    Debug SaveImage(0, "Screenshot.jpg", #PB_ImagePlugin_JPEG) 
    End 
EndProcedure 

;=========================================================================== 
;-GEOMETRY 
;=========================================================================== 

HandleError(OpenWindow(#WINDOW_ROOT, 0, 0, 400, 55, #APP_NAME,#PB_Window_SystemMenu | #PB_Window_ScreenCentered), "Main window could not be created.") 
HandleError(CreateGadgetList(WindowID(#WINDOW_ROOT)), "Gadget list for the main window could not be created.") 
StringGadget(#STRING_EXE, 5, 5, 285, 21, "") 
ButtonGadget(#BUTTON_SELECTEXE, 295, 5, 100, 21, "Select Program...") 
SpinGadget(#SPIN_TIME, 5, 30, 50, 21, 1, 1000) 
SetGadgetState(#SPIN_TIME, 60) : SetGadgetText(#SPIN_TIME,"60") 
TextGadget(#TEXT_SECONDS, 60, 33, 140, 21, "Seconds until screenshot.") 
ButtonGadget(#BUTTON_LAUNCH, 295, 30, 100, 21, "Launch") 

;=========================================================================== 
;-MAIN LOOP 
;=========================================================================== 

Repeat 
    EventID.l = WaitWindowEvent() 
    Select EventID 
        Case #PB_Event_Gadget 
            Select EventGadget() 
                Case #BUTTON_LAUNCH 
                    RunProgram(ExeName) 
                    Delay(GetGadgetState(#SPIN_TIME) * 1000) 
                    CaptureScreen() 
                Case #BUTTON_SELECTEXE 
                    ExeName = OpenFileRequester(#APP_NAME, "", "Executable (*.exe) | *.exe", 0) 
                    SetGadgetText(#STRING_EXE, ExeName) 
                Case #SPIN_TIME 
                    SetGadgetText(#SPIN_TIME, Str(GetGadgetState(#SPIN_TIME))) 
            EndSelect 
    EndSelect 
Until EventID = #PB_Event_CloseWindow 
End 

Posted: Tue Aug 22, 2006 4:53 pm
by dracflamloc
Yea the problem with mine was somewhere else =P