holomind and PhiLho,
Thanks! I've been wanting to make this little program for a year or so and this made it so much more tempting to start coding. I've been using
QuickShot for some time which has the same functionality as this. I found QuickShot to be a little slow and I like the idea of hosting the screenshots on my own server. This takes a full screenshot of the screen and uploads it to your own FTP server. It's meant to be dead-simple and fast. I use it mostly in IM chats when the other person can't receive files. (I've only added the code-snippet between "#Z::" and "return", assides from that it's identical to holomind's script.)
Code:
#Include GDIPlusHelper.ahk
;SitaShot by Murp|e. Updated 2007-02-17.
;Takes a screenshot of your desktop and automatically uploads it to your web server.
;You need to customize this with the information from your server. Search this code for the string "your" and customize all the values. Take a screenshot with Win+Z.
;See: http://www.autohotkey.com/forum/viewtopic.php?t=11860 for orignal
;Credits to holomind and PhiLho for the excellent code!!
Menu, Tray, icon, SitaShot_Icon.ico
OnExit, handle_exit
main:
FileCreateDir, screens
FileCreateDir, thumbs
WinGet, hw_frame, id, "Program Manager" ; Desktop ?
hdc_frame := DllCall( "GetDC", "uint", hw_frame )
hdc_frame_full := DllCall( "GetDC", "uint", hw_frame )
counter:=0 ; thumbnails
counter_f:=0 ; fullscreens
thumb_w:= 200
thumb_h:= ceil( thumb_w * A_ScreenHeight / A_ScreenWidth ) ; keep screenratio
use_antialize := 1
; buffer
hdc_buffer := DllCall( "gdi32.dll\CreateCompatibleDC" , "uint", hdc_frame )
hbm_buffer := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hdc_frame, "int", thumb_w, "int", thumb_h )
r := DllCall( "gdi32.dll\SelectObject" , "uint", hdc_buffer, "uint", hbm_buffer )
hdc_buffer_full := DllCall( "gdi32.dll\CreateCompatibleDC" , "uint", hdc_frame_full )
hbm_buffer_full := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hdc_frame_full, "int", A_ScreenWidth, "int", A_ScreenHeight )
r_full := DllCall( "gdi32.dll\SelectObject" , "uint", hdc_buffer_full, "uint", hbm_buffer_full )
; comment this line for speed but less quality
if use_antialize = 1
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_buffer, "int", 4 ) ; Halftone better quality with stretch
return
#Z::
Gosub, SaveImage_Full
FileDelete, Secret_FTP_Commands.txt
FileAppend, ;Creates a temporary file with the FTP commands, could this be avoided?
(
yourdomain.com ;The username you use to log on to your FTP.
yOurpassWOrd ;The password you use to log on to your FTP.
cd /yoursub/folders ;Choose a subfolder on your web domain such as /screenshots
lcd \screens
bin
prompt n
put "%fileNameDestP%" ;Uploads the file.
quit
), Secret_FTP_Commands.txt
runwait, ftp -s:Secret_FTP_Commands.txt ftp.yourdomain.com
FileDelete, Secret_FTP_Commands.txt
clipboard = http://www.yourdomain/yoursub/folders/%SitaShotFilename% ; Change this line too. Same values as above.
msgbox, Screenshot successfully uploaded and link copied to clipboard! ;It doesn't know if anything actually succeeded, it's just very optimistic about it all.
return
#v::
SaveImage_Full:
counter_f := counter_f +1
FormatTime, myTime, , yyyyMMdd_hhmmss
fileNameDestP = screens\S_%myTime%_%counter_f%_%A_ScreenWidth%x%A_ScreenHeight%.png
StringTrimLeft, SitaShotFilename, fileNameDestP, 8
If (GDIplus_Start() != 0)
Goto GDIplusError
; Copy BMP from DC
DllCall( "gdi32.dll\BitBlt"
, "uint", hdc_buffer_full, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight
, "uint", hdc_frame_full, "int", 0, "int", 0, "uint", 0x00CC0020 )
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer_full, uint, 0, uintp, bitmap )
; Save to PNG
If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
Goto GDIplusError
noParams = NONE
If (GDIplus_SaveImage(bitmap, fileNameDestP, pngEncoder, noParams) != 0)
Goto GDIplusError
Return
GDIplusError:
If (#GDIplus_lastError != "")
MsgBox 16, GDIplus Test, Error in %#GDIplus_lastError%
GDIplus_Stop()
Return
#c::
SaveImage:
counter := counter +1
FormatTime, myTime, , yyyyMMdd_hhmmss
fileNameDestP = thumbs\T_%myTime%_%counter%_%thumb_w%x%thumb_h%.png
If (GDIplus_Start() != 0)
Goto GDIplusError
; Copy BMP from DC
DllCall( "gdi32.dll\StretchBlt"
, "uint", hdc_buffer, "int", 0, "int", 0, "int", thumb_w, "int", thumb_h
, "uint", hdc_frame, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight, "uint", 0x00CC0020 )
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )
; Save to PNG
If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
Goto GDIplusError
noParams = NONE
If (GDIplus_SaveImage(bitmap, fileNameDestP, pngEncoder, noParams) != 0)
Goto GDIplusError
Return
#x::
handle_exit:
DllCall( "gdi32.dll\DeleteObject", "uint", hbm_buffer )
DllCall( "gdi32.dll\DeleteDC" , "uint", hdc_frame )
DllCall( "gdi32.dll\DeleteDC" , "uint", hdc_buffer )
ExitApp
I spent some hours making this today and there are several things I'd like to improve and would appreciate some pointers with.
1. I'd like to have one single file, instead of having two .AHK files. What is the easiest way of incorporating GDIPlusHelper.ahk into the main .AHK script?
2. The FTP part is fairly ugly since it exposes your FTP username and password for all to see. I don't personally care much about that, but I would imagine many people do. Does anyone know of an easy way to improve security?