#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Windows\Imgur.ico #AutoIt3Wrapper_Outfile=TinyPicCaptureUploader.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=Tested on Xp sp3 32 bit #AutoIt3Wrapper_Res_Description=Capture pic by mouse grab Or window and upload it to Imgur.com the image sharer. #AutoIt3Wrapper_Res_Fileversion=1.0.2.8 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P #AutoIt3Wrapper_Res_LegalCopyright=Copyright ? 2012 wakillon #AutoIt3Wrapper_Res_Language=1036 #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% #AutoIt3Wrapper_Res_Field=Compile date|%longdate% %time% #AutoIt3Wrapper_Res_Icon_Add=Imgur.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #NoTrayIcon #Region ;************ Includes ************ #Include #include #include #include #Include #Include #include #include #include #include #include #EndRegion ;************ Includes ************ If Not _Singleton ( @ScriptName, 1 ) Then Exit OnAutoItExitRegister ( '_OnAutoItExit' ) Opt ( 'GuiOnEventMode', 1 ) Opt ( 'TrayOnEventMode', 1 ) Opt ( 'TrayMenuMode', 1 ) #Region ------ Global Variables ------------------------------ Global $HHook, $WM_LBUTTON_TEST=0, $START_X, $START_Y, $LF_RI_SIZE=0, $TO_BO_SIZE=0, $IMGE_L=0, $IMGE_T=0, $IMGE_W=0, $IMGE_H=0 Global $hBitmap, $_Version = _GetScriptVersion ( ) Global $_DefaultBrowser = _GetDefaultBrowserPath ( ) Global $_TempDir = @TempDir & '\TPCU' Global $_RegKeySettings = "HKCU\Software\TinyPicCaptureUploader\Settings" Global $_RegTitleKey = 'TinyPicCaptureUploader' Global $_Gui, $_MouseGui, $_CaptureButton, $_UploadButton, $_WindowButton, $_Combo, $_Titles, $_PicPath, $_HwndChoice Global $_StatusBar, $_StatusBarHeight=20, $_Dll, $_MinimizeItem, $_StartItem, $_AboutItem, $_ImgurItem, $_SaveDirItem, $_OnTopItem, $_TopicItem, $_MuteItem, $_Mute Global $_Timer= _NowCalc ( ), $_NowCalc, $_ImgurPicPath = $_TempDir & '\Imgur3.jpg', $_ListOld[1] #EndRegion --- Global Variables ------------------------------ If _FileMissing ( ) Then _FileInstall ( ) _SetTrayMenu ( ) _Gui ( ) #Region ------ Main Loop ------------------------------ While 1 $_NowCalc = _NowCalc ( ) If _DateDiff ( 's', $_Timer, $_NowCalc ) >= 1 Then _UpDateComboList ( ) $_Timer = $_NowCalc If _IsMinimized ( $_Gui ) Then TrayItemSetText ( $_MinimizeItem, 'Restore Window' ) GUISetState ( @SW_HIDE, $_Gui ) EndIf EndIf Sleep ( 50 ) WEnd #EndRegion --- Main Loop ------------------------------ #Region ------ Gui ------------------------------ Func _Gui ( ) Local $_GuiWidht=450, $_GuiHeight=200 $_Gui = GUICreate ( ' ' & $_Version, $_GuiWidht, $_GuiHeight, @DesktopWidth - $_GuiWidht - 15, _ @DesktopHeight - $_GuiHeight - _GetTaskbarHeight ( )- $_StatusBarHeight - 20, -1, $WS_EX_ACCEPTFILES, WinGetHandle ( AutoItWinGetTitle ( ) ) ) GUISetOnEvent ( $GUI_EVENT_DROPPED, '_GetDroppedFilePath' ) GUISetOnEvent ( $GUI_EVENT_MINIMIZE, '_Minimize' ) GUISetIcon ( @WindowsDir & '\Imgur.ico' ) GUISetOnEvent ( $GUI_EVENT_CLOSE, '_Exit', $_Gui ) GUISetBkColor ( 0x000000, $_Gui ) _GuiSkin ( ) $_PicCtrl = GUICtrlCreatePic ( $_ImgurPicPath, 0, 0, $_GuiWidht, 77 ) GUICtrlSetTip ( $_PicCtrl, 'Drag your Pic here for upload it !' & @CRLF & 'Files Type supported : .jpg .jpeg .bmp .gif .png .tiff ', ' ', 1, 1 ) GUICtrlSetState ( $_PicCtrl, $GUI_DROPACCEPTED ) $_CaptureButton = GUICtrlCreateButton ( 'Start Mouse Capture', 20, 88, 100, 80, BitOR ( $BS_MULTILINE, $BS_CENTER ) ) GUICtrlSetOnEvent ( -1, '_Capture' ) GUICtrlSetFont ( -1, 12, 800 ) GUICtrlSetTip ( $_CaptureButton, 'Clic and Drag for Capture' & @CRLF & 'default Format : PNG', ' ', 1, 1 ) $_UploadButton = GUICtrlCreateButton ( 'Upload' & @CRLF & 'Capture', 330, 88, 100, 80, BitOR ( $BS_MULTILINE, $BS_CENTER ) ) GUICtrlSetOnEvent ( -1, '_Upload' ) GUICtrlSetFont ( -1, 14, 800 ) GUICtrlSetTip ( $_UploadButton, 'Upload your Last Pic Capture to Imgur.' & @CRLF & 'Default Upload Format : jpg for Static picture.', ' ', 1, 1 ) GUICtrlSetState ( $_UploadButton, $GUI_DISABLE ) $_WindowButton = GUICtrlCreateButton ( 'Start a Window Capture', 140, 88, 170, 40 ) GUICtrlSetOnEvent ( -1, '_WindowCapture' ) GUICtrlSetFont ( -1, 9, 600 ) GUICtrlSetTip ( $_WindowButton, 'Do a Window ScreenShot' & @CRLF & 'default Format : BMP', ' ', 1, 1 ) GUICtrlCreateLabel ( 'Select a Window', 140, 130, 170, 20, 0x01 ) GUICtrlSetColor ( -1, 0xFFFFFF ) GUICtrlSetFont ( -1, 9, 600 ) $_Combo = GUICtrlCreateCombo ( '', 140, 148, 170, 18 ) _UpDateComboList ( ) GUICtrlSetData ( $_Combo, '|' & $_Titles, 'Desktop' ) $_StatusBar = _GUICtrlStatusBar_Create ( $_Gui ) _GUICtrlStatusBar_SetMinHeight ( $_StatusBar, $_StatusBarHeight ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Drag and Drop a Pic on the Frog for Upload it...', 0 ) _GDIPlus_Startup ( ) If Round ( _Date_Time_GetTickCount ( )/1000 ) < 130 And RegRead ( 'HKCU\Software\Microsoft\Windows\CurrentVersion\Run', $_RegTitleKey ) <> '' Then GUISetState ( @SW_HIDE, $_Gui ) Else GUISetState ( @SW_SHOW, $_Gui ) GUICtrlSetState ( $_PicCtrl, $GUI_FOCUS ) EndIf _OnTop ( ) EndFunc ;==> _Gui ( ) Func _UpDateComboList ( ) $_List = _GetVisibleWinList ( ) If UBound ( $_List ) <> UBound ( $_ListOld ) Then $_Titles = '' $_Read = GUICtrlRead ( $_Combo ) For $_I = 1 To UBound ( $_List ) -1 $_WinTitle = WinGetTitle ( $_List[$_I] ) If $_WinTitle = 'Program Manager' Then $_Titles = $_Titles & '|Desktop' Else $_Titles = $_Titles & '|' & WinGetTitle ( $_List[$_I] ) EndIf Next GUICtrlSetData ( $_Combo, $_Titles, $_Read ) ReDim $_ListOld[UBound ( $_List )] $_ListOld = $_List EndIf EndFunc ;==> _UpDateComboList ( ) Func _ButtonsSetState ( $_State ) GUICtrlSetState ( $_CaptureButton, $_State ) GUICtrlSetState ( $_UploadButton, $_State ) GUICtrlSetState ( $_WindowButton, $_State ) EndFunc ;==> _ButtonsSetState ( ) Func _GuiSkin ( ) $_Dll = DllOpen ( $_TempDir & '\SkinH_EL.dll' ) DllCall ( $_Dll, 'int', 'SkinH_AttachEx', 'str', $_TempDir & '\itunes.she', 'str', 'mhgd' ) DllCall ( $_Dll, 'int', 'SkinH_SetAero', 'int', 1 ) EndFunc ;==> _GuiSkin ( ) #EndRegion --- Gui ------------------------------ #Region ------ Capture ------------------------------ Func _WindowCapture ( ) _ButtonsSetState ( $GUI_DISABLE ) If $hBitmap Then _WinAPI_DeleteObject ( $hBitmap ) $_PicPath = @MyDocumentsDir & '\' & StringRegExpReplace ( _NowCalc ( ), '(?i)(:|/| )', '' ) & '.png' $_List = _GetVisibleWinList ( ) $_ComboRead = GUICtrlRead ( $_Combo ) If $_ComboRead = '' Or $_ComboRead = 'Desktop' Then $_ComboRead = 'Program Manager' $_OptOld = Opt ( 'WinTitleMatchMode', 3 ) $_HwndChoice = WinGetHandle ( $_ComboRead ) Opt ( 'WinTitleMatchMode', $_OptOld ) If $_HwndChoice = '' Then MsgBox ( 262144+4096+16, "Error", "This Window no more exists !" ) _ButtonsSetState ( $GUI_ENABLE ) Return EndIf $_WinTitle= WinGetTitle ( $_HwndChoice ) If $_HwndChoice <> $_Gui Then GUISetState ( @SW_MINIMIZE, $_Gui ) If Not _IsMaximized ( $_HwndChoice ) And WinGetTitle ( $_HwndChoice ) <> 'Program Manager' Then Do WinSetState ( $_HwndChoice, '', @SW_RESTORE ) WinActivate ( $_HwndChoice, '' ) Until WinWaitActive ( $_HwndChoice, '', 1 ) If $_HwndChoice <> $_Gui Then _SetWindowPos ( ) EndIf Sleep ( 1000 ) $_PicPath = @MyDocumentsDir & '\' & StringRegExpReplace ( _NowCalc ( ), '(?i)(:|/| )', '' ) & '.bmp' _ScreenCapture_CaptureWnd ( $_PicPath, $_HwndChoice, -1, -1, -1, -1, False ) If Not $_Mute Then SoundPlay ( @WindowsDir & '\media\Ding2.wav' ) _DisplayPic ( $_PicPath ) GUISetState ( @SW_RESTORE, $_Gui ) _ButtonsSetState ( $GUI_ENABLE ) _OnTop ( ) WinActivate ( $_Gui ) _TrayTip ( $_Version, ' Pic was saved to :' & @CRLF & ' ' & @MyDocumentsDir, 1 ) EndFunc ;==> _WindowCapture ( ) Func _Capture ( ) If $hBitmap Then _WinAPI_DeleteObject ( $hBitmap ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Capturing...', 0 ) _MouseCapture ( ) _SaveImage ( $hBitmap, $_Gui ) GUICtrlSetState ( $_UploadButton, $GUI_ENABLE ) If Not $_Mute Then SoundPlay ( @WindowsDir & '\media\Ding2.wav' ) _DisplayPic ( $_PicPath ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Drag and Drop a Pic on the Frog for Upload it...', 0 ) EndFunc ;==> _Capture ( ) Func _MouseCapture ( ) Local $BORDER_LF_RI_SIZE=3, $BORDER_TO_BO_SIZE=3, $BORDCOLOR=0xFF0000 _SetCursor ( @WindowsDir & '\cursors\viseur_16885.cur', $OCR_NORMAL ) _SetCursor ( @WindowsDir & '\cursors\viseur_16885.cur', $OCR_IBEAM ) $LF_RI_SIZE = $BORDER_LF_RI_SIZE $TO_BO_SIZE = $BORDER_TO_BO_SIZE GUISetState ( @SW_HIDE, $_Gui ) $_MouseGui = GUICreate ( '', 1, 1, 1, 1, BitOR ( $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS ), BitOR ( $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE ) ) GUISetBkColor ( $BORDCOLOR, $_MouseGui ) $RegMouseProc = DllCallbackRegister ( '_LowLevelMouseProc', 'long', 'int;wparam;lparam' ) $HMod = _WinAPI_GetModuleHandle ( 0 ) $HHook = _WinAPI_SetWindowsHookEx ( $WH_MOUSE_LL, DllCallbackGetPtr ( $RegMouseProc ), $HMod ) While 1 If $WM_LBUTTON_TEST = 2 Then $hBitmap = _BitmapCreate ( ) If $_Gui <> 0 Then GUISetState ( @SW_SHOW , $_Gui ) _WinAPI_UnhookWindowsHookEx ( $HHook ) DllCallbackFree ( $RegMouseProc ) $WM_LBUTTON_TEST = 0 ExitLoop EndIf WEnd DllCall ( 'user32.dll', 'int', 'SystemParametersInfo', 'int', $SPI_SETCURSORS, 'int', 0, 'int', 0, 'int', 0 ) Return $hBitmap EndFunc ;==> _MouseCapture ( ) Func _LowLevelMouseProc ( $nCode, $wParam, $lParam ) If $nCode < 0 Then Return _WinAPI_CallNextHookEx ( $HHook, $nCode, $wParam, $lParam ) Select Case $wParam == $WM_LBUTTONDOWN And $WM_LBUTTON_TEST = 0 $POINT = DllStructCreate ( $tagPOINT, $lParam ) $START_X = DllStructGetData ( $POINT, 1 )-1 $START_Y = DllStructGetData ( $POINT, 2 )-1 $WM_LBUTTON_TEST = 1 Return 1 Case $wParam == $WM_MOUSEMOVE And $WM_LBUTTON_TEST = 1 $POINT = DllStructCreate ( $tagPOINT, $lParam ) $MOVE_X = DllStructGetData ( $POINT, 1 )+1 $MOVE_Y = DllStructGetData ( $POINT, 2 )+1 If $START_X >= $MOVE_X Then $L = $MOVE_X $R = $START_X Else $R = $MOVE_X $L = $START_X EndIf If $START_Y >= $MOVE_Y Then $B = $START_Y $T = $MOVE_Y Else $T = $START_Y $B = $MOVE_Y EndIf $W = $R - $L $H = $B - $T Global $IMGE_L = ( $L + $LF_RI_SIZE ), $IMGE_T = ( $T + $TO_BO_SIZE ), $IMGE_W = $W , $IMGE_H = $H _DrawGuiRgn ( $LF_RI_SIZE, $TO_BO_SIZE, $W, $H, $L, $T ) Case $wParam == $WM_LBUTTONUP And $WM_LBUTTON_TEST = 1 GUIDelete ( $_MouseGui ) $WM_LBUTTON_TEST = 2 Return 1 EndSelect Return _WinAPI_CallNextHookEx ( $HHook, $nCode, $wParam, $lParam ) EndFunc ;==> _LowLevelMouseProc ( ) Func _SetCursor ( $_CurFilePath, $_Cursor ) Local $_NewCur, $_Ret $_NewCur = DllCall ( 'user32.dll', 'int', 'LoadCursorFromFile', 'str', $_CurFilePath ) If Not @error Then $_Ret = DllCall ( 'user32.dll', 'int', 'SetSystemCursor', 'int', $_NewCur[0], 'int', $_Cursor ) If Not @error Then $_Ret = DllCall ( 'user32.dll', 'int', 'DestroyCursor', 'int', $_NewCur[0] ) EndIf EndFunc ;==> _SetCursor ( ) #EndRegion --- Capture ------------------------------ #Region ------ Resize ------------------------------ Func _ResizePic ( $_PicPath, $_NewPicPath, $_DimLimit=3000 ) If Not FileExists ( $_PicPath ) Then Return FileDelete ( $_NewPicPath ) Local $hImage, $hGraphics, $_Width, $_Height, $hNewBmp, $hNewGraphics, $_NewHeight, $_NewWidth $hImage = _GDIPlus_ImageLoadFromFile ( $_PicPath ) $_Width = _GDIPlus_ImageGetWidth ( $hImage ) $_Height = _GDIPlus_ImageGetHeight ( $hImage ) If $_DimLimit Then Do If $_Width <= $_DimLimit And $_Height <= $_DimLimit Then $_NewWidth = $_Width $_NewHeight = $_Height ExitLoop Else If $_Width > $_DimLimit Then $_NewWidth = $_DimLimit $_NewHeight = $_Height/$_Width * $_DimLimit ; keep ratio ElseIf $_Height > $_DimLimit Then $_NewWidth = $_Width/$_Height * $_DimLimit ; keep ratio $_NewHeight = $_DimLimit EndIf EndIf $_Width = $_NewWidth $_Height = $_NewHeight Until $_NewWidth <= $_DimLimit And $_NewHeight <= $_DimLimit Else $_NewWidth = $_Width $_NewHeight = $_Height EndIf $hGraphics = _GDIPlus_ImageGetGraphicsContext ( $hImage ) $hNewBmp = _GDIPlus_BitmapCreateFromGraphics ( $_NewWidth,$_NewHeight, $hGraphics ) $hNewGraphics = _GDIPlus_ImageGetGraphicsContext ( $hNewBmp ) _GDIPlus_GraphicsDrawImageRect ( $hNewGraphics, $hImage, 0, 0, $_NewWidth, $_NewHeight ) _GDIPlus_ImageSaveToFile ( $hNewBmp, $_NewPicPath ) _GDIPlus_GraphicsDispose ( $hGraphics ) _GDIPlus_GraphicsDispose ( $hNewGraphics ) _GDIPlus_BitmapDispose ( $hNewBmp ) _GDIPlus_ImageDispose ( $hImage ) Return FileExists ( $_NewPicPath ) EndFunc ;==> _ResizePic ( ) Func _GetFileType ( $_FilePath ) Local Const $TRID_GET_RES_NUM = 1 ; Get the number of results available Local Const $TRID_GET_RES_FILETYPE = 2 ; Filetype descriptions Local Const $TRID_GET_RES_FILEEXT = 3 If Not FileExists ( @SystemDir & '\TrIDLib.DLL' ) Then Return SetError ( 1 ) Local $_TrIDLibDll = DllOpen ( @SystemDir & '\TrIDLib.DLL' ) ; Open TrIDLib DLL FileChangeDir ( @SystemDir ) DllCall ( $_TrIDLibDll, 'int', 'TrID_LoadDefsPack', 'str', '' ) ; load the definitions FileChangeDir ( @ScriptDir ) DllCall ( $_TrIDLibDll, 'int', 'TrID_SubmitFileA', 'str', $_FilePath ) ; submit the file DllCall ( $_TrIDLibDll, 'int', 'TrID_Analyze' ) ; perform the analysis If @error Then DllClose ( $_TrIDLibDll ) Return SetError ( 2 ) EndIf Local $_Ret = DllCall ( $_TrIDLibDll, 'int', 'TrID_GetInfo', 'int', $TRID_GET_RES_NUM, 'int', 0, 'str', '' ) ; get the results number If Not $_Ret[0] Then DllClose ( $_TrIDLibDll ) Return SetError ( 3 ) EndIf Dim $Out[2] $_Ret = DllCall ( $_TrIDLibDll, 'int', 'TrID_GetInfo', 'int', $TRID_GET_RES_FILETYPE, 'int', 1, 'str', '' ) If Not @error Then $Out[0] = $_Ret[3] ; get the filetype description $_Ret = DllCall ( $_TrIDLibDll, 'int', 'TrID_GetInfo', 'int', $TRID_GET_RES_FILEEXT, 'int', 1, 'str', '' ) If Not @error Then $Out[1] = $_Ret[3] ; get the filetype extension DllClose ( $_TrIDLibDll ) Return $Out EndFunc ;==> _GetFileType ( ) #EndRegion --- Resize ------------------------------ #Region ------ Upload ------------------------------ Func _Upload ( ) If Not _IsConnected ( ) Then Return MsgBox ( 262144+4096+16, 'Error', 'You are Not Connected !' & @CRLF & 'Retry Later' ) _ButtonsSetState ( $GUI_DISABLE ) $_NewPicPath = $_TempDir & '\Tmp.jpg' FileDelete ( $_NewPicPath ) $_PicSize = FileGetSize ( $_PicPath )/1024 $_FileType = _GetFileType ( $_PicPath ) If Not @error Then Switch $_FileType[1] Case 'gif' Switch $_PicSize Case 1 To 2048 If StringInStr ( $_FileType[0], 'animated' ) Then _CurlUploadToImgur ( $_PicPath ) Else _ResizePic ( $_PicPath, $_NewPicPath ) _CurlUploadToImgur ( $_NewPicPath ) EndIf Case Else _ResizePic ( $_PicPath, $_NewPicPath ) _CurlUploadToImgur ( $_NewPicPath ) EndSwitch Case Else _ResizePic ( $_PicPath, $_NewPicPath ) _CurlUploadToImgur ( $_NewPicPath ) EndSwitch Else Switch @error Case 1 MsgBox ( 262144+4096+16, 'Error', 'An Error occured !' & @CRLF & 'TrIDLib.DLL not found in ' & @SystemDir, 4 ) Case 2 MsgBox ( 262144+4096+16, 'Error', 'An Error occured !' & @CRLF & 'Picture analysis has not succeeded', 4 ) Case 3 MsgBox ( 262144+4096+16, 'Error', 'An Error occured !' & @CRLF & 'File TrIDDefs.TRD Not found in ' & @SystemDir, 4 ) EndSwitch EndIf _ButtonsSetState ( $GUI_ENABLE ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Drag and Drop a Pic on the Frog for Upload it...', 0 ) EndFunc ;==> _Upload ( ) Func _CurlUploadToImgur ( $_UploadFilePath ) $_FullName = _GetFullNameByFullPath ( $_UploadFilePath ) $_UploadFilePath = FileGetShortName ( $_UploadFilePath ) $_Run = $_TempDir & '\curl.exe -F image=@"' & $_UploadFilePath & _ '" -F key=f77d0b8cd41eb62792be0bf303e649df --retry 2 --location-trusted --url "http://api.imgur.com/2/upload.xml"' $_Pid = Run ( $_Run, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD ) Local $_StdoutRead='', $_OutPut = '', $_Retry = 0 While ProcessExists ( $_Pid ) $_StdoutRead = StdoutRead ( $_Pid ) If Not @error And $_StdoutRead <> '' Then $_OutPut = $_OutPut & $_StdoutRead & @CRLF EndIf $_StderrRead = StderrRead ( $_Pid ) If Not @error And $_StderrRead <> '' Then $_StderrRead = StringStripWS ( $_StderrRead, 7 ) If StringInStr ( $_StderrRead, '%' ) = 0 Then StringReplace ( $_StderrRead, 'retries left', 'retries left' ) If @extended Then $_Retry += 1 $_StringSplit = StringSplit ( $_StderrRead, ' ' ) If Not @error Then _GUICtrlStatusBar_SetText ( $_StatusBar, ' Uploading Pic Named ' & $_FullName & ' --- Progress : ' & _Min ( Number ( $_StringSplit[1] ), 99 ) & '% --- ' & $_Retry +1 & '° Try', 0 ) EndIf EndIf Wend Local $_Pic_Links = StringRegExp ( $_OutPut, 'http://i.imgur.com/[^<]*', 3 ) If Not @error Then $_PicUrl = $_Pic_Links[0] _OpenInDefaultBrowser ( $_PicUrl ) ClipPut ( $_PicUrl ) If Not $_Mute Then SoundPlay ( @WindowsDir & '\media\Final.wav' ) Sleep ( 1000 ) _TrayTip ( $_Version, ' Pic Url was copied to the Clipboard !', 1 ) Else Select Case StringInStr ( $_OutPut, 'This method requires authentication' ) MsgBox ( 262144+4096+16, 'Error', 'Authentication is required !', 4 ) Case StringInStr ( $_OutPut, 'No image data was sent' ) MsgBox ( 262144+4096+16, 'Error', 'No image data was sent !', 4 ) Case StringInStr ( $_OutPut, '1000' ) MsgBox ( 262144+4096+16, 'Error', 'No image selected !', 4 ) Case StringInStr ( $_OutPut, '1001' ) MsgBox ( 262144+4096+16, 'Error', 'Image failed to upload !', 4 ) Case StringInStr ( $_OutPut, '1002' ) MsgBox ( 262144+4096+16, 'Error', 'Image larger than 10 MB !', 4 ) Case StringInStr ( $_OutPut, '1003' ) MsgBox ( 262144+4096+16, 'Error', 'Invalid image type or URL !', 4 ) Case StringInStr ( $_OutPut, '1004' ) MsgBox ( 262144+4096+16, 'Error', 'Invalid API Key !', 4 ) Case StringInStr ( $_OutPut, '1005' ) MsgBox ( 262144+4096+16, 'Error', 'Upload failed during process !', 4 ) Case StringInStr ( $_OutPut, '1006' ) MsgBox ( 262144+4096+16, 'Error', 'Upload failed during the copy process !', 4 ) Case StringInStr ( $_OutPut, '1007' ) MsgBox ( 262144+4096+16, 'Error', 'Upload failed during thumbnail process !', 4 ) Case StringInStr ( $_OutPut, '1008' ) MsgBox ( 262144+4096+16, 'Error', 'Upload limit reached !', 4 ) Case StringInStr ( $_OutPut, '1009' ) MsgBox ( 262144+4096+16, 'Error', 'Animated GIF is larger than 2MB !', 4 ) Case StringInStr ( $_OutPut, '1010' ) MsgBox ( 262144+4096+16, 'Error', 'Animated PNG is larger than 2MB !', 4 ) Case StringInStr ( $_OutPut, '1011' ) MsgBox ( 262144+4096+16, 'Error', 'Invalid URL !', 4 ) Case StringInStr ( $_OutPut, '1012' ) MsgBox ( 262144+4096+16, 'Error', 'Could not download the image from that URL !', 4 ) Case StringInStr ( $_OutPut, '9000' ) MsgBox ( 262144+4096+16, 'Error', 'Invalid API request !', 4 ) Case StringInStr ( $_OutPut, '9001' ) MsgBox ( 262144+4096+16, 'Error', 'Invalid response format !', 4 ) Case Else MsgBox ( 262144+4096+16, 'Error', 'Sorry, an error occured', 4 ) EndSelect EndIf EndFunc ;==> _CurlUploadToImgur ( ) #EndRegion --- Upload ------------------------------ Func _IsFilesSupported ( $_FilePath ) Switch String ( _GetExtByFullPath ( $_FilePath ) ) Case 'png', 'gif', 'bmp', 'jpeg', 'jpg', 'tiff' Return 1 EndSwitch EndFunc ;==> _IsFilesSupported ( ) Func _GetDroppedFilePath ( ) Local $_DragFile = @GUI_DRAGFILE If FileExists ( $_DragFile ) And _IsFilesSupported ( $_DragFile ) Then _ButtonsSetState ( $GUI_DISABLE ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Uploading...', 0 ) $_PicPath = $_DragFile _Upload ( ) Else $_PicPath = '' MsgBox ( 262144+4096+16, 'Error', 'Filetype Not Supported !' ) Endif _ButtonsSetState ( $GUI_ENABLE ) _GUICtrlStatusBar_SetText ( $_StatusBar, ' Drag and Drop a Pic on the Frog for Upload it...', 0 ) EndFunc ;==> _GetDroppedFilePath ( ) #Region ------ Miscellaneous ------------------------------ Func _GetExtByFullPath ( $_FullPath ) $_PathSplit = StringSplit ( $_FullPath, '.' ) If Not @error Then Return $_PathSplit[$_PathSplit[0]] EndFunc ;==> _GetExtByFullPath ( ) Func _GetDefaultBrowserPath ( ) $_DefaultBrowser = _WinAPI_AssocQueryString ( '.html', $ASSOCSTR_EXECUTABLE ) If Not @error Then Return $_DefaultBrowser EndFunc ;==> _GetDefaultBrowserPath ( ) Func _GetFullNameByFullPath ( $_FullPath ) $_FileName = StringSplit ( $_FullPath, '\' ) If Not @error Then Return $_FileName[$_FileName[0]] EndFunc ;==> _GetFullNameByFullPath ( ) Func _GetScriptVersion ( ) If Not @Compiled Then Return StringTrimRight ( @ScriptName, 4 ) & ' © wakillon 2010 - ' & @YEAR Else Return StringTrimRight ( @ScriptName, 4 ) & ' v' & FileGetVersion ( @ScriptFullPath ) & ' © wakillon 2010 - ' & @YEAR EndIf EndFunc ;==> _GetScriptVersion ( ) Func _GetTaskbarHeight ( ) $_OptOld = Opt ( 'WinTitleMatchMode', 4 ) $_WinPos = WinGetPos ( 'classname=Shell_TrayWnd' ) Opt ( 'WinTitleMatchMode', $_OptOld ) Return $_WinPos[3] EndFunc ;==> _GetTaskbarHeight ( ) Func _DisplayPic ( $_ImagePath ) Run ( 'rundll32 shimgvw.dll,ImageView_Fullscreen ' & $_ImagePath ) EndFunc ;==> _DisplayPic ( ) Func _IsConnected ( ) If Ping ( 'www.bing.com', 1 ) _ Or InetRead ( 'http://www.google.com/humans.txt', 19 ) Then Return True EndFunc ;==> _IsConnected ( ) Func _GetSourceCode ( $_Url ) $_InetRead = InetRead ( $_Url ) If Not @Error Then Return BinaryToString ( $_InetRead ) EndFunc ;==> _GetSourceCode ( ) #EndRegion --- Miscellaneous ------------------------------ #Region ------ Graphic ------------------------------ Func _SaveImage ( $hBitmap, $_Gui ) $_PicPath = @MyDocumentsDir & '\' & StringRegExpReplace ( _NowCalc ( ), '(?i)(:|/| )', '' ) & '.png' $Bitmap = _GDIPlus_BitmapCreateFromHBITMAP ( $hBitmap ) _GDIPlus_ImageSaveToFile ( $Bitmap, $_PicPath ) _WinAPI_DeleteObject ( $Bitmap ) _TrayTip ( $_Version, ' Pic was saved to :' & @CRLF & ' ' & @MyDocumentsDir, 1 ) EndFunc ;==> _SaveImage ( ) Func _DrawGuiRgn ( $BORDER_LF_RI_SIZE, $BORDER_TO_BO_SIZE, $WIDTH, $HEIGHT, $LEFT, $TOP ) $W = $BORDER_LF_RI_SIZE * 2 + $WIDTH $H = $BORDER_TO_BO_SIZE * 2 + $HEIGHT _WinAPI_SetWindowPos ( $_MouseGui, 0, $LEFT, $TOP, $LEFT + $W, $TOP + $H, 0 ) Sleep ( 20 ) $hREG1 = _WinAPI_CreateRectRgn ( 0, 0, $W, $H ) $hREG2 = _WinAPI_CreateRectRgn ( $BORDER_LF_RI_SIZE, $BORDER_TO_BO_SIZE, $BORDER_LF_RI_SIZE + $WIDTH, $BORDER_TO_BO_SIZE + $HEIGHT ) $hREG3 = _WinAPI_CreateRectRgn ( 0, 0, 0, 0 ) _WinAPI_CombineRgn ( $hREG3, $hREG1, $hREG2, $RGN_DIFF ) _WinAPI_DeleteObject ( $hREG1 ) _WinAPI_DeleteObject ( $hREG2 ) _WinAPI_SetWindowRgn ( $_MouseGui, $hREG3 ) _WinAPI_DeleteObject ( $hREG3 ) GUISetState ( @SW_SHOW, $_MouseGui ) EndFunc ;==> _DrawGuiRgn ( ) Func _BitmapCreate ( ) $DC = _WinAPI_GetDC ( 0 ) $CompatibleDC = _WinAPI_CreateCompatibleDC ( $DC ) $hBitmap = _WinAPI_CreateCompatibleBitmap ( $DC, $IMGE_W, $IMGE_H ) _WinAPI_SelectObject ( $CompatibleDC, $hBitmap ) _WinAPI_BitBlt ( $CompatibleDC, 0, 0, $IMGE_W, $IMGE_H, $DC, $IMGE_L, $IMGE_T, $SRCCOPY ) Return $hBitmap EndFunc ;==> _BitmapCreate ( ) #EndRegion --- Graphic ------------------------------ #Region ------ Windows ------------------------------ Func _SetWindowPos ( ) $_WinPos = WinGetPos ( $_HwndChoice ) WinMove ( $_HwndChoice, '', Default, Default, _Min ( @DesktopWidth - 20, $_WinPos[2] ), _Min ( @DesktopHeight - _GetTaskbarHeight ( ) - 40, $_WinPos[3] ) ) $_WinPos = WinGetPos ( $_HwndChoice ) WinMove ( $_HwndChoice, '', ( @DesktopWidth - $_WinPos[2] ) /2, ( @DesktopHeight - $_WinPos[3] ) /2 -10 ) Sleep ( 250 ) EndFunc ;==> _SetWindowPos ( ) Func _GetVisibleWinList ( ) $_WinList = WinList ( ) Dim $_WinListOut[1] For $_I = 1 To $_WinList[0][0] $_Pos = WinGetPos ( $_WinList[$_I][1] ) If _IsVisible ( $_WinList[$_I][1] ) And $_WinList[$_I][0] <> '' And $_Pos[2] * $_Pos[3] <> 0 Then _ArrayAdd ( $_WinListOut, $_WinList[$_I][1] ) Next Return $_WinListOut EndFunc ;==> _GetVisibleWinList ( ) Func _IsVisible ( $_Hwnd ) If BitAnd ( WinGetState ( $_Hwnd ), 2 ) Then Return 1 EndFunc ;==> _IsVisible ( ) Func _IsMinimized ( $_Hwnd ) If BitAnd ( WinGetState ( $_Hwnd ), 16 ) Then Return 1 EndFunc ;==> _IsMinimized ( ) Func _IsMaximized ( $_Hwnd ) If BitAnd ( WinGetState ( $_Hwnd ), 32 ) Then Return 1 EndFunc ;==> _IsMaximized ( ) Func _OnTop ( ) $_State = _IsTrayItemChecked ( $_OnTopItem ) RegWrite ( $_RegKeySettings, 'OnTop', 'REG_SZ', $_State ) WinSetOnTop ( $_Gui, '', $_State ) EndFunc ;==> _OnTop ( ) Func _IsTrayItemChecked ( $_TrayItem ) Return BitAND ( TrayItemGetState ( $_TrayItem ), $TRAY_CHECKED ) EndFunc ;==> _IsTrayItemChecked ( ) Func _Minimize ( ) TrayItemSetState ( $_MinimizeItem, $TRAY_UNCHECKED ) If _IsVisible ( $_Gui ) Then TrayItemSetText ( $_MinimizeItem, 'Restore Window' ) GUISetState ( @SW_HIDE, $_Gui ) Else TrayItemSetText ( $_MinimizeItem, 'Minimize To Tray' ) GUISetState ( @SW_SHOW, $_Gui ) GUISetState ( @SW_RESTORE, $_Gui ) EndIf EndFunc ;==> _Minimize ( ) #EndRegion --- Windows ------------------------------ Func _StartWithWindows ( ) If Not @Compiled Then TrayItemSetState ( $_StartItem, $TRAY_UNCHECKED ) MsgBox ( 262144, '', 'Script must be Compiled !' & @CRLF, 3 ) Return EndIf $_ItemGetState = TrayItemGetState ( $_StartItem ) If $_ItemGetState = $TRAY_CHECKED + $TRAY_ENABLE Then RegWrite ( 'HKCU\Software\Microsoft\Windows\CurrentVersion\Run', $_RegTitleKey, 'REG_SZ', @ScriptFullPath ) Else RegDelete ( 'HKCU\Software\Microsoft\Windows\CurrentVersion\Run', $_RegTitleKey ) EndIf EndFunc ;==> _StartWithWindows ( ) Func _About ( ) TraySetState ( 2 ) TrayItemSetState ( $_AboutItem, $TRAY_UNCHECKED ) MsgBox ( 262144+64 + 8192, 'About', 'Informations' & @CRLF & @CRLF & $_Version & @CRLF & @CRLF _ & 'Hi AutoIt coders !' & @CRLF & @CRLF _ & 'You can easily Capture by click and drag with your mouse or a complete Windows by selecting in the combo list.' & @TAB & @CRLF _ & 'All Captures are displayed in Microsoft Picture Viewer for get a preview before upload them.' & @CRLF _ & 'You can use the "Upload Capture" button or Drag & Drop an external pic on the frog' & @CRLF _ & 'for Upload it to http://imgur.com/.' & @CRLF _ & 'A temporary copy of your picture will be converted to jpg before being uploaded.( Not Animated Gifs < 2Mo )' & @CRLF _ & 'Picture will be opened in your default browser and direct link url will be copied to the clipboard.' & @CRLF _ & 'Your settings are automatically saved on exit.' & @CRLF _ & 'Double click on tray icon for restore or minimize Gui.' & @CRLF _ & 'By default ' & @MyDocumentsDir & ' is the Save directory.' & @CRLF & @CRLF _ & 'See Tray menu for options.' & @CRLF _ & 'Thanks to use TinyPicCaptureUploader !' & @CRLF & @CRLF _ & 'Thanks to AutoIt Community.' & @CRLF & @CRLF _ & 'wakillon.' ) TraySetState ( 1+4 ) EndFunc ;==> _About ( ) Func _MuteSounds ( ) $_RegRead = RegRead ( $_RegKeySettings, 'MuteSounds' ) If $_Mute=1 Then $_Mute=0 TrayItemSetState ( $_MuteItem, $TRAY_UNCHECKED ) RegWrite ( $_RegKeySettings, 'MuteSounds', 'REG_SZ', 0 ) Else $_Mute=1 TrayItemSetState ( $_MuteItem, $TRAY_CHECKED ) RegWrite ( $_RegKeySettings, 'MuteSounds', 'REG_SZ', 1 ) EndIf EndFunc ;==> _MuteSounds ( ) Func _OpenImgur ( ) TrayItemSetState ( $_ImgurItem, $TRAY_UNCHECKED ) _OpenInDefaultBrowser ( 'http://imgur.com/' ) EndFunc ;==> _OpenImgur ( ) Func _OpenTopic ( ) TrayItemSetState ( $_TopicItem, $TRAY_UNCHECKED ) _OpenInDefaultBrowser ( 'http://www.autoitscript.com/forum/topic/122168-tinypiccaptureuploader' ) EndFunc ;==> _OpenTopic ( ) Func _OpenInDefaultBrowser ( $_Url ) If FileExists ( $_DefaultBrowser ) Then ShellExecute ( $_Url ) Else ShellExecute ( 'iexplore.exe', $_Url ) EndIf EndFunc ;==> _OpenInDefaultBrowser ( ) Func _OpenSaveDir ( ) TrayItemSetState ( $_SaveDirItem, $TRAY_UNCHECKED ) ShellExecute ( @MyDocumentsDir ) EndFunc ;==> _OpenSaveDir ( ) #Region ------ Tray ------------------------------ Func _SetTrayMenu ( ) TraySetIcon ( @WindowsDir & '\Imgur.ico' ) $_TopicItem = TrayCreateItem ( $_Version ) TrayItemSetOnEvent ( -1, '_OpenTopic' ) TrayCreateItem ( '' ) $_StartItem = TrayCreateItem ( 'Start Minimized With Windows' ) TrayItemSetOnEvent ( -1, '_StartWithWindows' ) $_RegRead = RegRead ( 'HKCU\Software\Microsoft\Windows\CurrentVersion\Run', $_RegTitleKey ) If $_RegRead <> '' Then TrayItemSetState ( $_StartItem, $TRAY_CHECKED ) TrayCreateItem ( '' ) $_OnTopItem = TrayCreateItem ( 'Always on Top' ) TrayItemSetOnEvent ( -1, '_OnTop' ) $_RegRead = RegRead ( $_RegKeySettings, 'OnTop' ) If $_RegRead = '' Or $_RegRead = 1 Then TrayItemSetState ( $_OnTopItem, $TRAY_CHECKED ) Else TrayItemSetState ( $_OnTopItem, $TRAY_UNCHECKED ) EndIf TrayCreateItem ( '' ) $_MuteItem = TrayCreateItem ( 'Mute Sounds' ) TrayItemSetOnEvent ( -1, '_MuteSounds' ) $_RegRead = RegRead ( $_RegKeySettings, 'MuteSounds' ) If $_RegRead = '' Or $_RegRead = 0 Then $_Mute=0 TrayItemSetState ( $_MuteItem, $TRAY_UNCHECKED ) Else $_Mute=1 TrayItemSetState ( $_MuteItem, $TRAY_CHECKED ) EndIf TrayCreateItem ( '' ) $_ImgurItem = TrayCreateItem ( 'Open Imgur.com' ) TrayItemSetOnEvent ( -1, '_OpenImgur' ) TrayCreateItem ( '' ) $_SaveDirItem = TrayCreateItem ( 'Open Save Directory' ) TrayItemSetOnEvent ( -1, '_OpenSaveDir' ) TrayCreateItem ( '' ) $_MinimizeItem = TrayCreateItem ( 'Minimize To Tray' ) TrayItemSetOnEvent ( -1, '_Minimize' ) TrayCreateItem ( '' ) $_AboutItem = TrayCreateItem ( 'About' ) TrayItemSetOnEvent ( -1, '_About' ) TrayCreateItem ( '' ) TrayCreateItem ( 'Exit' ) TrayItemSetOnEvent ( -1, '_Exit' ) TraySetClick ( 16 ) TraySetState ( 4 ) TraySetOnEvent ( $TRAY_EVENT_PRIMARYDOUBLE, '_Minimize' ) TraySetToolTip ( $_Version ) EndFunc ;==> _SetTrayMenu ( ) Func _TrayTipClose ( ) AdlibUnRegister ( '_TrayTipClose' ) TrayTip ( '', '', 1, 1 ) EndFunc ;==> _TrayTipClose ( ) Func _TrayTip ( $_Title, $_Texte= '...', $_Ico=0 ) TrayTip ( $_Title, $_Texte, 3, $_Ico ) AdlibRegister ( '_TrayTipClose', 4000 ) EndFunc ;==> _TrayTip ( ) #EndRegion --- Tray ------------------------------ #Region ------ Init ------------------------------ Func _FileMissing ( ) If Not FileExists ( $_TempDir ) Then Return True If Not FileExists ( $_ImgurPicPath ) Then Return True If Not FileExists ( $_TempDir & '\curl.exe' ) Then Return True If Not FileExists ( $_TempDir & '\SkinH_EL.dll' ) Then Return True If Not FileExists ( $_TempDir & '\itunes.she' ) Then Return True If Not FileExists ( @WindowsDir & '\Imgur.ico' ) Then Return True If Not FileExists ( @WindowsDir & '\media\Ding2.wav' ) Then Return True If Not FileExists ( @WindowsDir & '\media\Final.wav' ) Then Return True If Not FileExists ( @WindowsDir & '\cursors\viseur_16885.cur' ) Then Return True If Not FileExists ( @SystemDir & '\TrIDLib.DLL' ) Then Return True If Not FileExists ( @SystemDir & '\TrIDDefs.TRD' ) Then Return True EndFunc ;==> _FileMissing ( ) Func _FileInstall ( ) RegWrite ( 'HKCU\Software\Microsoft\WINDOWS\CurrentVersion\Explorer\Advanced', 'EnableBalloonTips', 'REG_DWORD', 0x00000001 ) ; Enable Balloon Tips. ToolTip ( _StringRepeat ( ' ', 18 ) & 'Please Wait while downloading externals files' & @Crlf, @DesktopWidth/2-152, 0, $_Version, 1, 4 ) Local $_Url = 'http://tinyurl.com/dyzf24r/' If Not _IsConnected ( ) Then Exit MsgBox ( 262144+4096+16, 'Error', 'You are Not Connected !' & @CRLF & 'Retry Later' & @CRLF & 'Exiting...' ) If Not FileExists ( $_TempDir ) Then Dircreate ( $_TempDir ) If Not FileExists ( @WindowsDir & '\media\Ding2.wav' ) Then InetGet ( $_Url & 'Ding.wav', @WindowsDir & '\media\Ding2.wav', 9, 1 ) If Not FileExists ( @WindowsDir & '\media\Final.wav' ) Then InetGet ( $_Url & 'Final.wav', @WindowsDir & '\media\Final.wav', 9, 1 ) If Not FileExists ( $_ImgurPicPath ) Then InetGet ( $_Url & 'Imgur3.jpg', $_ImgurPicPath, 9, 0 ) If Not FileExists ( @WindowsDir & '\cursors\viseur_16885.cur' ) Then InetGet ( $_Url & 'viseur_16885.cur', @WindowsDir & '\cursors\viseur_16885.cur', 9, 0 ) If Not FileExists ( $_TempDir & '\SkinH_EL.dll' ) Then InetGet ( $_Url & 'SkinH_EL.dll', $_TempDir & '\SkinH_EL.dll', 9, 0 ) If Not FileExists ( $_TempDir & '\itunes.she' ) Then InetGet ( $_Url & 'itunes.she', $_TempDir & '\itunes.she', 9, 0 ) If Not FileExists ( @WindowsDir & '\Imgur.ico' ) Then InetGet ( $_Url & 'Imgur.ico', @WindowsDir & '\Imgur.ico', 9, 0 ) If Not FileExists ( @SystemDir & '\TrIDLib.DLL' ) Then InetGet ( $_Url & 'TrIDLib.dll', @SystemDir & '\TrIDLib.DLL', 9, 1 ) If Not FileExists ( @SystemDir & '\TrIDDefs.TRD' ) Then InetGet ( $_Url & 'triddefs.trd', @SystemDir & '\TrIDDefs.TRD', 9, 1 ) If Not FileExists ( $_TempDir & '\curl.exe' ) Then _DownloadCurl ( ) ToolTip ( '' ) EndFunc ;==> _FileInstall ( ) Func _DownloadCurl ( ) Local $_FilePath = $_TempDir & '\curl.exe' FileDelete ( $_FilePath ) Local $_BinaryCurl = StringRegExp ( _GetSourceCode ( 'http://tinyurl.com/5wy72ny' ), '(?s)(?i) _DownloadCurl ( ) #EndRegion --- Init ------------------------------ Func _Exit ( ) DllClose ( $_Dll ) DllCall ( 'user32.dll', 'int', 'AnimateWindow', 'hwnd', $_Gui, 'int', 1000, 'long', 0x00050010 ) _GDIPlus_ShutDown ( ) GUIDelete ( $_Gui ) Exit EndFunc ;==> _Exit ( ) Func _OnAutoItExit ( ) Opt ( 'TrayIconHide', 0 ) $_Split = StringSplit ( $_Version, '©' ) If Not @error Then TrayTip ( $_Split[1], $_Split[2], 1, 1 ) Sleep ( 2000 ) TrayTip ( '', '', 1, 1 ) EndFunc ;==> _OnAutoItExit ( )