Deal with Screenshots ... can it be done?

Just starting out? Need help? Post your questions and find answers here.
b1be
User
User
Posts: 25
Joined: Sat Mar 19, 2005 5:47 pm

Deal with Screenshots ... can it be done?

Post 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
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

It's possible
b1be
User
User
Posts: 25
Joined: Sat Mar 19, 2005 5:47 pm

:D.. Thanks ... :D

Post 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)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

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

Image
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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? :?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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:
--Kale

Image
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

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

Post 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 :)
b1be
User
User
Posts: 25
Joined: Sat Mar 19, 2005 5:47 pm

Post 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
Last edited by b1be on Sun Mar 20, 2005 1:22 pm, edited 1 time in total.
b1be
User
User
Posts: 25
Joined: Sat Mar 19, 2005 5:47 pm

Post by b1be »

Works like a CHARM ... :D ... thank you for your support..
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

This code doesn't appear to work in 4.0 anymore... =(
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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 
I may look like a mule, but I'm not a complete ass.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Yea the problem with mine was somewhere else =P
Post Reply