A screendump program the Hollywood way

Discuss any general programming issues here
Post Reply
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

A screendump program the Hollywood way

Post by TheMartian »

Hi
Here is a Screen dump program that will dump any selected area of the Desktop to the RAM: disk as a .BMP file. Multiple dumps are possible. I kind of like the idea using of a Hollywood display as the marker for which area to dump. It saves a lot of work because displays can be resizable and draggable and made semi transparent fairly easy. Who says displays can only be used to display something :P

The code is adapted to Amigas. I have not tested it on a PC or MAC, and you certainly need to direct the output elsewhere if testing on one of those platforms.

If you need it you can redirect the output to the clipboard using the SetClipBoard(#CLIPBOARD_IMAGE,#TEMP_BRUSH) instead and perhaps assign this type of dump to, say 'F11'. I haven't done it here though because a needed multiple dumps and the Clipboard only allows one dump at a time to exist in the buffer.

Comments and suggestions are of course welcome...

/*
************************************************************
**
** Created by: Jesper Schultz-Pedersen
** Project: Screendump
** File: main.hws
** Date: 10-04-2010 17:07:39
**
************************************************************
*/

/*
This program is a utility to create screendumps from a section of the screen.
It displays a semi transparent display/window that may be dragged or resized.
Dragging is done by using the mouse located near the top of the display, while
resizing is done from the lower right corner.

Whatever the display covers of the visible screen gets dumped. If the display
is not entirely within the visible screen, then only the part within the screen
is dumped. If this happens the display used to indicate the dumped area is
relocated to the centre of the screen afterward to solve a potential problem
with the ShowDisplay() function that currently cannot handle displays outside
the visible screen (I think!?...)

Press 'F12' to dump the selected area and 'ESC' to close the utility.

When first used the dump is sent to the location 'RAM:Screendump1.BMP'. You can do
multiple dumps in one session and they will then be named 'RAM:Screendump2.BMP'...
'RAM:Screendump3.BMP'... and so on, depending on the existence or not of another
file by that name in the same location.

You can run multiple instances of the utility - but why would you?.. Except perhaps to
dump a part of the screen showing the other instance of the program in action :-)

To use it on a PC or a Mac you have to change the destination string to something that
is legal on these machines.

Remember that the utility only works if it is the current display. You can run it and then
work on other things. But to trigger a dump you have to make it active. Of course that happens
when you position/resize it to stake out the dump area. So it is no big deal anyway.

If you set up the executable to be triggered by a key combination like ALT-F12 using the
FKey commodity (on the Amiga) you will have a flexible screen dump utility at your fingertips.

Have fun!

*/

@VERSION 4,5
@DISPLAY {Sizeable=True, Borderless=True}

Const #TEMP_BRUSH=999

runflag=True

/*
Create a semi transparent BGPic (using its alphachannel) for use with our display
*/

CreateBGPic(2,320,200,#RED)
SelectAlphaChannel(2,#BGPIC)
SetAlphaIntensity(50)
Cls
EndSelect
SetDisplayAttributes({BGPic=2})

/*
Set up a Key handler. 'F12' copies the selected area. 'ESC' closes the utility.
Using HideDisplay/ShowDisplay prevents our utility display from being visible while
dumping the Desktop contents below it.

If the modifyflag is set, our utility display is relocated to the middle of the Desktop
because of a potential problem when using ShowDisplay() on a display that is partly
outside the visible screen area.

You can do multiple screendumps. The utility adds a counter to the fixed filename and
increments the counter until it comes up with a filename that is not already in use.
*/

Function p_KeyHandler(msg)
Local counter,saveflag=1,false
Local filedestination$
switch msg.key
Case "F12":
Local x,y,w,h,modifyflag=p_GetSizeAndPosition()
HideDisplay()
GrabDesktop(#TEMP_BRUSH,{x=x,y=y,width=w,height=h})
If modifyflag Then SetDisplayAttributes({x=#CENTER,y=#CENTER})
ShowDisplay()
Repeat
filedestination$="RAM:Screendump"..counter..".BMP"
If Exists(filedestination$)
counter=counter+1
Else
SaveBrush(#TEMP_BRUSH,filedestination$,nil,#IMGFMT_BMP)
saveflag=True
EndIf
Until saveflag
Case "ESC":
runflag=False
EndSwitch
EndFunction


/*
The function returns the coordinates and current size of our utility display.
It also checks for the largest possible size so we can limit the size of the dumped area
if our utility display is not entirely inside the Desktop area. If we have to limit the
area the modifyflag returns true.
*/

Function p_GetSizeAndPosition()
Local x,y,w,h,maxw,maxh,tempw,temph
Local modifyflag=false
x=GetAttribute(#DISPLAY,1,#ATTRXPOS)
y=GetAttribute(#DISPLAY,1,#ATTRYPOS)
w=GetAttribute(#DISPLAY,1,#ATTRWIDTH)
h=GetAttribute(#DISPLAY,1,#ATTRHEIGHT)
maxw=GetAttribute(#DISPLAY,1,#ATTRMAXWIDTH)
maxh=GetAttribute(#DISPLAY,1,#ATTRMAXHEIGHT)
tempw=Min(w,maxw-x)
temph=Min(h,maxh-y)
if ((tempw<>w) or (temph<>h)) Then modifyflag=true
w=Min(w,maxw-x)
h=Min(h,maxh-y)
Return(x,y,w,h,modifyflag)
EndFunction

InstallEventHandler({OnKeyDown=p_KeyHandler})

While runflag
WaitEvent()
Wend

End()
Post Reply