msgbox

VkScreenshot v0.1

Jul 19th, 2011
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; http://msgbox.vk.com
  2.  
  3.  
  4.     Pass := ""
  5.     Login := ""
  6.     Link_To_Album := "http://vkontakte.ru/album37047698_135055718"
  7.  
  8.  
  9. #SingleInstance Force
  10. #Persistent
  11. SName := "VKScreenshot v0.1"
  12. SetBatchLines -1
  13. Menu, Tray, NoStandard
  14. Menu, Tray, Add, Exit, OnExit
  15. return
  16.  
  17.  
  18. Lbutton::
  19. Gui, Color, 000000
  20. Gui, Font, s10 Bold, Tahoma
  21. Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound +DLGFRAME
  22. Gui, Add, Text, x10 y10 w80 h80 BackgroundTrans cwhite, Width:
  23. Gui, Add, Text, x10 y28 w80 h80 BackgroundTrans cwhite, Height:
  24. Gui, Add, Text, x60 y10 w80 h80 BackgroundTrans vCX cwhite,
  25. Gui, Add, Text, x60 y28 w80 h80 BackgroundTrans vCY cwhite,
  26. WinSet, Transparent, 125
  27.     CoordMode, Mouse ,Screen
  28.     MouseGetPos, MX, MY
  29.     While, (GetKeyState("LButton", "p"))  {
  30.     MouseGetPos, MXend, MYend
  31.         h  := Abs(MY - MYend)
  32.         w  := Abs(MX - MXend)
  33.     If (MXend!=LCX && MYend!=LCY)  {
  34.     GuiControl,, CX, %w%
  35.     GuiControl,, CY, %h%
  36.     LCX := MXend
  37.     LCY := MYend
  38.     }
  39.     If (MX < MXend)
  40.         X := MX
  41.         Else
  42.         X := MXend
  43.     If (MY < MYend)
  44.         Y := MY
  45.         Else
  46.         Y := MYend
  47.         Gui, Show, x%X% y%Y% w%w% h%h%
  48.     if (GetKeyState("p", "p"))
  49.         {
  50.         Gui, Destroy
  51.         ; Send, {LButton up}
  52.         Return
  53.         }
  54.     sleep, 5
  55.     }
  56.     MouseGetPos, MXend, MYend
  57.     Gui, Destroy
  58.     If (MX > MXend)
  59.         {
  60.         temp := MX
  61.         MX := MXend
  62.         MXend := temp
  63.         }
  64.     If (MY > MYend)
  65.         {
  66.         temp := MY
  67.         MY := MYend
  68.         MYend := temp
  69.         }
  70.     CaptureScreen("" MX ", " MY ", " MXend ", " MYend "")
  71.     Image := a_scriptdir "\ScreenShot.jpg"
  72.     httpQueryOps:="storeHeader"
  73.     httpAgent :="Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.10"
  74.     httpQueryDwFlags:=(INTERNET_FLAG_NO_COOKIES:=0x00080000|INTERNET_FLAG_NO_AUTO_REDIRECT:=0x00200000)
  75.     URL:="http://login.vk.com/?act=login&email=" Login "&pass=" Pass ""
  76.     length:=httpQuery(data:="",URL)
  77.     varSetCapacity(data,-1)
  78.     RegExMatch(HttpQueryHeader,"hash=(.*?)&",hash)
  79.     URL:="http://vk.com/login.php?act=slogin&fast=1&hash=" hash1 "&redirect=1&s=1"
  80.     httpQuery(data:="",URL)
  81.     varSetCapacity(data,-1)
  82.     if HttpQueryHeader contains deleted
  83.     {
  84.     MsgBox, 64, % SName, Auth failed!
  85.     ExitApp
  86.     }else{
  87.     SID := RegexReplace(HttpQueryHeader, ".*remixsid=(.*?); .*", "$1")
  88.     Cookie:= "Cookie: remixsid=" SID ";"
  89.     httpQueryDwFlags:=(INTERNET_FLAG_NO_COOKIES:=0x00080000)
  90.     }
  91.     FileGetSize,size,%image%
  92.     SplitPath,image,OFN
  93.     FileRead,img,%image%
  94.     VarSetCapacity(placeholder,size,32)
  95.     Link := Link_To_Album "?act=add"
  96.     httpQuery(data:="", Link_To_Album, POSTdata, HEADERS:=Cookie)
  97.     VarsetCapacity(data, -1)
  98.     Temp := RegexReplace(data, ".*event[)]""></a>(.*?)<span class=""divide.*", "$1")
  99.     StringSplit, Temp, Temp, %a_space%
  100.     AlbumOffset := Temp1
  101.     Vars := "id,aid,gid,mid,hash,rhash"
  102.     httpQuery(data:="", Link, POSTdata, HEADERS:=Cookie)
  103.     VarsetCapacity(data, -1)
  104.     Loop, parse, Vars, `,
  105.     if (a_loopfield!="hash" && a_loopfield!="rhash" && a_loopfield!="url")
  106.     %a_loopfield% := regexreplace(data, ".*""" a_loopfield """:(.*?),.*", "$1")
  107.     else
  108.     %a_loopfield% := regexreplace(data, ".*""" a_loopfield """:""(.*?)"".*", "$1")
  109.     URL := "http://cs"(regexreplace(data, ".*url: 'http://cs(.*?)',.*", "$1"))""
  110.     boundary := "----------" . makeProperBoundary()
  111.     POSTdata:="--" boundary "`n"
  112.     . "Content-disposition: form-data; name=""act""`n`ndo_add`n--" boundary "`n"
  113.     . "Content-disposition: form-data; name=""id""`n`n" id "`n--" boundary "`n"
  114.     . "Content-disposition: form-data; name=""aid""`n`n" aid "`n--" boundary "`n"
  115.     . "Content-disposition: form-data; name=""gid""`n`n" gid "`n--" boundary "`n"
  116.     . "Content-disposition: form-data; name=""mid""`n`n" mid "`n--" boundary "`n"
  117.     . "Content-disposition: form-data; name=""hash""`n`n" hash "`n--" boundary "`n"
  118.     . "Content-disposition: form-data; name=""vk""`n`n`n--" boundary "`n"
  119.     . "Content-disposition: form-data; name=""rhash""`n`n" rhash "`n--" boundary "`n"
  120.     . "Content-disposition: form-data; name=""file1""; filename=""" ofn """`n"
  121.     . "Content-type: " MimeType(img) "`n`n" placeholder "`n--" boundary "--"
  122.     HEADERS:="Content-type: multipart/form-data, "
  123.     . "boundary=" boundary "`nContent-Length: " strlen(POSTdata)  "`n" cookie
  124.     DllCall("RtlMoveMemory","uInt"
  125.     ,(offset:=&POSTdata+strlen(POSTdata)-strlen(Boundary)-size-5)
  126.     ,"uInt",&img,"uInt",size)
  127.     httpQuery(data:="",URL,POSTdata,HEADERS)
  128.     varSetCapacity(data, -1)
  129.     if data not contains Security
  130.         TrayTip, %SName%, Okay!,1,1,1
  131.         else
  132.         {
  133.         TrayTip, %SName%, Fuck! There's an error!,1,1,1
  134.         ExitApp
  135.         }
  136.     FileDelete, ScreenShot.jpg
  137.     Esc::
  138.     OnExit:
  139.     ExitApp
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. MD5( ByRef V, L=0 ) {
  148.  VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
  149.  DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) )
  150.  DllCall( "advapi32\MD5Final", Str,MD5_CTX )
  151.  Loop % StrLen( Hex:="123456789ABCDEF0" )
  152.   N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
  153. Return MD5
  154. }
  155.  
  156. makeProperBoundary(){
  157.    Loop,26
  158.    n .= chr(64+a_index)
  159.    n .= "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
  160.    Loop,% StrLen(A_Now) {
  161.    Random,rnd,1,% StrLen(n)
  162.    Random,UL,0,1
  163.    b .= RegExReplace(SubStr(n,rnd,1),".$","$" (round(UL)? "U":"L") "0")
  164.    }
  165. Return b
  166. }
  167.  
  168.  
  169. UtfDecode( str )  {
  170.   RawLen := StrLen(str)
  171.   Charset := 0
  172.   BufSize := (RawLen + 1) * 2
  173.   VarSetCapacity(Buf, BufSize, 0)
  174.   DllCall("MultiByteToWideChar", "uint", 65001, "int", 0, "str", str
  175.   , "int", -1, "uint", &Buf, "uint", RawLen + 1)
  176.   DllCall("WideCharToMultiByte", "uint", Charset, "int", 0, "uint", &Buf, "int", -1
  177.   , "str", str, "uint", RawLen + 1
  178.   , "int", 0, "int", 0)
  179. Return str
  180. }
  181.  
  182. MimeType(ByRef Binary) {
  183. MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpg|89504e4 image/png|4657530"
  184.    . " application/x-shockwave-flash|49492a0 image/tiff"
  185.    @:="0123456789abcdef"
  186.    Loop,8
  187.    hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1)
  188.    Loop,Parse,MimeTypes,|
  189.    if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n)
  190.    Mime := RegExReplace(A_LoopField,".*?\s")
  191. Return (Mime!="") ? Mime : "application/octet-stream"
  192. }
  193.    
  194.  
  195. URLEncode( p_data,p_reserved=true,p_encode=true)  {
  196.    old_FormatInteger := A_FormatInteger
  197.    SetFormat, Integer, hex
  198.     unsafe := "25000102030405060708090A0B0C0D0E"
  199.     . "0F101112131415161718191A1B1C1D1E1F20222"
  200.     . "33C3E5B5C5D5E607B7C7D7F808182838485868"
  201.     . "788898A8B8C8D8E8F909192939495969798999A"
  202.     . "9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABAC"
  203.     . "ADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDB"
  204.     . "EBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCEC"
  205.     . "FD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF7"
  206.     . "EE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0"
  207.     . "F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"
  208.    if (p_reserved)
  209.       unsafe = %unsafe%24262B2C2F3A3B3D3F40
  210.    if ( p_encode )
  211.     loop, % StrLen(unsafe)//2
  212.     {
  213.     StringMid, token, unsafe, A_Index*2-1, 2
  214.     StringReplace, p_data, p_data, % Chr( "0x" token ), `%%token%, all
  215.     }else
  216.     loop, % StrLen(unsafe)//2
  217.     {
  218.     StringMid, token, unsafe, A_Index*2-1, 2
  219.     StringReplace, p_data, p_data, `%%token%, % Chr("0x"token), all
  220.     }
  221.    SetFormat, Integer, %old_FormatInteger%
  222. return, p_data
  223. }
  224.  
  225.  
  226.  
  227. URLDecode( p_data )  {
  228. return, URLEncode( p_data, true, false )
  229. }
  230.  
  231. httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")  {
  232.    global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType
  233.        , httpQueryDwFlags
  234.    defaultOps =
  235.    (LTrim Join|
  236.       httpAgent=script|httpProxy=0|httpProxyByPass=0|INTERNET_FLAG_SECURE=0x00800000
  237.       SECURITY_FLAG_IGNORE_UNKNOWN_CA=0x00000100|SECURITY_FLAG_IGNORE_CERT_CN_INVALID=0x00001000
  238.       SECURITY_FLAG_IGNORE_CERT_DATE_INVALID=0x00002000|SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE=0x00000200
  239.       INTERNET_OPEN_TYPE_PROXY=3|INTERNET_OPEN_TYPE_DIRECT=1|INTERNET_SERVICE_HTTP=3
  240.    )
  241.    Loop,Parse,defaultOps,|
  242.    {
  243.       RegExMatch(A_LoopField,"(?P<Option>[^=]+)=(?P<Default>.*)",http)
  244.       if StrLen(%httpOption%)=0
  245.          %httpOption% := httpDefault
  246.    }
  247.  
  248.    hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll")
  249.  
  250.    offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|"
  251.                   . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024"
  252.    VarSetCapacity(URL_COMPONENTS,60,0)
  253.    NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24)
  254.    
  255.    Loop,Parse,offset_name_length,|
  256.    {
  257.       RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_)
  258.       VarSetCapacity(%iCU_Name%,iCU_Size,0)
  259.       NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset)
  260.       NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4)
  261.    }
  262.  
  263.    DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS)
  264.  
  265.    Loop,Parse,offset_name_length,|
  266.    {
  267.       RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_)
  268.       VarSetCapacity(%iCU_Name%,-1)
  269.    }
  270.    nPort:=NumGet(URL_COMPONENTS,24,"uInt")
  271.    
  272.    dwFlags := httpQueryDwFlags
  273.    if (lpszScheme = "https")
  274.       dwFlags |= (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
  275.                |SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)
  276.  
  277.    if (lpszScheme="unknown") {
  278.       Result := "ERR: No Valid URL supplied."
  279.       Return StrLen(Result)
  280.    }
  281.  
  282.    hInternet := DllCall("WinINet\InternetOpenA"
  283.                   ,"Str",httpAgent,"UInt"
  284.                   ,(httpProxy != 0 ?  INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT )
  285.                   ,"Str",httpProxy,"Str",httpProxyBypass,"Uint",0)
  286.  
  287.    hConnect := DllCall("WinINet\InternetConnectA"
  288.                   ,"uInt",hInternet,"Str",lpszHostname, "Int",nPort
  289.                   ,"Str",lpszUserName, "Str",lpszPassword,"uInt",INTERNET_SERVICE_HTTP
  290.                   ,"uInt",0,"uInt*",0)
  291.  
  292.    if (Strlen(POSTDATA)>0) {
  293.       HTTPVerb:="POST"
  294.       if StrLen(Headers)=0
  295.          Headers:="Content-Type: application/x-www-form-urlencoded"
  296.    } else
  297.       HTTPVerb:="GET"    
  298.  
  299.    hRequest := DllCall("WinINet\HttpOpenRequestA"
  300.                   ,"uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo
  301.                   ,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes
  302.                   ,"uInt",dwFlags,"uInt",Context:=0 )
  303.  
  304.    sRequest := DllCall("WinINet\HttpSendRequestA"
  305.                   , "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers)
  306.                   , "Str",POSTData,"uInt",Strlen(POSTData))
  307.  
  308.    VarSetCapacity(header, 2048, 0)
  309.    VarSetCapacity(header_len, 4, 0)
  310.    
  311.    Loop, 5
  312.      if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest
  313.       ,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)
  314.       break
  315.  
  316.    If (headerRequest=1) {
  317.       VarSetCapacity(res,headerLength:=NumGet(header_len),32)
  318.       DllCall("RtlMoveMemory","uInt",&res,"uInt",&header,"uInt",headerLength)
  319.       Loop,% headerLength
  320.          if (*(&res-1+a_index)=0)
  321.             NumPut(Asc("`n"),res,a_index-1,"uChar")
  322.       VarSetCapacity(res,-1)
  323.    } else
  324.       res := "timeout"
  325.  
  326.    Loop,Parse,res,`n,`r
  327.    {
  328.       RetValue := A_LoopField
  329.       break
  330.    }
  331.    
  332.    If (RetValue="timeout") {
  333.       html := "Error: timeout"
  334.       return -1
  335.    }
  336.    RetValue := RegExReplace(RetValue,"HTTP/1\.[01]\s+")
  337.    
  338.    RetValue := SubStr(RetValue,1,3)
  339.    
  340.    if strlen(HTTPQueryOps)>0 {
  341.       if (instr(HTTPQueryOps,"showHeader"))
  342.          MsgBox % res
  343.       if (instr(HTTPQueryOps,"storeHeader"))
  344.          global HttpQueryHeader := res
  345.       if (instr(HTTPQueryOps,"updateSize")) {
  346.          Loop,Parse,res,`n
  347.             If RegExMatch(A_LoopField,"Content-Length:\s+?(?P<Size>\d+)",full) {
  348.                global HttpQueryFullSize := fullSize
  349.                break
  350.             }
  351.          if (fullSize+0=0)
  352.             HttpQueryFullSize := "size unavailable"
  353.       }
  354.    }
  355.  
  356.    if !(InStr("100 200 201 202 302",RetValue)) {
  357.       Result := RetValue " " RetMsg
  358.       return StrLen(Result)
  359.    }
  360.  
  361.    VarSetCapacity(BytesRead,4,0)
  362.    fsize := 0
  363.    Loop            
  364.    {  bc := A_Index
  365.       VarSetCapacity(buffer%bc%,1024,0)
  366.       ReadFile := DllCall("wininet\InternetReadFile"
  367.                   ,"uInt",hRequest,"uInt",&buffer%bc%,"uInt",1024,"uInt",&BytesRead)
  368.       ReadBytes := NumGet(BytesRead)  
  369.       If ((ReadFile!=0)&&(!ReadBytes))  
  370.          break                      
  371.       Else {
  372.          fsize += ReadBytes  
  373.          sizeArray .= ReadBytes "|"
  374.       }
  375.       if (instr(HTTPQueryOps,"updateSize"))
  376.          Global HttpQueryCurrentSize := fsize
  377.    }
  378.    sizeArray := SubStr(sizeArray,1,-1)  
  379.    
  380.    VarSetCapacity(result,fSize+1,0)      
  381.    Dest := &result            
  382.    Loop,Parse,SizeArray,|
  383.       DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField)
  384.       , Dest += A_LoopField
  385.      
  386.    DllCall("WinINet\InternetCloseHandle", "uInt", hRequest)  
  387.    DllCall("WinINet\InternetCloseHandle", "uInt", hInternet)
  388.    DllCall("WinINet\InternetCloseHandle", "uInt", hConnect)
  389.    DllCall("FreeLibrary", "UInt", hModule)              
  390.    return fSize
  391. }
  392.  
  393.  
  394.  
  395.  
  396.  
  397. CaptureScreen(aRect = 0, bCursor = False, sFile = "", nQuality = "100")
  398. {
  399.     If  !aRect
  400.     {
  401.         SysGet, nL, 76
  402.         SysGet, nT, 77
  403.         SysGet, nW, 78
  404.         SysGet, nH, 79
  405.     }
  406.     Else If aRect = 1
  407.         WinGetPos, nL, nT, nW, nH, A
  408.     Else If aRect = 2
  409.     {
  410.         WinGet, hWnd, ID, A
  411.         VarSetCapacity(rt, 16, 0)
  412.         DllCall("GetClientRect" , "Uint", hWnd, "Uint", &rt)
  413.         DllCall("ClientToScreen", "Uint", hWnd, "Uint", &rt)
  414.         nL := NumGet(rt, 0, "int")
  415.         nT := NumGet(rt, 4, "int")
  416.         nW := NumGet(rt, 8)
  417.         nH := NumGet(rt,12)
  418.     }
  419.     Else If aRect = 3
  420.     {
  421.         VarSetCapacity(mi, 40, 0)
  422.         DllCall("GetCursorPos", "int64P", pt)
  423.         DllCall("GetMonitorInfo", "Uint", DllCall("MonitorFromPoint", "int64", pt, "Uint", 2), "Uint", NumPut(40,mi)-4)
  424.         nL := NumGet(mi, 4, "int")
  425.         nT := NumGet(mi, 8, "int")
  426.         nW := NumGet(mi,12, "int") - nL
  427.         nH := NumGet(mi,16, "int") - nT
  428.     }
  429.     Else
  430.     {
  431.         StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
  432.         nL := rt1
  433.         nT := rt2
  434.         nW := rt3 - rt1
  435.         nH := rt4 - rt2
  436.         znW := rt5
  437.         znH := rt6
  438.     }
  439.  
  440.     mDC := DllCall("CreateCompatibleDC", "Uint", 0)
  441.     hBM := CreateDIBSection(mDC, nW, nH)
  442.     oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
  443.     hDC := DllCall("GetDC", "Uint", 0)
  444.     DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
  445.     DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
  446.     If  bCursor
  447.         CaptureCursor(mDC, nL, nT)
  448.     DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
  449.     DllCall("DeleteDC", "Uint", mDC)
  450.     If  znW && znH
  451.         hBM := Zoomer(hBM, nW, nH, znW, znH)
  452.     If  sFile = 0
  453.         SetClipboardData(hBM)
  454.     Else    Convert(hBM, sFile, nQuality), DllCall("DeleteObject", "Uint", hBM)
  455. }
  456.  
  457. CaptureCursor(hDC, nL, nT)
  458. {
  459.     VarSetCapacity(mi, 20, 0), mi := Chr(20)
  460.     DllCall("GetCursorInfo", "Uint", &mi)
  461.     bShow   := NumGet(mi, 4)
  462.     hCursor := NumGet(mi, 8)
  463.     xCursor := NumGet(mi,12)
  464.     yCursor := NumGet(mi,16)
  465.  
  466.     If  bShow && hCursor:=DllCall("CopyIcon", "Uint", hCursor)
  467.     {
  468.     VarSetCapacity(ni, 20, 0)
  469.     DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
  470.     bIcon    := NumGet(ni, 0)
  471.     xHotspot := NumGet(ni, 4)
  472.     yHotspot := NumGet(ni, 8)
  473.     hBMMask  := NumGet(ni,12)
  474.     hBMColor := NumGet(ni,16)
  475.  
  476.     DllCall("DrawIcon", "Uint", hDC, "int", xCursor - xHotspot - nL, "int", yCursor - yHotspot - nT, "Uint", hCursor)
  477.     DllCall("DestroyIcon", "Uint", hCursor)
  478.     If  hBMMask
  479.     DllCall("DeleteObject", "Uint", hBMMask)
  480.     If  hBMColor
  481.     DllCall("DeleteObject", "Uint", hBMColor)
  482.     }
  483. }
  484.  
  485. Zoomer(hBM, nW, nH, znW, znH)
  486. {
  487.     mDC1 := DllCall("CreateCompatibleDC", "Uint", 0)
  488.     mDC2 := DllCall("CreateCompatibleDC", "Uint", 0)
  489.     zhBM := CreateDIBSection(mDC2, znW, znH)
  490.     oBM1 := DllCall("SelectObject", "Uint", mDC1, "Uint",  hBM)
  491.     oBM2 := DllCall("SelectObject", "Uint", mDC2, "Uint", zhBM)
  492.     DllCall("SetStretchBltMode", "Uint", mDC2, "int", 4)
  493.     DllCall("StretchBlt", "Uint", mDC2, "int", 0, "int", 0, "int", znW, "int", znH, "Uint", mDC1, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020)
  494.     DllCall("SelectObject", "Uint", mDC1, "Uint", oBM1)
  495.     DllCall("SelectObject", "Uint", mDC2, "Uint", oBM2)
  496.     DllCall("DeleteDC", "Uint", mDC1)
  497.     DllCall("DeleteDC", "Uint", mDC2)
  498.     DllCall("DeleteObject", "Uint", hBM)
  499.     Return  zhBM
  500. }
  501.  
  502. Convert(sFileFr = "", sFileTo = "", nQuality = "100")
  503. {
  504.     If  sFileTo  =
  505.         sFileTo := A_ScriptDir . "\ScreenShot.jpg"
  506.     SplitPath, sFileTo, , sDirTo, sExtTo, sNameTo
  507.  
  508.     If Not  hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll")
  509.         Return  sFileFr+0 ? SaveHBITMAPToFile(sFileFr, sDirTo . "\" . sNameTo . ".bmp") : ""
  510.     VarSetCapacity(si, 16, 0), si := Chr(1)
  511.     DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)
  512.  
  513.     If  !sFileFr
  514.     {
  515.         DllCall("OpenClipboard", "Uint", 0)
  516.         If   DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2))
  517.         DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage)
  518.         DllCall("CloseClipboard")
  519.     }
  520.     Else If sFileFr Is Integer
  521.         DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage)
  522.     Else    DllCall("gdiplus\GdipLoadImageFromFile", "Uint", Unicode4Ansi(wFileFr,sFileFr), "UintP", pImage)
  523.  
  524.     DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
  525.     VarSetCapacity(ci,nSize,0)
  526.     DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)
  527.     Loop, % nCount
  528.         If  InStr(Ansi4Unicode(NumGet(ci,76*(A_Index-1)+44)), "." . sExtTo)
  529.         {
  530.             pCodec := &ci+76*(A_Index-1)
  531.             Break
  532.         }
  533.     If  InStr(".JPG.JPEG.JPE.JFIF", "." . sExtTo) && nQuality<>"" && pImage && pCodec
  534.     {
  535.     DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize)
  536.     VarSetCapacity(pi,nSize,0)
  537.     DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi)
  538.     Loop, % NumGet(pi)
  539.         If  NumGet(pi,28*(A_Index-1)+20)=1 && NumGet(pi,28*(A_Index-1)+24)=6
  540.         {
  541.             pParam := &pi+28*(A_Index-1)
  542.             NumPut(nQuality,NumGet(NumPut(4,NumPut(1,pParam+0)+20)))
  543.             Break
  544.         }
  545.     }
  546.  
  547.     If  pImage
  548.         pCodec  ? DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", Unicode4Ansi(wFileTo,sFileTo), "Uint", pCodec, "Uint", pParam) : DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pImage, "UintP", hBitmap, "Uint", 0) . SetClipboardData(hBitmap), DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
  549.  
  550.     DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)
  551.     DllCall("FreeLibrary", "Uint", hGdiPlus)
  552. }
  553.  
  554. CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
  555. {
  556.     NumPut(VarSetCapacity(bi, 40, 0), bi)
  557.     NumPut(nW, bi, 4)
  558.     NumPut(nH, bi, 8)
  559.     NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
  560.     NumPut(0,  bi,16)
  561.     Return  DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
  562. }
  563.  
  564. SaveHBITMAPToFile(hBitmap, sFile)
  565. {
  566.     DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
  567.     hFile:= DllCall("CreateFile", "Uint", &sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0)
  568.     DllCall("WriteFile", "Uint", hFile, "int64P", 0x4D42|14+40+NumGet(oi,44)<<16, "Uint", 6, "UintP", 0, "Uint", 0)
  569.     DllCall("WriteFile", "Uint", hFile, "int64P", 54<<32, "Uint", 8, "UintP", 0, "Uint", 0)
  570.     DllCall("WriteFile", "Uint", hFile, "Uint", &oi+24, "Uint", 40, "UintP", 0, "Uint", 0)
  571.     DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44), "UintP", 0, "Uint", 0)
  572.     DllCall("CloseHandle", "Uint", hFile)
  573. }
  574.  
  575. SetClipboardData(hBitmap)
  576. {
  577.     DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
  578.     hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
  579.     pDIB := DllCall("GlobalLock", "Uint", hDIB)
  580.     DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
  581.     DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
  582.     DllCall("GlobalUnlock", "Uint", hDIB)
  583.     DllCall("DeleteObject", "Uint", hBitmap)
  584.     DllCall("OpenClipboard", "Uint", 0)
  585.     DllCall("EmptyClipboard")
  586.     DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
  587.     DllCall("CloseClipboard")
  588. }
  589.  
  590. Unicode4Ansi(ByRef wString, sString)
  591. {
  592.     nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
  593.     VarSetCapacity(wString, nSize * 2)
  594.     DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
  595.     Return  &wString
  596. }
  597.  
  598. Ansi4Unicode(pString)
  599. {
  600.     nSize := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int",  0, "Uint", 0, "Uint", 0)
  601.     VarSetCapacity(sString, nSize)
  602.     DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
  603.     Return  sString
  604. }
Advertisement
Add Comment
Please, Sign In to add comment