├── .gitignore ├── Functions ├── Pause.ahk ├── Notify.ahk ├── Suspend.ahk ├── StayAwake.ahk ├── Click.ahk ├── PixelCheck.ahk ├── PixelMap.ahk ├── Window.ahk ├── TimerUtils.ahk ├── PixelSearch.ahk └── Gdip_All.ahk ├── Icons ├── favicon_ahkancolle.ico └── favicon_ahkcsortie.ico ├── Constants ├── PixelColor.ahk └── ExpeditionTime.ahk ├── XYColor.ahk ├── PauseUtility.ahk ├── README.md ├── AHKCSortie.ahk └── AHKanColle.ahk /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.ini 3 | *.jpg 4 | *.db 5 | *.exe 6 | *.bat 7 | Debug -------------------------------------------------------------------------------- /Functions/Pause.ahk: -------------------------------------------------------------------------------- 1 | ;Pause v1.0 2 | 3 | Pause2: 4 | { 5 | Pause 6 | } 7 | 8 | Pause::Pause -------------------------------------------------------------------------------- /Icons/favicon_ahkancolle.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ryuuhou/AHKanColle/HEAD/Icons/favicon_ahkancolle.ico -------------------------------------------------------------------------------- /Icons/favicon_ahkcsortie.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ryuuhou/AHKanColle/HEAD/Icons/favicon_ahkcsortie.ico -------------------------------------------------------------------------------- /Functions/Notify.ahk: -------------------------------------------------------------------------------- 1 | ;Notify v1.60803 2 | 3 | Notify(n,m,i) 4 | { 5 | global NotificationLevel 6 | if (NotificationLevel >= i) 7 | { 8 | TrayTip, %n%, %m%,,17 9 | } 10 | return 11 | } -------------------------------------------------------------------------------- /Functions/Suspend.ahk: -------------------------------------------------------------------------------- 1 | ;Suspend v1.0 2 | 3 | SysIntSuspend(sus) 4 | { 5 | if sus = 1 6 | { 7 | Run %A_ScriptDir%\Sysinternals\pssuspend.exe KanColleViewer.exe 8 | }else 9 | { 10 | Run %A_ScriptDir%\Sysinternals\pssuspend.exe -r KanColleViewer.exe 11 | } 12 | } -------------------------------------------------------------------------------- /Functions/StayAwake.ahk: -------------------------------------------------------------------------------- 1 | ;StayAwake v1.0 2 | 3 | StayAwake() 4 | { 5 | SetTimer, MoveMouse, 60000 6 | } 7 | 8 | MoveMouse: 9 | { 10 | MouseMove, 1, 0, 1, R ;Move the mouse one pixel to the right 11 | MouseMove, -1, 0, 1, R ;Move the mouse back one pixel 12 | SetTimer, MoveMouse, 60000 13 | return 14 | } -------------------------------------------------------------------------------- /Functions/Click.ahk: -------------------------------------------------------------------------------- 1 | ;Click v1.61121 2 | 3 | ClickS(x,y) 4 | { 5 | global uid 6 | global Background 7 | global XDiff 8 | global YDiff 9 | global Class 10 | global ClickDelay 11 | global coffset 12 | Sleep ClickDelay 13 | WinActivateRestore() 14 | Random, xoff, -coffset, coffset 15 | Random, yoff, -coffset, coffset 16 | if Background = 1 17 | { 18 | SetControlDelay -1 19 | if Class = 0 20 | { 21 | tx := xoff+x 22 | ty := yoff+y 23 | ControlClick, x%tx% y%ty%, ahk_id %uid%,,,,NA Pos 24 | } 25 | else 26 | { 27 | tx := x-XDiff+xoff 28 | ty := y-YDiff+yoff 29 | ControlClick, %Class%,ahk_id %uid%,,,, x%tx% y%ty% 30 | } 31 | } 32 | else if Background = 0 33 | { 34 | tx := xoff+x 35 | ty := yoff+y 36 | Click %tx%, %ty% 37 | } 38 | return 39 | } -------------------------------------------------------------------------------- /Constants/PixelColor.ahk: -------------------------------------------------------------------------------- 1 | ;Pixel Color Constants v1.71216 2 | 3 | HPC := 0x209fa2 ;Home 4 | HEPC := 0x1c8f92 ;Home + Exped 5 | RPC := 0x404041 ;Resupply 6 | SPC := 0x626D6F ;Sortie 7 | S2PC := 0x37444d ;Sortie 2 8 | EPC := 0xEFE8DB ;Expeditions 9 | ESUPC := 0x540907 ;Expedition sent unhovered button 10 | ESHPC := 0x760607 ;Expedition sent hovered button 11 | NRPC := 0x444444 ;Needs Resupply 12 | ECPC := 0xffffff ;Error Cat 13 | RPN := 0xb0887f ;Reference pixel normal 14 | RPNL := 0x686d4a ;Reference pixel left 15 | RPNR := 0xa88665 ;Reference pixel right 16 | RPD := 0x9e7a72 ;Reference pixel dimmed 17 | RPDL := 0x5d6242 ;Reference pixel dimmed left 18 | RPDR := 0x97785b ;Reference pixel dimmed right 19 | REPC := 0xe8dece ;Repair 20 | CPC := 0xd0d5d3 ;Compass 21 | FPC := 0xdedfdc ;Formation 22 | SRPC := 0x202122 ;Sortie Results 23 | NBPC := 0x408 ;Night Battle 24 | CSPC := 0x162629 ;Continue Screen 25 | CCPC := 0xcc5852 ;Critical 26 | IBPC := 0x3a87b3 ;In Battle 27 | EX2PC := 0x23A0A1 ; Expedition 2 highlighted -------------------------------------------------------------------------------- /Constants/ExpeditionTime.ahk: -------------------------------------------------------------------------------- 1 | ;ExpeditionTime 2 | ;Times are in milliseconds 3 | 4 | ET[1] := 900000 5 | ET[2] := 1800000 6 | ET[3] := 1200000 7 | ET[4] := 3000000 8 | ET[5] := 5400000 9 | ET[6] := 2400000 10 | ET[7] := 3600000 11 | ET[8] := 10800000 12 | ET[9] := 14400000 13 | ET[10] := 5400000 14 | ET[11] := 18000000 15 | ET[12] := 28800000 16 | ET[13] := 14400000 17 | ET[14] := 21600000 18 | ET[15] := 43200000 19 | ET[16] := 14400000 20 | ET[17] := 2700000 21 | ET[18] := 18000000 22 | ET[19] := 21600000 23 | ET[20] := 7200000 24 | ET[21] := 8400000 25 | ET[22] := 10800000 26 | ET[23] := 14400000 27 | ET[24] := 30000000 28 | ET[25] := 144000000 29 | ET[26] := 288000000 30 | ET[27] := 72000000 31 | ET[28] := 90000000 32 | ET[29] := 86400000 33 | ET[30] := 172800000 34 | ET[31] := 7200000 35 | ET[32] := 86400000 36 | ET[33] := 900000 ;Support 37 | ET[34] := 1800000 ;Support 38 | ET[35] := 25200000 39 | ET[36] := 32400000 40 | ET[37] := 9900000 41 | ET[38] := 10500000 42 | ET[39] := 108000000 43 | ET[40] := 24600000 44 | -------------------------------------------------------------------------------- /Functions/PixelCheck.ahk: -------------------------------------------------------------------------------- 1 | ;PixelCheck v1.71216 2 | 3 | DEC2HEX(DEC, RARGB="false") 4 | { 5 | SetFormat, IntegerFast, hex 6 | RGB += DEC ;Converts the decimal to hexidecimal 7 | if(RARGB=="true") 8 | RGB := RGB & 0x00ffffff 9 | SetFormat, IntegerFast, d 10 | return RGB 11 | } 12 | 13 | PixelGetColorS(x,y,z := 0) 14 | { 15 | global uid 16 | i := 0 17 | lHEX := 0 18 | WinActivateRestore() 19 | Loop 20 | { 21 | pToken := Gdip_Startup() 22 | pBitmap := Gdip_BitmapFromHWND(uid) 23 | pARGB := GDIP_GetPixel(pBitmap, x, y) 24 | pHEX := DEC2HEX(pARGB,"true") 25 | if (pHEX = lHEX) 26 | { 27 | i += 1 28 | }else 29 | { 30 | lHEX := pHEX 31 | i := 1 32 | } 33 | Gdip_DisposeImage(pBitmap) 34 | Gdip_Shutdown(pToken) 35 | Sleep 50 36 | }Until i > z 37 | return lHEX 38 | } 39 | 40 | WaitForPixelColor(x, y, pc, cx := -1, cy := -1, timeout := 60) 41 | { 42 | global uid 43 | global ECPC 44 | ecc := 0 45 | i := 0 46 | tpc := 0 47 | loop 48 | { 49 | Sleep 500 50 | tpc := PixelGetColorS(x,y,3) 51 | For k,v in pc 52 | { 53 | if (tpc = v) 54 | { 55 | Sleep 500 56 | return k 57 | } 58 | } 59 | if (tpc = ECPC) 60 | { 61 | ecc += 1 62 | } 63 | if (cy != -1 and cx != -1) 64 | { 65 | ClickS(cx,cy) 66 | } 67 | Sleep 500 68 | i += 1 69 | }Until i > timeout 70 | ;MsgBox % "Expecting " . v . ", got " . tpc 71 | if ecc > 5 72 | { 73 | GuiControl,, NB, ErrorCat 74 | Pause 75 | } 76 | return 0 77 | } 78 | -------------------------------------------------------------------------------- /Functions/PixelMap.ahk: -------------------------------------------------------------------------------- 1 | ;PixelMap v1.71216 2 | 3 | 4 | PixelMap() 5 | { 6 | global 7 | local i := 1 8 | Hx := FX - 330 ;Home Button 9 | Hy := FY - 415 10 | Gx := FX + 401 11 | Gy := FY - 8 12 | Sx := FX - 185 ;Sortie Button 13 | Sy := FY - 200 14 | S2x := FX - 151 15 | S2y := FY - 248 16 | Rx := FX - 300 ;Resupply Button 17 | Ry := FY - 240 18 | SAx := FX - 255 19 | SAy := FY - 291 20 | Ex := FX + 280 ;Expedition Button 21 | Ey := FY - 240 22 | Extrax := FX + 300 ;Extra mission Button 23 | Extray := FY - 240 24 | LAbreastx := FX + 266 25 | LAbreasty := FY - 115 26 | ESx := FX + 290 27 | ESy := FY - 11 28 | 3Ex := FX + 47 29 | 4Ex := FX + 78 30 | 34Ey := FY - 344 31 | 2Rx := FX - 200 32 | 3Rx := FX - 170 33 | 4Rx := FX - 140 34 | 234Ry := FY - 340 35 | PGx[1] := FX - 240 36 | PGx[2] := FX - 180 37 | PGx[3] := FX - 125 38 | PGx[4] := FX - 70 39 | PGx[5] := FX - 10 40 | PGy := FY - 20 41 | Loop 42 | { 43 | th := FY-280+30*(i-1) 44 | Eh[i] := th 45 | Eh[i+8] := th 46 | Eh[i+16] := th 47 | Eh[i+24] := th 48 | Eh[i+32] := th 49 | i += 1 50 | }Until i = 9 51 | SPGx[1] := FX - 225 52 | SPGx[3] := FX - 71 53 | SPGx[5] := FX + 75 54 | PGy := FY - 20 55 | REx := FX - 255 56 | REy := FY - 97 57 | MAPx[1] := FX - 100 58 | MAPy[1] := FY - 251 59 | MAPx[2] := FX + 252 60 | MAPy[2] := FY - 247 61 | MAPx[4] := FX + 252 62 | MAPy[4] := FY - 100 63 | MAPx[5] := FX + 252 64 | MAPy[5] := FY - 247 65 | LAx := FX + 69 66 | LAy := FY - 275 67 | CSBx := FX - 86 68 | CSBy := FY - 221 69 | ESBx := FX + 130 70 | ESBy := FY - 221 71 | CNBx := FX - 88 72 | CNBy := FY - 216 73 | RBx := FX - 128 74 | RBy := FY - 294 75 | BBx := FX + 361 76 | BBy := FY - 169 77 | BCx := FX + 128 78 | BCy := FY - 55 79 | CCx := FX + 353 80 | CCy := FY - 324 81 | return 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Functions/Window.ahk: -------------------------------------------------------------------------------- 1 | ;Window v1.03 11/14/15 2 | 3 | CheckWindow() 4 | { 5 | global 6 | IfWinExist, ahk_id %uid% 7 | { 8 | WinActivateRestore() 9 | WinGetPos, , , TWinW, TWinH 10 | if (TWinW != WinW or TWinH != WinH) 11 | { 12 | GuiControl,, NB, Window size changed, reinitializing pixel map 13 | Sleep 1000 14 | RPixelSearch() 15 | } 16 | } 17 | else 18 | { 19 | GuiControl,, NB, Window not found, searching for window 20 | Sleep 1000 21 | SetWindow() 22 | } 23 | return 24 | } 25 | 26 | SetWindow() 27 | { 28 | global 29 | local i := 1 30 | Sleep 300 31 | Loop 32 | { 33 | uid := 0 34 | uid := WinExist(WINID) 35 | if not uid = 0 36 | { 37 | WinActivateRestore(1) 38 | WinGetPos, , , WinW, WinH 39 | GuiControl,, NB, Window found 40 | Break 41 | } 42 | else 43 | { 44 | GuiControl,, NB, Window not found. Retrying (%i%) 45 | Sleep 1000 46 | i += 1 47 | if i > 30 48 | { 49 | GuiControl,, NB, Could not find window, unpause script to try again 50 | i := 1 51 | Pause 52 | } 53 | } 54 | } 55 | RPixelSearch() 56 | } 57 | 58 | WinActivateRestore(force := 0) 59 | { 60 | global Background 61 | global uid 62 | 63 | WinGet, MMX, MinMax, ahk_id %uid% 64 | if MMX = -1 65 | { 66 | WinRestore 67 | Sleep 500 68 | } 69 | if WinActive(ahk_id %uid%) 70 | { 71 | } 72 | else if (Background = 0 or force = 1) 73 | { 74 | WinActivate 75 | Sleep 500 76 | } 77 | return 78 | } 79 | 80 | SpecificWindows() 81 | { 82 | global Background 83 | if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME,WIN_XP 84 | { 85 | if Background = 1 86 | { 87 | MsgBox This version of Windows is unsupported. Script may not function properly. 88 | Background := 0 89 | IniWrite,%Background%,config.ini,Variables,Background 90 | } 91 | } 92 | return 93 | } -------------------------------------------------------------------------------- /XYColor.ahk: -------------------------------------------------------------------------------- 1 | ;XYCOLOR v1.61001 2 | 3 | if not A_IsAdmin 4 | { 5 | Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+ 6 | ExitApp 7 | } 8 | #Persistent 9 | #SingleInstance 10 | #Include %A_ScriptDir%/Functions/Gdip_All.ahk ;Thanks to tic (Tariq Porter) for his GDI+ Library => ahkscript.org/boards/viewtopic.php?t=6517 11 | CoordMode, Pixel, Relative 12 | CoordMode, Mouse, Relative 13 | 14 | IniRead, Background, config.ini, Variables, Background, 1 15 | IniRead, Class, config.ini, Variables, Class, 0 16 | 17 | Initialize() 18 | 19 | IniRead, WINID, config.ini, Variables, WINID, KancolleViewer! 20 | 21 | #Include %A_ScriptDir%/Constants/PixelColor.ahk 22 | 23 | SpecificWindows() 24 | Gui, 1: New 25 | Gui, 1: Default 26 | Gui, Add, Text,, FX 27 | Gui, Add, Text,, FY 28 | Gui, Add, Text,, Color 29 | Gui, Add, Edit, r1 w20 vFXB ReadOnly 30 | Gui, Add, Edit, r1 w20 vFYB ReadOnly 31 | Gui, Add, Edit, r1 w20 vColorB ReadOnly 32 | Gui, Add, Edit, r1 w20 vNB ReadOnly 33 | GuiControl, Move, FXB, x40 y5 w70 34 | GuiControl, Move, FYB, x40 y30 w70 35 | GuiControl, Move, ColorB, x40 y55 w70 36 | GuiControl, Move, NB, y90 w300 37 | Gui, Show, Autosize 38 | IniWrite,1,config.ini,Do Not Modify,Busy 39 | Busy := 1 40 | SetWindow() 41 | return 42 | 43 | ~RButton Up:: 44 | { 45 | if WinExist("A") = uid 46 | { 47 | MouseGetPos, mxp, myp 48 | tx := mxp - FX 49 | ty := myp - FY 50 | if tx > 0 51 | { 52 | tx = +%tx% 53 | } 54 | if ty > 0 55 | { 56 | ty = +%ty% 57 | } 58 | GuiControl,, FXB, %tx% 59 | GuiControl,, FYB, %ty% 60 | PixelGetColor, PC, mxp, myp, RGB 61 | GuiControl,, ColorB, %PC% 62 | PixelGetColor, PC, FX, FY, RGB 63 | MsgBox % PC 64 | 65 | } 66 | return 67 | } 68 | 69 | #Include %A_ScriptDir%/Functions/Click.ahk 70 | #Include %A_ScriptDir%/Functions/PixelCheck.ahk 71 | #Include %A_ScriptDir%/Functions/Window.ahk 72 | #Include %A_ScriptDir%/Functions/PixelSearch.ahk 73 | #Include %A_ScriptDir%/Functions/PixelMap.ahk 74 | 75 | Initialize() 76 | { 77 | global 78 | return 79 | } 80 | 81 | GuiClose: 82 | { 83 | ExitApp 84 | } -------------------------------------------------------------------------------- /Functions/TimerUtils.ahk: -------------------------------------------------------------------------------- 1 | ;TimerUtils v1.51230 2 | 3 | ParseTime(ss) 4 | { 5 | global NB 6 | sl := StrLen(ss) 7 | i := 0 8 | ii := 0 9 | tt := 0 10 | mx := 1000 11 | cc := 0 12 | loop 13 | { 14 | ts := SubStr(ss,sl,1) 15 | if ts is integer 16 | { 17 | i := i + ts*10**ii 18 | ii += 1 19 | if sl = 1 20 | { 21 | tt := tt + i * mx 22 | return tt 23 | } 24 | } 25 | else if ts is alpha 26 | { 27 | if i > 0 28 | { 29 | tt := tt + i * mx 30 | } 31 | if ts = h 32 | { 33 | mx := 3600000 34 | } 35 | else if ts = m 36 | { 37 | mx := 60000 38 | } 39 | else if ts = s 40 | { 41 | mx := 1000 42 | } 43 | else 44 | { 45 | GuiControl,, NB, Invalid time input 46 | Exit 47 | } 48 | ii := 0 49 | i := 0 50 | } 51 | else if ts = : 52 | { 53 | if cc = 0 54 | { 55 | tt := tt + i * 1000 56 | mx := 60000 57 | } 58 | else if cc = 1 59 | { 60 | tt := tt + i * 60000 61 | mx := 3600000 62 | } 63 | else 64 | { 65 | GuiControl,, NB, Invalid time input 66 | Exit 67 | } 68 | if sl = 1 69 | { 70 | return tt 71 | } 72 | i := 0 73 | ii := 0 74 | cc += 1 75 | } 76 | else 77 | { 78 | GuiControl,, NB, Invalid time input 79 | Exit 80 | } 81 | sl := sl - 1 82 | } 83 | } 84 | 85 | IsExpedWithinRange( d, lc, uc) 86 | { 87 | global 88 | local i := 2 89 | local GRT 90 | loop 91 | { 92 | GRT := GetRemainingTime(TCS[i],TCL[i]) 93 | if (GRT > d and GRT < d+uc and d < GRT+lc) 94 | { 95 | d := GRT+10000 96 | i := 1 97 | } 98 | i += 1 99 | }Until i > 4 100 | return d 101 | } 102 | 103 | GetRemainingTime(n, n2, b := 0) 104 | { 105 | global Busy 106 | i := n+n2-A_TickCount 107 | if b = 1 108 | { 109 | if (i < 60000 and Busy = 0) 110 | { 111 | IniWrite,1,config.ini,Do Not Modify,Busy 112 | Busy := 1 113 | } 114 | } 115 | return i 116 | } 117 | 118 | MS2HMS(ms) 119 | { 120 | if ms < 0 121 | { 122 | return "00:00:00" 123 | } 124 | var := Floor(ms/3600000) 125 | ms := ms - var*3600000 126 | if (var<10) 127 | tString := "0" . var . ":" 128 | else 129 | tString := var . ":" 130 | 131 | var := Floor(ms/60000) 132 | ms := ms - var*60000 133 | if (var<10) 134 | tString := tString . "0" . var . ":" 135 | else 136 | tString := tString . var . ":" 137 | var := Floor(ms/1000) 138 | if (var<10) 139 | tString := tString . "0" . var 140 | else 141 | tString := tString . var 142 | return tString 143 | } -------------------------------------------------------------------------------- /Functions/PixelSearch.ahk: -------------------------------------------------------------------------------- 1 | ;PixelSearch v1.71214 2 | 3 | RPixelSearch() 4 | { 5 | global 6 | local i := 1 7 | local tx 8 | local ty 9 | local cy 10 | local PSS 11 | local RPTL 12 | local RPTR 13 | local run 14 | loop 15 | { 16 | WinActivate, ahk_id %uid% 17 | PSS := 0 18 | tx := 0 19 | ty := 0 20 | cy := WinH 21 | run := 0 22 | RPTL := 0 23 | RPTR := 0 24 | loop 25 | { 26 | run := run + 1 27 | PixelSearch, BX1, BY1, tx, ty, WinW, cy, RPN, 1, Fast RGB 28 | if (ErrorLevel = 0) 29 | { 30 | PixelGetColor, RPTL, BX1-1, BY1, RGB 31 | PixelGetColor, RPTR, BX1+1, BY1, RGB 32 | if (RPTL = RPNL and RPTR = RPNR) 33 | { 34 | PSS := 1 35 | break 36 | } 37 | if (++tx >= WinW) 38 | { 39 | tx := 0 40 | ty := ty + 1 41 | cy := ty 42 | } 43 | else 44 | { 45 | tx := BX1+1 46 | ty := BY1 47 | cy := BY1 48 | } 49 | } 50 | else if (run = 1) 51 | { 52 | break 53 | } 54 | else 55 | { 56 | tx := 0 57 | ty := ty + 1 58 | cy := WinH 59 | } 60 | 61 | } until ty >= WinH 62 | if (PSS = 0) 63 | { 64 | WinActivate, ahk_id %uid% 65 | PSS := 0 66 | tx := 0 67 | ty := 0 68 | cy := WinH 69 | RPTL := 0 70 | RPTR := 0 71 | run := 0 72 | loop 73 | { 74 | run := run + 1 75 | PixelSearch, BX1, BY1, tx, ty, WinW, cy, RPD, 1, Fast RGB 76 | if (ErrorLevel = 0) 77 | { 78 | PixelGetColor, RPTL, BX1-1, BY1, RGB 79 | PixelGetColor, RPTR, BX1+1, BY1, RGB 80 | if (RPTL = RPDL and RPTR = RPDR) 81 | { 82 | PSS := 1 83 | break 84 | } 85 | if (++tx >= WinW) 86 | { 87 | tx := 0 88 | ty := ty + 1 89 | cy := ty 90 | } 91 | else 92 | { 93 | tx := BX1+1 94 | ty := BY1 95 | cy := BY1 96 | } 97 | } 98 | else if (run = 1) 99 | { 100 | break 101 | } 102 | else 103 | { 104 | tx := 0 105 | ty := ty + 1 106 | cy := WinH 107 | } 108 | 109 | } until ty >= WinH 110 | } 111 | if PSS = 1 112 | { 113 | if not Class = 0 114 | { 115 | XDiff := BX1 - 678 116 | YDiff := BY1 - 17 117 | } 118 | FX := BX1 + 98 119 | FY := BY1 + 458 120 | PixelMap() 121 | GuiControl,, NB, Ready 122 | return 123 | } 124 | else 125 | { 126 | GuiControl,, NB, Invalid Screen, Retrying (%i%) 127 | Sleep 1000 128 | i += 1 129 | if i > 30 130 | { 131 | GuiControl,, NB, Could not find reference pixel, unpause script to try again 132 | i := 1 133 | Pause 134 | } 135 | } 136 | } 137 | } -------------------------------------------------------------------------------- /PauseUtility.ahk: -------------------------------------------------------------------------------- 1 | ;Pause Utility v1.60813 2 | 3 | if not A_IsAdmin 4 | { 5 | Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+ 6 | ExitApp 7 | } 8 | 9 | #Persistent 10 | 11 | IniRead, PauseHr, config.ini, Variables, PauseHr, -1 12 | IniRead, PauseMn, config.ini, Variables, PauseMn, -1 13 | IniRead, ResumeHr, config.ini, Variables, ResumeHr, -1 14 | IniRead, ResumeMn, config.ini, Variables, ResumeMn, -1 15 | IniRead, PCSleep, config.ini, Variables, PCSleep, 0 16 | IniRead, NotificationLevel, config.ini, Variables, NotificationLevel, 1 17 | 18 | Resume := 0 19 | tString := "" 20 | 21 | if (PauseHr = -1 or PauseHr < 0 or PauseHr > 23 or PauseMn = -1 or PauseMn < 0 or PauseMn > 59) 22 | { 23 | MsgBox PauseHr and PauseMn not set in config.ini file or invalid time input. 24 | ExitApp 25 | } 26 | else 27 | { 28 | tt := GetRemainingTime(PauseHr,PauseMn) 29 | SetTimer, TogglePause, %tt% 30 | tString := "Script will be paused at " . PauseHr . ":" . PauseMn 31 | } 32 | 33 | if not (ResumeHr = -1 or ResumeHr < 0 or ResumeHr > 23 or ResumeMn = -1 or ResumeMn < 0 or ResumeMn > 59) 34 | { 35 | Resume := 1 36 | tt := GetRemainingTime(ResumeHr,ResumeMn) 37 | SetTimer, ToggleResume, %tt% 38 | tString := tString . " and resumed at " . ResumeHr . ":" . ResumeMn 39 | } 40 | 41 | Notify("Pause Utility", tString,1) 42 | 43 | return 44 | 45 | GetRemainingTime(hr,mn) 46 | { 47 | global 48 | if (hr < A_Hour) 49 | { 50 | TRH := 24 - A_Hour + hr 51 | } 52 | else 53 | { 54 | TRH := hr - A_Hour 55 | } 56 | 57 | if (mn < A_Min) 58 | { 59 | TRM := 60 - A_Min + mn 60 | TRH := TRH - 1 61 | if (TRH < 0) 62 | { 63 | TRH := 24 + TRH 64 | } 65 | } 66 | else 67 | { 68 | TRM := mn - A_Min 69 | } 70 | 71 | TR := TRH * 3600000 + TRM * 60000 72 | return TR 73 | } 74 | 75 | TogglePause: 76 | { 77 | SetTimer, TogglePause, Off 78 | DetectHiddenWindows, On 79 | SetTitleMatchMode 2 80 | WinGet, ahkc_id, ID, AHKanColle ahk_class AutoHotkeyGUI 81 | WinGet, ahkcs_id, ID, AHKCSortie ahk_class AutoHotkeyGUI 82 | PostMessage, 0x111, 65306,,, ahk_id %ahkc_id% 83 | PostMessage, 0x111, 65306,,, ahk_id %ahkcs_id% 84 | Notify("Pause Utility", "Paused",1) 85 | if (PCSleep = 1 and Resume = 0) 86 | { 87 | DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0) 88 | } 89 | else if Resume = 1 90 | { 91 | Notify("Pause Utility", "Pause repeating in 24 hours",1) 92 | SetTimer, TogglePause, 86400000 93 | } 94 | return 95 | } 96 | 97 | ToggleResume: 98 | { 99 | SetTimer, ToggleResume, Off 100 | DetectHiddenWindows, On 101 | SetTitleMatchMode 2 102 | WinGet, ahkc_id, ID, AHKanColle ahk_class AutoHotkeyGUI 103 | WinGet, ahkcs_id, ID, AHKCSortie ahk_class AutoHotkeyGUI 104 | PostMessage, 0x111, 65306,,, ahk_id %ahkc_id% 105 | PostMessage, 0x111, 65306,,, ahk_id %ahkcs_id% 106 | SetTimer, ToggleResume, 86400000 107 | Notify("Pause Utility", "Resumed",1) 108 | return 109 | } 110 | 111 | #Include %A_ScriptDir%/Functions/Notify.ahk 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | AHKanColle (Click script for KanColle expeditions) 3 | -- 4 | 5 | by Ryuuhou 6 | 7 | README 08/03/16 8 | 9 | ``` 10 | >scripting 11 | >kuso ttk 12 | ``` 13 | 14 | ## Requirements: 15 | 16 | Running from source 17 | * AHK (http://ahkscript.org/ or https://autohotkey.com/) 18 | * Gdip_All library by tic (included) 19 | 20 | Running from releases (v1.60803 or above) 21 | * None 22 | 23 | THIS SCRIPT IS ONLY TESTED AND MAINTAINED ON WIN8.1 AND WIN10. I may be unable to help you on any other version. 24 | 25 | ## Features: 26 | 27 | * Background scripting (cannot be minimized) 28 | * Dynamic pixel checking to prevent user error 29 | * Easy to use GUI with changeable settings 30 | * Error Cat detection (script will be paused) 31 | * Can be set up to pause/resume at a certain time 32 | * All clicks have randomness to avoid click tracking 33 | * Uses Windows notifications 34 | 35 | ## How to use: AHKanColle 36 | Set which expedition each fleet will run, press ENTER to submit. 37 | Use expedition 0 to disable resending that fleet. 38 | 39 | Enter a remaining time if it is currently already on an expedition. The following syntax are allowed for the time 2 hours 2 minutes and 2 seconds. 02:02:02 | 2:2:2 | 2h2m2s 40 | 41 | If it is not on an expedition, use 0 to resupply and send after pushing the button "Send Expeditions." 42 | 43 | Use a remaining time of -1 to disable scripting for that fleet. 44 | 45 | Do not leave the fields blank. 46 | 47 | Enter a MinWait and MaxWait in MILLISECONDS. The script will wait a random amount of time between these two numbers after an expedition comes back. 48 | 49 | If you are not playing with KanColleViewer, add/create an entry in the config.ini file in the script directory. Use AutoIt3 Window Spy that is included with your AHK installation to determine the window properties. As shown below (Three valid options are show, **PICK ONE**)- 50 | 51 | ``` 52 | [Variables] 53 | WINID=艦隊これくしょん -艦これ- - オンラインゲーム - DMM.com - Mozilla Firefox 54 | WINID=ahk_class MozillaWindowClass 55 | WINID=ahk_exe firefox.exe 56 | ``` 57 | 58 | If using a browser, the name of window will usually be in the titlebar. 59 | 60 | ## How to use: Pause Utility 61 | 62 | Simple pause script that runs alongside AHKanColle. 63 | 64 | Enter in config.ini under [Variables], PauseHr=22 , and PauseMn=22 to pause at 22:22. Use 24 Hour format only. You may use PCSleep=1 to sleep the computer at that time as well. 65 | 66 | Use ResumeHr and ResumeMn to have the script resume at a specific time. Can be omitted for pause functionality only. When resume is enabled, PCSleep will be ignored and expired timers will automatically be set to pause/resume 24 hours later. 67 | 68 | ## How to use: AHKCSortie 69 | 70 | Sortie script that should be used along with AHKanColle. GUI is pretty self explanatory. Set the map you would like to script, set an interval if you would like it to automatically send again, and press start. 71 | Currently, world 1, 3 and 5, maps 1, 2 and 4, are supported though only 1-1 (sparkling), 3-2 and 5-4 are recommended. The script will check for critically damaged ships and resupply before each sortie. For sparkling, set #Nodes to 2 so the script continues to the next battle. 72 | 73 | Some recommended intervals: 74 | * 1000 for fatigue grinding 75 | * 900000 for full morale recovery (recommended for 5-4) 76 | * -1 to disable auto sending 77 | 78 | **I AM NOT RESPONSIBLE IF THIS SCRIPT BUGS AND SINKS YOUR SHIP. Use at your own risk.** 79 | 80 | ## FAQ: 81 | 82 | #### The script gets stuck at "Waiting for homescreen..." or after hiding the UI, how do I fix this? 83 | Do NOT use hardware acceleration on your browsers (KC Kai) or use "Direct/GPU" on KCV. 84 | 85 | #### The script says invalid screen even though I am sitting on the HQ screen, what is going on? 86 | No clue. For unknown reasons, the script sometimes starts unable to "see" the game window. Restart the script a few times, if this does not fix it, make sure the game is at High quality and 100% scale. 87 | 88 | #### Why does the script take focus when it supposedly works in background? 89 | Although this script was designed to work in background, certain applications may lose focus while scripting. 90 | 91 | #### Can I minimize my browser/viewer while scripting? 92 | Do NOT minimize browser/KCV, mouse clicks do not work while minimized. It can be behind other windows. 93 | 94 | #### Why did the script send the wrong expedition? 95 | If you have not unlocked all expeditions, your expeditions may be out of place and cause problems. It is up to you to change the constants within the script if you wish to use it. 96 | 97 | #### Can I play while scripting? 98 | You may play when the script is idle. Playing while the script is running may lead to bugging the script. 99 | 100 | #### Why is the script having issues clicking on my viewer? 101 | If you are able to get the class name of the game frame (using Window Spy), you can specify a class name in config.ini. 102 | For ElectronicObserver, Class=Internet Explorer_Server1 (shown below) 103 | ``` 104 | [Variables] 105 | WINID=ahk_exe ElectronicObserver.exe 106 | Class=Internet Explorer_Server1 107 | ``` 108 | Another option is to disable background clicking in the config.ini. See the bottom for a full list of config.ini settings. 109 | 110 | ##Config.ini 111 | Many of these variables are OPTIONAL and will have default values, only WINID is mandatory. See "How to use: AHKanColle" for proper WINID format. 112 | ``` 113 | [Variables] 114 | WINID=KanColleViewer! 115 | //Name of the browser window/viewer that the script should script on. 116 | Background=1 117 | //Script attempts to click without losing focus from other windows. When set to 0, clicks are no longer done in background. May fix issues with certain viewers. 118 | Class=0 119 | //When set to class name, i.e. Internet Explorer_Server1, the script will click directly on the class rather than the window. May fix issues with certain applications. This setting is ignored if Background=0 120 | NotificationLevel=1 121 | //Uses Windows notifications to alert you of expeditions returning or sortie status. Use a value of 0 to disable notifications. Use a value of 2 for more detailed notifications. 122 | DisableCriticalCheck=0 123 | //When set to 1, AHKCSortie will not check for critical damage ONLY when "Start" is pressed. Sorties triggered by the interval will ALWAYS be checked. 124 | DisableResupply=0 125 | //When set to 1, AHKCSortie will not resupply ONLY when "Start" is pressed. Sorties triggered by the interval will ALWAYS be resupplied. 126 | PauseHr=22 127 | PauseMn=22 128 | //Pauses the script at 22:22 (24 hr format ONLY). Used for PauseUtility since there is no GUI for it. Set these first, then open pause utility. 129 | PCSleep=0 130 | //When set to 1, the script will attempt to put the computer to sleep when PauseUtility pauses the scripts. 131 | iDOL=0 132 | //When set to 1, the script will always idle on HQ screen (Mainly if you want to hear your secretary's hourlies). Yes, its a reference/play on words. 133 | ``` -------------------------------------------------------------------------------- /AHKCSortie.ahk: -------------------------------------------------------------------------------- 1 | ;AHKCSortie v1.61121 2 | 3 | #Persistent 4 | #SingleInstance 5 | #Include %A_ScriptDir%/Functions/Gdip_All.ahk ;Thanks to tic (Tariq Porter) for his GDI+ Library => ahkscript.org/boards/viewtopic.php?t=6517 6 | 7 | if not A_IsAdmin 8 | { 9 | Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+ 10 | ExitApp 11 | } 12 | CoordMode, Pixel, Relative 13 | Menu, Tray, Icon, %A_ScriptDir%/Icons/favicon_ahkcsortie.ico,,1 14 | 15 | IniRead, Background, config.ini, Variables, Background, 1 16 | IniRead, Class, config.ini, Variables, Class, 0 17 | 18 | Initialize() 19 | 20 | IniRead, WINID, config.ini, Variables, WINID, KanColleViewer! 21 | 22 | MiscDelay := 1000 23 | 24 | ;PixelColor Constants 25 | 26 | #Include %A_ScriptDir%/Constants/PixelColor.ahk 27 | 28 | BC := 0 29 | BusyS := 0 30 | TR := 0 31 | DT := 0 32 | Nodes := 1 33 | 34 | IniRead, NotificationLevel, config.ini, Variables, NotificationLevel, 1 35 | IniRead, TWinX, config.ini, Variables, LastXS, 0 36 | IniRead, TWinY, config.ini, Variables, LastYS, 0 37 | SpecificWindows() 38 | IniRead, World, config.ini, Variables, World, %A_Space% 39 | IniRead, Map, config.ini, Variables, Map, %A_Space% 40 | IniRead, DisableCriticalCheck, config.ini, Variables, DisableCriticalCheck, 0 41 | IniRead, Sparkling, config.ini, Variables, Sparkling, 0 42 | IniRead, DisableResupply, config.ini, Variables, DisableResupply, 0 43 | IniRead, SortieInterval, config.ini, Variables, SortieInterval, -1 ;900000 for full morale 44 | IniRead, MinRandomWait, config.ini, Variables, MinRandomWaitS, 0 45 | IniRead, MaxRandomWait, config.ini, Variables, MaxRandomWaitS, 300000 46 | Gui, 1: New 47 | Gui, 1: Default 48 | Gui, Add, Text,, Map: 49 | Gui, Add, Text,, MinWait: 50 | Gui, Add, Text,, MaxWait: 51 | Gui, Add, Edit, r1 w20 vNB ReadOnly 52 | GuiControl, Move, NB, x10 w300 y80 53 | Gui, Add, Edit, gWorldF r2 limit3 w10 vWorldV -VScroll ym, %World% 54 | GuiControl, Move, WorldV, x37 h17 w15 55 | Gui, Add, Text, x55 ym, - 56 | Gui, Add, Edit, gMapF r2 limit3 w10 vMapV -VScroll ym, %Map% 57 | GuiControl, Move, MapV, x62 h17 w15 58 | Gui, Add, Text, ym, Interval(ms): 59 | Gui, Add, Edit, gIntervalF r2 w15 vIntervalV -VScroll ym, %SortieInterval% 60 | GuiControl, Move, IntervalV, h17 w70 61 | Gui, Add, Text, vText, #Nodes 62 | GuiControl, Move, Text, x150 y35 63 | Gui, Add, Edit, gNodeCount r2 limit3 w10 vNodeCount -VScroll ym, %Nodes% 64 | GuiControl, Move, NodeCount, x195 y33 h17 w25 65 | Gui, Add, Button, gSSBF vSSB, A 66 | GuiControl, Move, SSB, x250 w60 ym 67 | GuiControl,,SSB, Start 68 | Gui, Add, Edit, gMiW r2 w20 vmid -VScroll, %MinRandomWait% 69 | GuiControl, Move, mid, h20 x60 y30 w80 70 | Gui, Add, Edit, gMaW r2 w20 vmad -VScroll, %MaxRandomWait% 71 | GuiControl, Move, mad, h20 x60 y55 w80 72 | Menu, Main, Add, Pause, Pause2 73 | Menu, Main, Add, 0, DN 74 | Gui, Menu, Main 75 | Gui, Show, X%TWinX% Y%TWinY% Autosize, AHKCSortie 76 | SetWindow() 77 | if DisableCriticalCheck = 1 78 | { 79 | GuiControl,, NB, Ready - WARNING: CRITICAL CHECK IS OFF 80 | } 81 | return 82 | 83 | Repair() 84 | { 85 | global 86 | local ti 87 | tpc2 := PixelGetColorS(FX,FY,3) 88 | if (tpc2 != HPC) 89 | { 90 | ClickS(Hx,Hy) 91 | GuiControl,, NB, Waiting for home screen 92 | pc := [] 93 | pc := [HPC,HEPC] 94 | WaitForPixelColor(FX,FY,pc) 95 | } 96 | ClickS(REx,REy) 97 | GuiControl,, NB, Waiting for repair screen 98 | pc := [] 99 | pc := [REPC] 100 | WaitForPixelColor(FX,FY,pc) 101 | Sleep MiscDelay 102 | Loop 103 | { 104 | GuiControl,, NB, Checking HP states 105 | ClickS(RBx,RBy) 106 | Sleep MiscDelay 107 | tpc2 := PixelGetColorS(CCx,CCy,3) 108 | if (tpc2 = CCPC) 109 | { 110 | Notify("AHKCSortie", "Critical HP detected, repairing",1) 111 | GuiControl,, NB, Critical HP detected, repairing 112 | ti := BC+1 113 | Menu, Main, Rename, %BC%, %ti% 114 | BC += 1 115 | ClickS(CCx,CCy) 116 | Sleep 500 117 | ClickS(BBx,BBy) 118 | Sleep 500 119 | ClickS(ESx,ESy) 120 | Sleep 500 121 | ClickS(BCx,BCy) 122 | pc := [] 123 | pc := [REPC] 124 | WaitForPixelColor(FX,FY,pc) 125 | Sleep 9000 126 | } 127 | else 128 | { 129 | Notify("AHKCSortie", "HP check completed",2) 130 | GuiControl,, NB, HP check completed 131 | return 132 | } 133 | } 134 | } 135 | 136 | Delay: 137 | { 138 | IniRead, Busy, config.ini, Do Not Modify, Busy, 1 139 | if DT = 0 140 | { 141 | DT := 1 142 | Random, SR, MinRandomWait, MaxRandomWait 143 | QTS := A_TickCount 144 | QTL := SR 145 | SetTimer, NBUpdate, 2000 146 | tSS := MS2HMS(GetRemainingTime(QTS,QTL)) 147 | Notify("AHKCSortie", "Starting sortie in " . tSS,1) 148 | Sleep SR 149 | goto Delay 150 | } 151 | else if (Busy = 0 and BusyS = 0) 152 | { 153 | { 154 | goto Sortie 155 | } 156 | } 157 | else 158 | { 159 | if (Busy = 1 and BusyS = 0) 160 | { 161 | GuiControl,, NB, An expedition is returning, retrying every 10 seconds 162 | SetTimer, NBUpdate, Off 163 | } 164 | SetTimer, Delay, 10000 165 | } 166 | return 167 | } 168 | 169 | Sortie: 170 | { 171 | SetTimer, NBUpdate, Off 172 | SetTimer, Delay, Off 173 | BusyS := 1 174 | DT := 0 175 | TR := 0 176 | GuiControl, Hide, SSB 177 | CheckWindow() 178 | Notify("AHKCSortie", "Preparing to send sortie",1) 179 | if not (BP = 1 and DisableCriticalCheck = 1) 180 | { 181 | if not (World = 1 and Map = 1 and Sparkling = 1) 182 | { 183 | Repair() 184 | } 185 | } 186 | if not (BP = 1 and DisableResupply = 1) 187 | { 188 | Resupply(1) 189 | } 190 | tpc2 := PixelGetColorS(FX,FY,3) 191 | if (tpc2 != HPC) 192 | { 193 | ClickS(Hx,Hy) 194 | GuiControl,, NB, Waiting for home screen 195 | pc := [] 196 | pc := [HPC] 197 | WaitForPixelColor(FX,FY,pc) 198 | } 199 | ClickS(Sx,Sy) 200 | GuiControl,, NB, Waiting for sortie screen 201 | pc := [] 202 | pc := [SPC] 203 | WaitForPixelColor(FX,FY,pc) 204 | ClickS(S2x,S2y) 205 | GuiControl,, NB, Waiting for sortie selection screen 206 | pc := [] 207 | pc := [S2PC] 208 | WaitForPixelColor(FX,FY,pc) 209 | tf := SPGx[World] 210 | ClickS(tf,PGy) 211 | GuiControl,, NB, Starting sortie 212 | Sleep MiscDelay 213 | if(Map > 4) 214 | { 215 | ClickS(Extrax,Extray) 216 | } 217 | tfx := MAPx[Map] 218 | tfy := MAPy[Map] 219 | ClickS(tfx,tfy) 220 | Sleep MiscDelay 221 | ClickS(ESx,ESy) 222 | Sleep MiscDelay 223 | ClickS(ESx,ESy) 224 | Notify("AHKCSortie", "Sortie started",1) 225 | if SortieInterval != -1 226 | { 227 | SetTimer, Delay, %SortieInterval% 228 | TR := 1 229 | TCS := A_TickCount 230 | } 231 | NC := 1 232 | Loop 233 | { 234 | GuiControl,, NB, Waiting for compass/formation 235 | pc := [] 236 | pc := [CPC,FPC,IBPC] 237 | tpc := WaitForPixelColor(LAx,LAy,pc,,,30) 238 | Sleep MiscDelay 239 | if tpc = 1 240 | { 241 | ClickS(ESx,ESy) 242 | GuiControl,, NB, Waiting for formation 243 | pc := [] 244 | pc := [FPC,IBPC] 245 | tpc2 := WaitForPixelColor(LAx,LAy,pc) 246 | if tpc2 = 1 247 | { 248 | Sleep MiscDelay 249 | if(World = 1 and Map = 5) 250 | { 251 | ClickS(LAbreastx,LAbreasty) 252 | } 253 | else 254 | { 255 | ClickS(LAx,LAy) 256 | } 257 | } 258 | } 259 | else if tpc = 2 260 | { 261 | if(World = 1 and Map = 5) 262 | { 263 | ClickS(LAbreastx,LAbreasty) 264 | } 265 | else 266 | { 267 | ClickS(LAx,LAy) 268 | } 269 | } 270 | GuiControl,, NB, Waiting for results 271 | pc := [] 272 | pc := [SRPC,NBPC] 273 | WaitForPixelColor(FX,FY,pc,,,250) 274 | Sleep 5000 275 | tpc := WaitForPixelColor(FX,FY,pc) 276 | if tpc = 2 277 | { 278 | GuiControl,, NB, Cancelling night battle 279 | Sleep 3000 280 | ClickS(CNBx,CNBy) 281 | } 282 | GuiControl,, NB, Waiting... 283 | pc := [] 284 | pc := [HPC,HEPC,CSPC] 285 | tpc := WaitForPixelColor(FX,FY,pc,FX,FY) 286 | if tpc = 1 or tpc = 2 287 | { 288 | Break 289 | } 290 | else if tpc = 3 291 | { 292 | GuiControl,, NB, Continue screen 293 | Sleep 2000 294 | if (NC = Nodes) 295 | { 296 | GuiControl,, NB, Ending sortie 297 | ClickS(ESBx,ESBy) 298 | } 299 | else 300 | { 301 | Notify("AHKCSortie", "Proceeding to next node",2) 302 | GuiControl,, NB, Continuing Sortie 303 | ClickS(CSBx,CSBy) 304 | } 305 | } 306 | NC += 1 307 | }Until NC > Nodes 308 | GuiControl,, NB, Waiting for home screen 309 | pc := [] 310 | pc := [HPC,HEPC] 311 | WaitForPixelColor(FX,FY,pc,ESBx,ESBy) 312 | Notify("AHKCSortie", "Sortie completed",1) 313 | GuiControl,, NB, Idle 314 | BusyS := 0 315 | GuiControl, Show, SSB 316 | if SortieInterval != -1 317 | { 318 | BP := 0 319 | SetTimer, NBUpdate, 2000 320 | } 321 | return 322 | } 323 | 324 | Resupply(r) 325 | { 326 | global 327 | GuiControl,, NB, Resupplying... 328 | tpc := 0 329 | tpc := PixelGetColorS(FX,FY,3) 330 | if (tpc = HPC) 331 | { 332 | ClickS(Rx,Ry) 333 | } 334 | else if (tpc != RPC) 335 | { 336 | ClickS(Hx,Hy) 337 | pc := [] 338 | pc := [HPC] 339 | WaitForPixelColor(FX,FY,pc) 340 | ClickS(Rx,Ry) 341 | } 342 | pc := [] 343 | pc := [RPC] 344 | WaitForPixelColor(FX,FY,pc) 345 | GuiControl,, NB, Resupplying fleet %r% 346 | Sleep MiscDelay 347 | rti := 0 348 | rti2 := 5 349 | if (World = 1 and Map = 1 and Sparkling = 1) 350 | { 351 | rti2 := 0 352 | } 353 | Loop 354 | { 355 | ClickS(SAx,SAy+50*rti) 356 | rti := rti+1 357 | Sleep 1 358 | }Until (rti > rti2) 359 | ClickS(ESx,ESy) 360 | pc := [] 361 | pc := [RPC] 362 | WaitForPixelColor(FX,FY,pc) 363 | return 364 | } 365 | 366 | WorldF: 367 | { 368 | Gui, submit,nohide 369 | if WorldV contains `n 370 | { 371 | StringReplace, WorldV, WorldV, `n,,All 372 | GuiControl,, WorldV, %WorldV% 373 | Send, {end} 374 | if (WorldV=1 or WorldV=3 or WorldV=5) 375 | { 376 | World := WorldV 377 | GuiControl,, NB, World set 378 | IniWrite,%World%,config.ini,Variables,World 379 | } 380 | else 381 | { 382 | GuiControl,, NB, Unsupported world 383 | } 384 | } 385 | return 386 | } 387 | 388 | MapF: 389 | { 390 | Gui, submit,nohide 391 | if MapV contains `n 392 | { 393 | StringReplace, MapV, MapV, `n,,All 394 | GuiControl,, MapV, %MapV% 395 | Send, {end} 396 | if (MapV=1 or MapV=2 or MapV=4 or MapV=5) 397 | { 398 | Map := MapV 399 | GuiControl,, NB, Map # set 400 | IniWrite,%Map%,config.ini,Variables,Map 401 | } 402 | else 403 | { 404 | GuiControl,, NB, Unsupported map # 405 | } 406 | } 407 | return 408 | } 409 | 410 | NodeCount: 411 | { 412 | Gui, submit,nohide 413 | if NodeCount contains `n 414 | { 415 | StringReplace, NodeCount, NodeCount, `n,,All 416 | GuiControl,, NodeCount, %NodeCount% 417 | Send, {end} 418 | if (NodeCount > 0 and NodeCount < 4) 419 | { 420 | Nodes := NodeCount 421 | if Nodes > 1 422 | { 423 | MsgBox WARNING: Script will continue past first node and will NOT check for critical damage. You risk sinking any girl that is not flagship. 424 | } 425 | GuiControl,, NB, # of nodes set 426 | } 427 | else 428 | { 429 | GuiControl,, NB, Invalid entry, must be within 1 and 3 430 | } 431 | } 432 | return 433 | } 434 | 435 | IntervalF: 436 | { 437 | Gui, submit,nohide 438 | if IntervalV contains `n 439 | { 440 | StringReplace, IntervalV, IntervalV, `n,,All 441 | GuiControl,, IntervalV, %IntervalV% 442 | Send, {end} 443 | if IntervalV is integer 444 | { 445 | SortieInterval := IntervalV 446 | if (SortieInterval < 1000) 447 | { 448 | SortieInterval := -1 449 | GuiControl,, NB, Interval disabled 450 | SetTimer, Delay, Off 451 | SetTimer, NBUpdate, Off 452 | TR := 0 453 | } 454 | else 455 | { 456 | if TR = 1 457 | { 458 | tt := SortieInterval - A_TickCount + TCS 459 | if tt < 0 460 | { 461 | tt := 1000 462 | } 463 | SetTimer, Delay, %tt% 464 | } 465 | GuiControl,, NB, Interval set 466 | } 467 | IniWrite,%SortieInterval%,config.ini,Variables,SortieInterval 468 | 469 | } 470 | else 471 | { 472 | GuiControl,, NB, Invalid interval 473 | } 474 | } 475 | return 476 | } 477 | 478 | MiW: 479 | { 480 | Gui, submit,nohide 481 | if mid contains `n 482 | { 483 | StringReplace, mid, mid, `n,,All 484 | GuiControl,, mid, %mid% 485 | Send, {end} 486 | MinRandomWait := mid 487 | IniWrite,%mid%,config.ini,Variables,MinRandomWaitS 488 | GuiControl,, NB, Changed minimum random delay 489 | } 490 | return 491 | } 492 | 493 | MaW: 494 | { 495 | Gui, submit,nohide 496 | if mad contains `n 497 | { 498 | StringReplace, mad, mad, `n,,All 499 | GuiControl,, mad, %mad% 500 | Send, {end} 501 | MaxRandomWait := mad 502 | IniWrite,%mad%,config.ini,Variables,MaxRandomWaitS 503 | GuiControl,, NB, Changed max random delay 504 | } 505 | return 506 | } 507 | 508 | SSBF: 509 | { 510 | if (Map < 1 or World < 1) 511 | { 512 | MsgBox Map or world invalid. Press enter after each field to submit. 513 | return 514 | } 515 | GuiControl, Hide, SSB 516 | BP := 1 517 | DT := 1 518 | goto Delay 519 | return 520 | } 521 | 522 | NBUpdate: 523 | { 524 | if DT = 0 525 | { 526 | ts := Round((TCS + SortieInterval - A_TickCount)/60000,2) 527 | GuiControl,, NB, Idle - Restarting in %ts% minutes 528 | } 529 | else 530 | { 531 | tSS := MS2HMS(GetRemainingTime(QTS,QTL)) 532 | GuiControl,, NB, Delay - %tSS% 533 | } 534 | return 535 | } 536 | 537 | DN: 538 | { 539 | return 540 | } 541 | 542 | #Include %A_ScriptDir%/Functions/Click.ahk 543 | #Include %A_ScriptDir%/Functions/TimerUtils.ahk 544 | #Include %A_ScriptDir%/Functions/PixelCheck.ahk 545 | #Include %A_ScriptDir%/Functions/Pause.ahk 546 | #Include %A_ScriptDir%/Functions/Window.ahk 547 | #Include %A_ScriptDir%/Functions/PixelSearch.ahk 548 | #Include %A_ScriptDir%/Functions/PixelMap.ahk 549 | #Include %A_ScriptDir%/Functions/Notify.ahk 550 | 551 | 552 | Initialize() 553 | { 554 | global 555 | SPGx := Array(item) 556 | MAPx := Array(item) 557 | MAPy := Array(item) 558 | pc := Array(item) 559 | Q := Array() 560 | NC := 0 561 | ClickDelay := 500 562 | coffset := 7 563 | } 564 | 565 | GuiClose: 566 | { 567 | WinGetPos,TWinX,TWinY 568 | IniWrite,%TWinX%,config.ini,Variables,LastXS 569 | IniWrite,%TWinY%,config.ini,Variables,LastYS 570 | ExitApp 571 | } -------------------------------------------------------------------------------- /AHKanColle.ahk: -------------------------------------------------------------------------------- 1 | ;AHKanColle v1.71216 2 | 3 | 4 | if not A_IsAdmin 5 | { 6 | Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+ 7 | ExitApp 8 | } 9 | #Persistent 10 | #SingleInstance 11 | #Include %A_ScriptDir%/Functions/Gdip_All.ahk ;Thanks to tic (Tariq Porter) for his GDI+ Library => ahkscript.org/boards/viewtopic.php?t=6517 12 | CoordMode, Pixel, Relative 13 | Menu, Tray, Icon, %A_ScriptDir%/Icons/favicon_ahkancolle.ico,,1 14 | 15 | IniRead, Background, config.ini, Variables, Background, 1 16 | IniRead, Class, config.ini, Variables, Class, 0 17 | 18 | Initialize() 19 | 20 | IniRead, WINID, config.ini, Variables, WINID, KanColleViewer! 21 | 22 | SetExped[2] := 0 23 | SetExped[3] := 0 24 | SetExped[4] := 0 25 | 26 | ;Variable Delays 27 | 28 | IniRead, MinRandomWait, config.ini, Variables, MinRandomWait, 5000 ;Minimum time to wait after exped returns. 29 | IniRead, MaxRandomWait, config.ini, Variables, MaxRandomWait, 300000 ;Maximum time to wait after exped returns. 30 | 31 | ;Constant Delays (Leave alone) 32 | 33 | ClockDelay := -59000 ;Set your clock delay (normally around -59000 to be safe) 34 | SendDelay := 3500 ;Used for expedition sending animation 35 | MiscDelay := 1000 ;Delay for actions with little to no animation time 36 | 37 | ;PixelColor Contants 38 | 39 | #Include %A_ScriptDir%/Constants/PixelColor.ahk 40 | 41 | RTI := 2000 ;Refresh interval for GUI 42 | SetTimer, Refresh, %RTI% 43 | 44 | IniRead, iDOL, config.ini, Variables, iDOL, 0 45 | if Background = 0 46 | { 47 | StayAwake() 48 | } 49 | SpecificWindows() 50 | IniRead, NotificationLevel, config.ini, Variables, NotificationLevel, 1 51 | Notify("AHKanColle", "Notifications enabled, disable in config with NotificationLevel=0",1) 52 | IniRead, TWinX, config.ini, Variables, LastX, 0 53 | IniRead, TWinY, config.ini, Variables, LastY, 0 54 | IniRead, World, config.ini, Variables, World, 0 55 | IniRead, Map, config.ini, Variables, Map, 0 56 | IniRead, SortieInterval, config.ini, Variables, SortieInterval, 300000 57 | Gui, 1: New 58 | Gui, 1: Default 59 | Gui, Add, Text,, Exped 2: 60 | Gui, Add, Text,, Exped 3: 61 | Gui, Add, Text,, Exped 4: 62 | Gui, Add, Text,, MinWait: 63 | Gui, Add, Text,, MaxWait: 64 | Gui, Add, Edit, r1 w20 vNB ReadOnly 65 | GuiControl, Move, NB, w300 y139 66 | IniRead, tSetExped, config.ini, Variables, SetExped2, %A_Space% 67 | Gui, Add, Edit, gESE2 r2 limit4 w20 vSE2 -VScroll ym, %tSetExped% 68 | GuiControl, Move, SE2, h20 69 | IniRead, tSetExped, config.ini, Variables, SetExped3, %A_Space% 70 | Gui, Add, Edit, gESE3 r2 limit4 w20 vSE3 -VScroll, %tSetExped% 71 | GuiControl, Move, SE3, h20 y32 72 | IniRead, tSetExped, config.ini, Variables, SetExped4, %A_Space% 73 | Gui, Add, Edit, gESE4 r2 limit4 w20 vSE4 -VScroll, %tSetExped% 74 | GuiControl, Move, SE4, h20 y58 75 | Gui, Add, Edit, gMiW r2 w20 vmid -VScroll, %MinRandomWait% 76 | GuiControl, Move, mid, h20 y85 w80 77 | Gui, Add, Edit, gMaW r2 w20 vmad -VScroll, %MaxRandomWait% 78 | GuiControl, Move, mad, h20 y112 w80 79 | Gui, Add, Text,ym x+20,Remaining Time: 80 | Gui, Add, Text,,Remaining Time: 81 | Gui, Add, Text,,Remaining Time: 82 | Gui, Add, Edit, ReadOnly gERT2 r2 w63 vTRT2 -VScroll -HScroll ym 83 | GuiControl, Move, TRT2, h20 84 | Gui, Add, Edit, ReadOnly gERT3 r2 w63 vTRT3 -VScroll -HScroll 85 | GuiControl, Move, TRT3, h20 y32 86 | Gui, Add, Edit, ReadOnly gERT4 r2 w63 vTRT4 -VScroll -HScroll 87 | GuiControl, Move, TRT4, h20 y58 88 | Gui, Add, Text, vT2 ym, 00:00:00 89 | Gui, Add, Text, vT3, 00:00:00 90 | Gui, Add, Text, vT4, 00:00:00 91 | Gui, Add, Button, gSEButton vSEB, A 92 | GuiControl, Move, SEB, x210 y110 w95 93 | GuiControl,,SEB, Send Expeditions 94 | GuiControl, Hide, SEB 95 | Menu, Main, Add, Pause, Pause2 96 | Gui, Menu, Main 97 | Gui, Show, X%TWinX% Y%TWinY% Autosize, AHKanColle 98 | SetWindow() 99 | GuiControl, Focus, SE2 100 | Gui, Show 101 | IniWrite,1,config.ini,Do Not Modify,Busy 102 | Busy := 1 103 | return 104 | 105 | 2Return: 106 | { 107 | SetTimer, 2Return, Off 108 | IniWrite,1,config.ini,Do Not Modify,Busy 109 | Busy := 1 110 | CDT[2] := 0 111 | GuiControl,, T2, 00:00:00 112 | QueueInsert(2) 113 | if Q.MaxIndex() = 1 114 | { 115 | Random, SR, MinRandomWait, MaxRandomWait 116 | SR := IsExpedWithinRange(SR, 10000, 60000) 117 | SetTimer, QueueTimer, %SR% 118 | QTS := A_TickCount 119 | QTL := SR 120 | CDT[1] := 1 121 | } 122 | else 123 | { 124 | RF := 1 125 | } 126 | tSS := MS2HMS(GetRemainingTime(QTS,QTL,1)) 127 | Notify("AHKanColle", "Expedition 2 returning in " . tSS,1) 128 | return 129 | } 130 | 131 | 3Return: 132 | { 133 | SetTimer, 3Return, Off 134 | IniWrite,1,config.ini,Do Not Modify,Busy 135 | Busy := 1 136 | CDT[3] := 0 137 | GuiControl,, T3, 00:00:00 138 | QueueInsert(3) 139 | if Q.MaxIndex() = 1 140 | { 141 | Random, SR, MinRandomWait, MaxRandomWait 142 | SR := IsExpedWithinRange(SR, 10000, 60000) 143 | SetTimer, QueueTimer, %SR% 144 | QTS := A_TickCount 145 | QTL := SR 146 | CDT[1] := 1 147 | } 148 | else 149 | { 150 | RF := 1 151 | } 152 | tSS := MS2HMS(GetRemainingTime(QTS,QTL,1)) 153 | Notify("AHKanColle", "Expedition 3 returning in " . tSS,1) 154 | return 155 | } 156 | 157 | 4Return: 158 | { 159 | SetTimer, 4Return, Off 160 | IniWrite,1,config.ini,Do Not Modify,Busy 161 | Busy := 1 162 | CDT[4] := 0 163 | GuiControl,, T4, 00:00:00 164 | QueueInsert(4) 165 | if Q.MaxIndex() = 1 166 | { 167 | Random, SR, MinRandomWait, MaxRandomWait 168 | SR := IsExpedWithinRange(SR, 10000, 60000) 169 | SetTimer, QueueTimer, %SR% 170 | QTS := A_TickCount 171 | QTL := SR 172 | CDT[1] := 1 173 | } 174 | else 175 | { 176 | RF := 1 177 | } 178 | tSS := MS2HMS(GetRemainingTime(QTS,QTL,1)) 179 | Notify("AHKanColle", "Expedition 3 returning in " . tSS,1) 180 | return 181 | } 182 | 183 | QueueTimer: 184 | { 185 | SetTimer, QueueTimer, Off 186 | goto Queue 187 | return 188 | } 189 | 190 | Queue: 191 | { 192 | IniWrite,1,config.ini,Do Not Modify,Busy 193 | Busy := 1 194 | GuiControl, Hide, SEB 195 | CDT[1] := 0 196 | if RF = 1 197 | { 198 | RF := 0 199 | } 200 | CheckWindow() 201 | GuiControl,, NB, Waiting for home screen... 202 | tpc := 0 203 | tpc := PixelGetColorS(Gx,Gy,3) 204 | if (tpc = HPC) 205 | { 206 | GuiControl,, NB, Detected home screen 207 | ClickS(Rx,Ry) 208 | pc := [] 209 | pc := [RPC] 210 | WaitForPixelColor(Gx,Gy,pc) 211 | } 212 | if (tpc != HEPC) 213 | { 214 | ClickS(Hx,Hy) 215 | } 216 | pc := [] 217 | pc := [HPC,HEPC] 218 | tpc := WaitForPixelColor(Gx,Gy,pc,,,900) 219 | if tpc = 2 220 | { 221 | GuiControl,, NB, Detected expeditions returning, waiting for animations 222 | pc := [] 223 | pc := [HPC] 224 | WaitForPixelColor(Gx,Gy,pc,ESx,ESy,120) 225 | } 226 | else if tpc = 0 227 | { 228 | if Q.MaxIndex() > 0 229 | { 230 | goto Queue 231 | return 232 | } 233 | } 234 | qi := 1 235 | Loop 236 | { 237 | Resupply(Q[qi]) 238 | qi += 1 239 | }Until qi > Q.MaxIndex() 240 | if RF = 1 241 | { 242 | RF := 0 243 | goto Queue 244 | return 245 | } 246 | Loop 247 | { 248 | SendExp(Q[1]) 249 | RemovedValue := Q.Remove(1) 250 | if RF = 1 251 | { 252 | RF := 0 253 | goto Queue 254 | return 255 | } 256 | }Until Q.MaxIndex() = "" 257 | Notify("AHKanColle", "Expedition(s) have been sent",1) 258 | GuiControl,, NB, Idle 259 | IniWrite,0,config.ini,Do Not Modify,Busy 260 | Busy := 0 261 | if (iDOL = 1) 262 | { 263 | ClickS(Hx,Hy) 264 | GuiControl,, NB, iDOL 265 | } 266 | return 267 | } 268 | 269 | Resupply(r) 270 | { 271 | global 272 | GuiControl,, NB, Resupplying... 273 | tpc := 0 274 | tpc := PixelGetColorS(Gx,Gy,3) 275 | if (tpc = HPC) 276 | { 277 | ClickS(Rx,Ry) 278 | } 279 | else if (tpc != RPC) 280 | { 281 | ClickS(Hx,Hy) 282 | pc := [] 283 | pc := [HPC] 284 | WaitForPixelColor(Gx,Gy,pc) 285 | ClickS(Rx,Ry) 286 | } 287 | pc := [] 288 | pc := [RPC] 289 | WaitForPixelColor(Gx,Gy,pc) 290 | GuiControl,, NB, Resupplying expedition %r% 291 | if r = 2 292 | { 293 | pc := [] 294 | pc := [EX2PC] 295 | WaitForPixelColor(2Rx,234Ry,pc,2Rx,234Ry) 296 | } 297 | else if r = 3 298 | { 299 | ClickS(3Rx,234Ry) 300 | } 301 | else if r = 4 302 | { 303 | ClickS(4Rx,234Ry) 304 | } 305 | Sleep MiscDelay 306 | rti := 0 307 | Loop 308 | { 309 | ClickS(SAx,SAy+50*rti) 310 | rti := rti+1 311 | Sleep 1 312 | }Until rti > 5 313 | ClickS(ESx,ESy) 314 | pc := [] 315 | pc := [RPC] 316 | WaitForPixelColor(Gx,Gy,pc) 317 | } 318 | 319 | SendExp(n) 320 | { 321 | global 322 | if SetExped[n] != 0 323 | { 324 | GuiControl,, NB, Sending... 325 | td := SetExped[n] 326 | te := Eh[td] 327 | tpc := 0 328 | tpc := PixelGetColorS(Gx,Gy,3) 329 | if (tpc != EPC and tpc != ESUPC and tpc != ESHPC) 330 | { 331 | if (tpc != HPC) 332 | { 333 | ClickS(Hx,Hy) 334 | pc := [] 335 | pc := [HPC] 336 | WaitForPixelColor(Gx,Gy,pc) 337 | } 338 | ClickS(Sx,Sy) 339 | pc := [] 340 | pc := [SPC] 341 | WaitForPixelColor(Gx,Gy,pc) 342 | ClickS(Ex,Ey) 343 | pc := [] 344 | pc := [EPC] 345 | WaitForPixelColor(Gx,Gy,pc) 346 | } 347 | GuiControl,, NB, Sending expedition %n% 348 | if td > 32 349 | { 350 | tf := PGx[5] 351 | ClickS(tf,PGy) 352 | } 353 | else if td > 24 354 | { 355 | tf := PGx[4] 356 | ClickS(tf,PGy) 357 | } 358 | else if td > 16 359 | { 360 | tf := PGx[3] 361 | ClickS(tf,PGy) 362 | } 363 | else if td > 8 364 | { 365 | tf := PGx[2] 366 | ClickS(tf,PGy) 367 | } 368 | else 369 | { 370 | tf := PGx[1] 371 | ClickS(tf,PGy) 372 | } 373 | Sleep MiscDelay 374 | ClickS(FX,te) 375 | Sleep MiscDelay 376 | tpc := PixelGetColorS(Gx,Gy,2) 377 | if (tpc != ESUPC and tpc != ESHPC) 378 | { 379 | ClickS(ESx,ESy) 380 | Sleep MiscDelay 381 | if n = 3 382 | ClickS(3Ex,34Ey) 383 | else if n = 4 384 | ClickS(4Ex,34Ey) 385 | Sleep MiscDelay 386 | ClickS(ESx,ESy) 387 | } 388 | else 389 | { 390 | GuiControl,, NB, Error: Expedition in progress 391 | } 392 | pc := [] 393 | pc := [ESUPC,ESHPC] 394 | WaitForPixelColor(Gx,Gy,pc) 395 | if n = 2 396 | { 397 | ta := (ET[SetExped[2]]+ClockDelay)*-1 398 | TCS[2] := A_TickCount 399 | TCL[2] := -ta 400 | SetTimer, 2Return, %ta% 401 | CDT[2] := 1 402 | } 403 | else if n = 3 404 | { 405 | ta := (ET[SetExped[3]]+ClockDelay)*-1 406 | TCS[3] := A_TickCount 407 | TCL[3] := -ta 408 | SetTimer, 3Return, %ta% 409 | CDT[3] := 1 410 | } 411 | else if n = 4 412 | { 413 | ta := (ET[SetExped[4]]+ClockDelay)*-1 414 | TCS[4] := A_TickCount 415 | TCL[4] := -ta 416 | SetTimer, 4Return, %ta% 417 | CDT[4] := 1 418 | } 419 | Sleep SendDelay 420 | } 421 | } 422 | 423 | MiW: 424 | { 425 | Gui, submit,nohide 426 | if mid contains `n 427 | { 428 | StringReplace, mid, mid, `n,,All 429 | GuiControl,, mid, %mid% 430 | Send, {end} 431 | MinRandomWait := mid 432 | IniWrite,%mid%,config.ini,Variables,MinRandomWait 433 | GuiControl,, NB, Changed minimum random delay 434 | } 435 | return 436 | } 437 | 438 | MaW: 439 | { 440 | Gui, submit,nohide 441 | if mad contains `n 442 | { 443 | StringReplace, mad, mad, `n,,All 444 | GuiControl,, mad, %mad% 445 | Send, {end} 446 | MaxRandomWait := mad 447 | IniWrite,%mad%,config.ini,Variables,MaxRandomWait 448 | GuiControl,, NB, Changed max random delay 449 | } 450 | return 451 | } 452 | 453 | ESE2: 454 | { 455 | Gui, submit,nohide 456 | if SE2 contains `n 457 | { 458 | StringReplace, SE2, SE2, `n,,All 459 | GuiControl,, SE2, %SE2% 460 | Send, {end} 461 | SetExped[2] := SE2 462 | if SetExped[2] > -1 and SetExped[2] < 40 then 463 | { 464 | if SetExped[2] = 0 465 | { 466 | GuiControl,, NB, Expedition 2 will not be resent 467 | }else{ 468 | GuiControl,, NB, Expedition 2 set 469 | } 470 | tSetExped := SetExped[2] 471 | IniWrite,%tSetExped%,config.ini,Variables,SetExped2 472 | GuiControl, % "-Readonly", TRT2 473 | GuiControl, Focus, TRT2 474 | } 475 | else 476 | { 477 | GuiControl,, NB, Invalid expedition for fleet 2 478 | } 479 | } 480 | return 481 | } 482 | 483 | ESE3: 484 | { 485 | Gui, submit,nohide 486 | if SE3 contains `n 487 | { 488 | StringReplace, SE3, SE3, `n,,All 489 | GuiControl,, SE3, %SE3% 490 | Send, {end} 491 | SetExped[3] := SE3 492 | if SetExped[3] > -1 and SetExped[3] < 40 then 493 | { 494 | if SetExped[3] = 0 495 | { 496 | GuiControl,, NB, Expedition 3 will not be resent 497 | }else{ 498 | GuiControl,, NB, Expedition 3 set 499 | } 500 | tSetExped := SetExped[3] 501 | IniWrite,%tSetExped%,config.ini,Variables,SetExped3 502 | GuiControl, % "-Readonly", TRT3 503 | GuiControl, Focus, TRT3 504 | } 505 | else 506 | { 507 | GuiControl,, NB, Invalid expedition for fleet 3 508 | } 509 | } 510 | return 511 | } 512 | 513 | ESE4: 514 | { 515 | Gui, submit,nohide 516 | if SE4 contains `n 517 | { 518 | StringReplace, SE4, SE4, `n,,All 519 | GuiControl,, SE4, %SE4% 520 | Send, {end} 521 | SetExped[4] := SE4 522 | if SetExped[4] > -1 and SetExped[4] < 40 then 523 | { 524 | if SetExped[4] = 0 525 | { 526 | GuiControl,, NB, Expedition 4 will not be resent 527 | }else{ 528 | GuiControl,, NB, Expedition 4 set 529 | } 530 | tSetExped := SetExped[4] 531 | IniWrite,%tSetExped%,config.ini,Variables,SetExped4 532 | GuiControl, % "-Readonly", TRT4 533 | GuiControl, Focus, TRT4 534 | } 535 | else 536 | { 537 | GuiControl,, NB, Invalid expedition for fleet 4 538 | } 539 | } 540 | return 541 | } 542 | 543 | ERT2: 544 | { 545 | Gui, Submit, NoHide 546 | if TRT2 contains `n 547 | { 548 | StringReplace, TRT2, TRT2, `n,,All 549 | GuiControl,, TRT2, %TRT2% 550 | Send, {end} 551 | RT2 := TRT2 552 | if (RT2 != "") 553 | { 554 | QueueRemove(2) 555 | if TRT2 = 0 556 | { 557 | QueueInsert(2,1) 558 | GuiControl,, NB, Expedition 2 is ready to be refueled and sent 559 | GuiControl, % "+ReadOnly", TRT2 560 | GuiControl, Focus, SE3 561 | } 562 | else if (RT2 != -1) 563 | { 564 | ta := ParseTime(RT2) 565 | if (ta < ClockDelay*-1) 566 | { 567 | ta := ClockDelay*-1+1000 568 | } 569 | ta := (ta+ClockDelay)*-1 570 | TCS[2] := A_TickCount 571 | TCL[2] := -ta 572 | SetTimer, 2Return, %ta% 573 | GuiControl,, NB, Remaining time for fleet 2 set 574 | GuiControl, % "+ReadOnly", TRT2 575 | GuiControl, Focus, SE3 576 | CDT[2] := 1 577 | } 578 | else { 579 | SetTimer, 2Return, Off 580 | GuiControl,, NB, Expedition 2 disabled 581 | GuiControl,, T2, 00:00:00 582 | CDT[2] := 0 583 | GuiControl, % "+ReadOnly", TRT2 584 | GuiControl, Focus, SE3 585 | } 586 | S[2] := 1 587 | if (S[2] = 1 and S[3] = 1 and S[4] = 1 and Q.MaxIndex() < 1) 588 | { 589 | IniWrite,0,config.ini,Do Not Modify,Busy 590 | Busy := 0 591 | } 592 | } 593 | } 594 | return 595 | } 596 | 597 | ERT3: 598 | { 599 | Gui, Submit, NoHide 600 | if TRT3 contains `n 601 | { 602 | StringReplace, TRT3, TRT3, `n,,All 603 | GuiControl,, TRT3, %TRT3% 604 | Send, {end} 605 | RT3 := TRT3 606 | if (RT3 != "") 607 | { 608 | QueueRemove(3) 609 | if RT3 = 0 610 | { 611 | QueueInsert(3,1) 612 | GuiControl,, NB, Expedition 3 is ready to be refueled and sent 613 | GuiControl, % "+Readonly", TRT3 614 | GuiControl, Focus, SE4 615 | } 616 | else if (RT3 != -1) 617 | { 618 | ta := ParseTime(RT3) 619 | if (ta < ClockDelay*-1) 620 | { 621 | ta := ClockDelay*-1+1000 622 | } 623 | ta := (ta+ClockDelay)*-1 624 | TCS[3] := A_TickCount 625 | TCL[3] := -ta 626 | SetTimer, 3Return, %ta% 627 | GuiControl,, NB, Remaining time for fleet 3 set 628 | GuiControl, % "+Readonly", TRT3 629 | GuiControl, Focus, SE4 630 | CDT[3] := 1 631 | } 632 | else 633 | { 634 | SetTimer, 3Return, Off 635 | GuiControl,, NB, Expedition 3 disabled 636 | GuiControl,, T3, 00:00:00 637 | CDT[3] := 0 638 | GuiControl, % "+Readonly", TRT3 639 | GuiControl, Focus, SE4 640 | } 641 | S[3] := 1 642 | if (S[2] = 1 and S[3] = 1 and S[4] = 1 and Q.MaxIndex() < 1) 643 | { 644 | IniWrite,0,config.ini,Do Not Modify,Busy 645 | Busy := 0 646 | } 647 | } 648 | } 649 | return 650 | } 651 | 652 | ERT4: 653 | { 654 | Gui, Submit, NoHide 655 | if TRT4 contains `n 656 | { 657 | StringReplace, TRT4, TRT4, `n,,All 658 | GuiControl,, TRT4, %TRT4% 659 | Send, {end} 660 | RT4 := TRT4 661 | if (RT4 != "") 662 | { 663 | QueueRemove(4) 664 | if RT4 = 0 665 | { 666 | QueueInsert(4,1) 667 | GuiControl,, NB, Expedition 4 is ready to be refueled and sent 668 | GuiControl, % "+Readonly", TRT4 669 | } 670 | else if (RT4 != -1) 671 | { 672 | ta := ParseTime(RT4) 673 | if (ta < ClockDelay*-1) 674 | { 675 | ta := ClockDelay*-1+1000 676 | } 677 | ta := (ta+ClockDelay)*-1 678 | TCS[4] := A_TickCount 679 | TCL[4] := -ta 680 | SetTimer, 4Return, %ta% 681 | GuiControl,, NB, Remaining time for fleet 4 set 682 | GuiControl, % "+Readonly", TRT4 683 | CDT[4] := 1 684 | } 685 | else 686 | { 687 | SetTimer, 4Return, Off 688 | GuiControl,, NB, Expedition 4 disabled 689 | GuiControl,, T4, 00:00:00 690 | CDT[4] := 0 691 | GuiControl, % "+Readonly", TRT4 692 | } 693 | if Q.MaxIndex < 1 694 | { 695 | IniWrite,0,config.ini,Do Not Modify,Busy 696 | Busy := 0 697 | } 698 | S[4] := 1 699 | if (S[2] = 1 and S[3] = 1 and S[4] = 1 and Q.MaxIndex() < 1) 700 | { 701 | IniWrite,0,config.ini,Do Not Modify,Busy 702 | Busy := 0 703 | } 704 | } 705 | } 706 | return 707 | } 708 | 709 | SEButton: 710 | { 711 | GuiControl, Hide, SEB 712 | if Q.MaxIndex() > 0 713 | { 714 | SR := IsExpedWithinRange(1, 10000, 60000) 715 | SRS := Round(SR/1000,2) 716 | SetTimer, QueueTimer, %SR% 717 | GuiControl,, NB, Manual send in %SRS% seconds 718 | } 719 | return 720 | } 721 | 722 | QueueRemove(qrn) 723 | { 724 | global 725 | if Q.MaxIndex() > 0 726 | { 727 | QRi := 1 728 | Loop 729 | { 730 | if Q[QRi] = qrn 731 | { 732 | Q.Remove(QRi) 733 | } 734 | QRi += 1 735 | }Until QRi > Q.MaxIndex() 736 | } 737 | if Q.MaxIndex() < 1 738 | { 739 | GuiControl, Hide, SEB 740 | SetTimer, QueueTimer, Off 741 | CDT[1] := 0 742 | } 743 | return 744 | } 745 | 746 | QueueInsert(qin,QIs := 0) 747 | { 748 | global 749 | if QIs = 0 750 | { 751 | QueueRemove(qin) 752 | } 753 | Q.Insert(qin) 754 | GuiControl, Show, SEB 755 | return 756 | } 757 | 758 | Refresh: 759 | { 760 | if CDT[1] = 1 761 | { 762 | tSS := MS2HMS(GetRemainingTime(QTS,QTL,1)) 763 | GuiControl,, NB, Expedition returning - %tSS% 764 | } 765 | if CDT[2] = 1 766 | { 767 | tSS := MS2HMS(GetRemainingTime(TCS[2],TCL[2],1)) 768 | GuiControl,, T2, %tSS% 769 | } 770 | if CDT[3] = 1 771 | { 772 | tSS := MS2HMS(GetRemainingTime(TCS[3],TCL[3],1)) 773 | GuiControl,, T3, %tSS% 774 | } 775 | if CDT[4] = 1 776 | { 777 | tSS := MS2HMS(GetRemainingTime(TCS[4],TCL[4],1)) 778 | GuiControl,, T4, %tSS% 779 | } 780 | return 781 | } 782 | 783 | #Include %A_ScriptDir%/Functions/Click.ahk 784 | #Include %A_ScriptDir%/Functions/TimerUtils.ahk 785 | #Include %A_ScriptDir%/Functions/PixelCheck.ahk 786 | #Include %A_ScriptDir%/Functions/Pause.ahk 787 | #Include %A_ScriptDir%/Functions/Window.ahk 788 | #Include %A_ScriptDir%/Functions/PixelSearch.ahk 789 | #Include %A_ScriptDir%/Functions/StayAwake.ahk 790 | #Include %A_ScriptDir%/Functions/PixelMap.ahk 791 | #Include %A_ScriptDir%/Functions/Notify.ahk 792 | 793 | Initialize() 794 | { 795 | global 796 | SetExped := Array(item) 797 | ET := Array(item) 798 | Eh := Array(item) 799 | PGx := Array(item) 800 | SPGx := Array(item) 801 | MAPx := Array(item) 802 | MAPy := Array(item) 803 | TCS := Array(item) 804 | TCL := Array(item) 805 | CDT := Array(item) 806 | Q := Array() 807 | S := Array(item) 808 | pc := Array(item) 809 | S[2] := 0 810 | S[3] := 0 811 | S[4] := 0 812 | TRT2 := 0 813 | TRT3 := 0 814 | TRT4 := 0 815 | TCS[2] := 0 816 | TCS[3] := 0 817 | TCS[4] := 0 818 | TCL[2] := 0 819 | TCL[3] := 0 820 | TCL[4] := 0 821 | CDT[2] := 0 822 | CDT[3] := 0 823 | CDT[4] := 0 824 | RF := 0 825 | IB := 0 826 | ClickDelay := 150 827 | coffset := 4 828 | #Include %A_ScriptDir%/Constants/ExpeditionTime.ahk 829 | } 830 | 831 | GuiClose: 832 | { 833 | WinGetPos,TWinX,TWinY 834 | IniWrite,%TWinX%,config.ini,Variables,LastX 835 | IniWrite,%TWinY%,config.ini,Variables,LastY 836 | ExitApp 837 | } -------------------------------------------------------------------------------- /Functions/Gdip_All.ahk: -------------------------------------------------------------------------------- 1 | ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11 2 | ; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013 3 | ; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64 4 | ; 5 | ; 6 | ;##################################################################################### 7 | ;##################################################################################### 8 | ; STATUS ENUMERATION 9 | ; Return values for functions specified to have status enumerated return type 10 | ;##################################################################################### 11 | ; 12 | ; Ok = = 0 13 | ; GenericError = 1 14 | ; InvalidParameter = 2 15 | ; OutOfMemory = 3 16 | ; ObjectBusy = 4 17 | ; InsufficientBuffer = 5 18 | ; NotImplemented = 6 19 | ; Win32Error = 7 20 | ; WrongState = 8 21 | ; Aborted = 9 22 | ; FileNotFound = 10 23 | ; ValueOverflow = 11 24 | ; AccessDenied = 12 25 | ; UnknownImageFormat = 13 26 | ; FontFamilyNotFound = 14 27 | ; FontStyleNotFound = 15 28 | ; NotTrueTypeFont = 16 29 | ; UnsupportedGdiplusVersion = 17 30 | ; GdiplusNotInitialized = 18 31 | ; PropertyNotFound = 19 32 | ; PropertyNotSupported = 20 33 | ; ProfileNotFound = 21 34 | ; 35 | ;##################################################################################### 36 | ;##################################################################################### 37 | ; FUNCTIONS 38 | ;##################################################################################### 39 | ; 40 | ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) 41 | ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") 42 | ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="") 43 | ; SetImage(hwnd, hBitmap) 44 | ; Gdip_BitmapFromScreen(Screen=0, Raster="") 45 | ; CreateRectF(ByRef RectF, x, y, w, h) 46 | ; CreateSizeF(ByRef SizeF, w, h) 47 | ; CreateDIBSection 48 | ; 49 | ;##################################################################################### 50 | 51 | ; Function: UpdateLayeredWindow 52 | ; Description: Updates a layered window with the handle to the DC of a gdi bitmap 53 | ; 54 | ; hwnd Handle of the layered window to update 55 | ; hdc Handle to the DC of the GDI bitmap to update the window with 56 | ; Layeredx x position to place the window 57 | ; Layeredy y position to place the window 58 | ; Layeredw Width of the window 59 | ; Layeredh Height of the window 60 | ; Alpha Default = 255 : The transparency (0-255) to set the window transparency 61 | ; 62 | ; return If the function succeeds, the return value is nonzero 63 | ; 64 | ; notes If x or y omitted, then layered window will use its current coordinates 65 | ; If w or h omitted then current width and height will be used 66 | 67 | UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) 68 | { 69 | Ptr := A_PtrSize ? "UPtr" : "UInt" 70 | 71 | if ((x != "") && (y != "")) 72 | VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt") 73 | 74 | if (w = "") ||(h = "") 75 | WinGetPos,,, w, h, ahk_id %hwnd% 76 | 77 | return DllCall("UpdateLayeredWindow" 78 | , Ptr, hwnd 79 | , Ptr, 0 80 | , Ptr, ((x = "") && (y = "")) ? 0 : &pt 81 | , "int64*", w|h<<32 82 | , Ptr, hdc 83 | , "int64*", 0 84 | , "uint", 0 85 | , "UInt*", Alpha<<16|1<<24 86 | , "uint", 2) 87 | } 88 | 89 | ;##################################################################################### 90 | 91 | ; Function BitBlt 92 | ; Description The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle 93 | ; of pixels from the specified source device context into a destination device context. 94 | ; 95 | ; dDC handle to destination DC 96 | ; dx x-coord of destination upper-left corner 97 | ; dy y-coord of destination upper-left corner 98 | ; dw width of the area to copy 99 | ; dh height of the area to copy 100 | ; sDC handle to source DC 101 | ; sx x-coordinate of source upper-left corner 102 | ; sy y-coordinate of source upper-left corner 103 | ; Raster raster operation code 104 | ; 105 | ; return If the function succeeds, the return value is nonzero 106 | ; 107 | ; notes If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle 108 | ; 109 | ; BLACKNESS = 0x00000042 110 | ; NOTSRCERASE = 0x001100A6 111 | ; NOTSRCCOPY = 0x00330008 112 | ; SRCERASE = 0x00440328 113 | ; DSTINVERT = 0x00550009 114 | ; PATINVERT = 0x005A0049 115 | ; SRCINVERT = 0x00660046 116 | ; SRCAND = 0x008800C6 117 | ; MERGEPAINT = 0x00BB0226 118 | ; MERGECOPY = 0x00C000CA 119 | ; SRCCOPY = 0x00CC0020 120 | ; SRCPAINT = 0x00EE0086 121 | ; PATCOPY = 0x00F00021 122 | ; PATPAINT = 0x00FB0A09 123 | ; WHITENESS = 0x00FF0062 124 | ; CAPTUREBLT = 0x40000000 125 | ; NOMIRRORBITMAP = 0x80000000 126 | 127 | BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") 128 | { 129 | Ptr := A_PtrSize ? "UPtr" : "UInt" 130 | 131 | return DllCall("gdi32\BitBlt" 132 | , Ptr, dDC 133 | , "int", dx 134 | , "int", dy 135 | , "int", dw 136 | , "int", dh 137 | , Ptr, sDC 138 | , "int", sx 139 | , "int", sy 140 | , "uint", Raster ? Raster : 0x00CC0020) 141 | } 142 | 143 | ;##################################################################################### 144 | 145 | ; Function StretchBlt 146 | ; Description The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, 147 | ; stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. 148 | ; The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context. 149 | ; 150 | ; ddc handle to destination DC 151 | ; dx x-coord of destination upper-left corner 152 | ; dy y-coord of destination upper-left corner 153 | ; dw width of destination rectangle 154 | ; dh height of destination rectangle 155 | ; sdc handle to source DC 156 | ; sx x-coordinate of source upper-left corner 157 | ; sy y-coordinate of source upper-left corner 158 | ; sw width of source rectangle 159 | ; sh height of source rectangle 160 | ; Raster raster operation code 161 | ; 162 | ; return If the function succeeds, the return value is nonzero 163 | ; 164 | ; notes If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt 165 | 166 | StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="") 167 | { 168 | Ptr := A_PtrSize ? "UPtr" : "UInt" 169 | 170 | return DllCall("gdi32\StretchBlt" 171 | , Ptr, ddc 172 | , "int", dx 173 | , "int", dy 174 | , "int", dw 175 | , "int", dh 176 | , Ptr, sdc 177 | , "int", sx 178 | , "int", sy 179 | , "int", sw 180 | , "int", sh 181 | , "uint", Raster ? Raster : 0x00CC0020) 182 | } 183 | 184 | ;##################################################################################### 185 | 186 | ; Function SetStretchBltMode 187 | ; Description The SetStretchBltMode function sets the bitmap stretching mode in the specified device context 188 | ; 189 | ; hdc handle to the DC 190 | ; iStretchMode The stretching mode, describing how the target will be stretched 191 | ; 192 | ; return If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0 193 | ; 194 | ; STRETCH_ANDSCANS = 0x01 195 | ; STRETCH_ORSCANS = 0x02 196 | ; STRETCH_DELETESCANS = 0x03 197 | ; STRETCH_HALFTONE = 0x04 198 | 199 | SetStretchBltMode(hdc, iStretchMode=4) 200 | { 201 | return DllCall("gdi32\SetStretchBltMode" 202 | , A_PtrSize ? "UPtr" : "UInt", hdc 203 | , "int", iStretchMode) 204 | } 205 | 206 | ;##################################################################################### 207 | 208 | ; Function SetImage 209 | ; Description Associates a new image with a static control 210 | ; 211 | ; hwnd handle of the control to update 212 | ; hBitmap a gdi bitmap to associate the static control with 213 | ; 214 | ; return If the function succeeds, the return value is nonzero 215 | 216 | SetImage(hwnd, hBitmap) 217 | { 218 | SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd% 219 | E := ErrorLevel 220 | DeleteObject(E) 221 | return E 222 | } 223 | 224 | ;##################################################################################### 225 | 226 | ; Function SetSysColorToControl 227 | ; Description Sets a solid colour to a control 228 | ; 229 | ; hwnd handle of the control to update 230 | ; SysColor A system colour to set to the control 231 | ; 232 | ; return If the function succeeds, the return value is zero 233 | ; 234 | ; notes A control must have the 0xE style set to it so it is recognised as a bitmap 235 | ; By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control 236 | ; 237 | ; COLOR_3DDKSHADOW = 21 238 | ; COLOR_3DFACE = 15 239 | ; COLOR_3DHIGHLIGHT = 20 240 | ; COLOR_3DHILIGHT = 20 241 | ; COLOR_3DLIGHT = 22 242 | ; COLOR_3DSHADOW = 16 243 | ; COLOR_ACTIVEBORDER = 10 244 | ; COLOR_ACTIVECAPTION = 2 245 | ; COLOR_APPWORKSPACE = 12 246 | ; COLOR_BACKGROUND = 1 247 | ; COLOR_BTNFACE = 15 248 | ; COLOR_BTNHIGHLIGHT = 20 249 | ; COLOR_BTNHILIGHT = 20 250 | ; COLOR_BTNSHADOW = 16 251 | ; COLOR_BTNTEXT = 18 252 | ; COLOR_CAPTIONTEXT = 9 253 | ; COLOR_DESKTOP = 1 254 | ; COLOR_GRADIENTACTIVECAPTION = 27 255 | ; COLOR_GRADIENTINACTIVECAPTION = 28 256 | ; COLOR_GRAYTEXT = 17 257 | ; COLOR_HIGHLIGHT = 13 258 | ; COLOR_HIGHLIGHTTEXT = 14 259 | ; COLOR_HOTLIGHT = 26 260 | ; COLOR_INACTIVEBORDER = 11 261 | ; COLOR_INACTIVECAPTION = 3 262 | ; COLOR_INACTIVECAPTIONTEXT = 19 263 | ; COLOR_INFOBK = 24 264 | ; COLOR_INFOTEXT = 23 265 | ; COLOR_MENU = 4 266 | ; COLOR_MENUHILIGHT = 29 267 | ; COLOR_MENUBAR = 30 268 | ; COLOR_MENUTEXT = 7 269 | ; COLOR_SCROLLBAR = 0 270 | ; COLOR_WINDOW = 5 271 | ; COLOR_WINDOWFRAME = 6 272 | ; COLOR_WINDOWTEXT = 8 273 | 274 | SetSysColorToControl(hwnd, SysColor=15) 275 | { 276 | WinGetPos,,, w, h, ahk_id %hwnd% 277 | bc := DllCall("GetSysColor", "Int", SysColor, "UInt") 278 | pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16)) 279 | pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap) 280 | Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h) 281 | hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) 282 | SetImage(hwnd, hBitmap) 283 | Gdip_DeleteBrush(pBrushClear) 284 | Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap) 285 | return 0 286 | } 287 | 288 | ;##################################################################################### 289 | 290 | ; Function Gdip_BitmapFromScreen 291 | ; Description Gets a gdi+ bitmap from the screen 292 | ; 293 | ; Screen 0 = All screens 294 | ; Any numerical value = Just that screen 295 | ; x|y|w|h = Take specific coordinates with a width and height 296 | ; Raster raster operation code 297 | ; 298 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 299 | ; -1: one or more of x,y,w,h not passed properly 300 | ; 301 | ; notes If no raster operation is specified, then SRCCOPY is used to the returned bitmap 302 | 303 | Gdip_BitmapFromScreen(Screen=0, Raster="") 304 | { 305 | if (Screen = 0) 306 | { 307 | Sysget, x, 76 308 | Sysget, y, 77 309 | Sysget, w, 78 310 | Sysget, h, 79 311 | } 312 | else if (SubStr(Screen, 1, 5) = "hwnd:") 313 | { 314 | Screen := SubStr(Screen, 6) 315 | if !WinExist( "ahk_id " Screen) 316 | return -2 317 | WinGetPos,,, w, h, ahk_id %Screen% 318 | x := y := 0 319 | hhdc := GetDCEx(Screen, 3) 320 | } 321 | else if (Screen&1 != "") 322 | { 323 | Sysget, M, Monitor, %Screen% 324 | x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop 325 | } 326 | else 327 | { 328 | StringSplit, S, Screen, | 329 | x := S1, y := S2, w := S3, h := S4 330 | } 331 | 332 | if (x = "") || (y = "") || (w = "") || (h = "") 333 | return -1 334 | 335 | chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC() 336 | BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster) 337 | ReleaseDC(hhdc) 338 | 339 | pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) 340 | SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc) 341 | return pBitmap 342 | } 343 | 344 | ;##################################################################################### 345 | 346 | ; Function Gdip_BitmapFromHWND 347 | ; Description Uses PrintWindow to get a handle to the specified window and return a bitmap from it 348 | ; 349 | ; hwnd handle to the window to get a bitmap from 350 | ; 351 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 352 | ; 353 | ; notes Window must not be not minimised in order to get a handle to it's client area 354 | 355 | Gdip_BitmapFromHWND(hwnd) 356 | { 357 | WinGetPos,,, Width, Height, ahk_id %hwnd% 358 | hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) 359 | PrintWindow(hwnd, hdc) 360 | pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) 361 | SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) 362 | return pBitmap 363 | } 364 | 365 | ;##################################################################################### 366 | 367 | ; Function CreateRectF 368 | ; Description Creates a RectF object, containing a the coordinates and dimensions of a rectangle 369 | ; 370 | ; RectF Name to call the RectF object 371 | ; x x-coordinate of the upper left corner of the rectangle 372 | ; y y-coordinate of the upper left corner of the rectangle 373 | ; w Width of the rectangle 374 | ; h Height of the rectangle 375 | ; 376 | ; return No return value 377 | 378 | CreateRectF(ByRef RectF, x, y, w, h) 379 | { 380 | VarSetCapacity(RectF, 16) 381 | NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float") 382 | } 383 | 384 | ;##################################################################################### 385 | 386 | ; Function CreateRect 387 | ; Description Creates a Rect object, containing a the coordinates and dimensions of a rectangle 388 | ; 389 | ; RectF Name to call the RectF object 390 | ; x x-coordinate of the upper left corner of the rectangle 391 | ; y y-coordinate of the upper left corner of the rectangle 392 | ; w Width of the rectangle 393 | ; h Height of the rectangle 394 | ; 395 | ; return No return value 396 | 397 | CreateRect(ByRef Rect, x, y, w, h) 398 | { 399 | VarSetCapacity(Rect, 16) 400 | NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint") 401 | } 402 | ;##################################################################################### 403 | 404 | ; Function CreateSizeF 405 | ; Description Creates a SizeF object, containing an 2 values 406 | ; 407 | ; SizeF Name to call the SizeF object 408 | ; w w-value for the SizeF object 409 | ; h h-value for the SizeF object 410 | ; 411 | ; return No Return value 412 | 413 | CreateSizeF(ByRef SizeF, w, h) 414 | { 415 | VarSetCapacity(SizeF, 8) 416 | NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float") 417 | } 418 | ;##################################################################################### 419 | 420 | ; Function CreatePointF 421 | ; Description Creates a SizeF object, containing an 2 values 422 | ; 423 | ; SizeF Name to call the SizeF object 424 | ; w w-value for the SizeF object 425 | ; h h-value for the SizeF object 426 | ; 427 | ; return No Return value 428 | 429 | CreatePointF(ByRef PointF, x, y) 430 | { 431 | VarSetCapacity(PointF, 8) 432 | NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float") 433 | } 434 | ;##################################################################################### 435 | 436 | ; Function CreateDIBSection 437 | ; Description The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly 438 | ; 439 | ; w width of the bitmap to create 440 | ; h height of the bitmap to create 441 | ; hdc a handle to the device context to use the palette from 442 | ; bpp bits per pixel (32 = ARGB) 443 | ; ppvBits A pointer to a variable that receives a pointer to the location of the DIB bit values 444 | ; 445 | ; return returns a DIB. A gdi bitmap 446 | ; 447 | ; notes ppvBits will receive the location of the pixels in the DIB 448 | 449 | CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0) 450 | { 451 | Ptr := A_PtrSize ? "UPtr" : "UInt" 452 | 453 | hdc2 := hdc ? hdc : GetDC() 454 | VarSetCapacity(bi, 40, 0) 455 | 456 | NumPut(w, bi, 4, "uint") 457 | , NumPut(h, bi, 8, "uint") 458 | , NumPut(40, bi, 0, "uint") 459 | , NumPut(1, bi, 12, "ushort") 460 | , NumPut(0, bi, 16, "uInt") 461 | , NumPut(bpp, bi, 14, "ushort") 462 | 463 | hbm := DllCall("CreateDIBSection" 464 | , Ptr, hdc2 465 | , Ptr, &bi 466 | , "uint", 0 467 | , A_PtrSize ? "UPtr*" : "uint*", ppvBits 468 | , Ptr, 0 469 | , "uint", 0, Ptr) 470 | 471 | if !hdc 472 | ReleaseDC(hdc2) 473 | return hbm 474 | } 475 | 476 | ;##################################################################################### 477 | 478 | ; Function PrintWindow 479 | ; Description The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC 480 | ; 481 | ; hwnd A handle to the window that will be copied 482 | ; hdc A handle to the device context 483 | ; Flags Drawing options 484 | ; 485 | ; return If the function succeeds, it returns a nonzero value 486 | ; 487 | ; PW_CLIENTONLY = 1 488 | 489 | PrintWindow(hwnd, hdc, Flags=0) 490 | { 491 | Ptr := A_PtrSize ? "UPtr" : "UInt" 492 | 493 | return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags) 494 | } 495 | 496 | ;##################################################################################### 497 | 498 | ; Function DestroyIcon 499 | ; Description Destroys an icon and frees any memory the icon occupied 500 | ; 501 | ; hIcon Handle to the icon to be destroyed. The icon must not be in use 502 | ; 503 | ; return If the function succeeds, the return value is nonzero 504 | 505 | DestroyIcon(hIcon) 506 | { 507 | return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon) 508 | } 509 | 510 | ;##################################################################################### 511 | 512 | PaintDesktop(hdc) 513 | { 514 | return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc) 515 | } 516 | 517 | ;##################################################################################### 518 | 519 | CreateCompatibleBitmap(hdc, w, h) 520 | { 521 | return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h) 522 | } 523 | 524 | ;##################################################################################### 525 | 526 | ; Function CreateCompatibleDC 527 | ; Description This function creates a memory device context (DC) compatible with the specified device 528 | ; 529 | ; hdc Handle to an existing device context 530 | ; 531 | ; return returns the handle to a device context or 0 on failure 532 | ; 533 | ; notes If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen 534 | 535 | CreateCompatibleDC(hdc=0) 536 | { 537 | return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc) 538 | } 539 | 540 | ;##################################################################################### 541 | 542 | ; Function SelectObject 543 | ; Description The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type 544 | ; 545 | ; hdc Handle to a DC 546 | ; hgdiobj A handle to the object to be selected into the DC 547 | ; 548 | ; return If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced 549 | ; 550 | ; notes The specified object must have been created by using one of the following functions 551 | ; Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time) 552 | ; Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush 553 | ; Font - CreateFont, CreateFontIndirect 554 | ; Pen - CreatePen, CreatePenIndirect 555 | ; Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect 556 | ; 557 | ; notes If the selected object is a region and the function succeeds, the return value is one of the following value 558 | ; 559 | ; SIMPLEREGION = 2 Region consists of a single rectangle 560 | ; COMPLEXREGION = 3 Region consists of more than one rectangle 561 | ; NULLREGION = 1 Region is empty 562 | 563 | SelectObject(hdc, hgdiobj) 564 | { 565 | Ptr := A_PtrSize ? "UPtr" : "UInt" 566 | 567 | return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj) 568 | } 569 | 570 | ;##################################################################################### 571 | 572 | ; Function DeleteObject 573 | ; Description This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object 574 | ; After the object is deleted, the specified handle is no longer valid 575 | ; 576 | ; hObject Handle to a logical pen, brush, font, bitmap, region, or palette to delete 577 | ; 578 | ; return Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context 579 | 580 | DeleteObject(hObject) 581 | { 582 | return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject) 583 | } 584 | 585 | ;##################################################################################### 586 | 587 | ; Function GetDC 588 | ; Description This function retrieves a handle to a display device context (DC) for the client area of the specified window. 589 | ; The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window. 590 | ; 591 | ; hwnd Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen 592 | ; 593 | ; return The handle the device context for the specified window's client area indicates success. NULL indicates failure 594 | 595 | GetDC(hwnd=0) 596 | { 597 | return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd) 598 | } 599 | 600 | ;##################################################################################### 601 | 602 | ; DCX_CACHE = 0x2 603 | ; DCX_CLIPCHILDREN = 0x8 604 | ; DCX_CLIPSIBLINGS = 0x10 605 | ; DCX_EXCLUDERGN = 0x40 606 | ; DCX_EXCLUDEUPDATE = 0x100 607 | ; DCX_INTERSECTRGN = 0x80 608 | ; DCX_INTERSECTUPDATE = 0x200 609 | ; DCX_LOCKWINDOWUPDATE = 0x400 610 | ; DCX_NORECOMPUTE = 0x100000 611 | ; DCX_NORESETATTRS = 0x4 612 | ; DCX_PARENTCLIP = 0x20 613 | ; DCX_VALIDATE = 0x200000 614 | ; DCX_WINDOW = 0x1 615 | 616 | GetDCEx(hwnd, flags=0, hrgnClip=0) 617 | { 618 | Ptr := A_PtrSize ? "UPtr" : "UInt" 619 | 620 | return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags) 621 | } 622 | 623 | ;##################################################################################### 624 | 625 | ; Function ReleaseDC 626 | ; Description This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context 627 | ; 628 | ; hdc Handle to the device context to be released 629 | ; hwnd Handle to the window whose device context is to be released 630 | ; 631 | ; return 1 = released 632 | ; 0 = not released 633 | ; 634 | ; notes The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context 635 | ; An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function. 636 | 637 | ReleaseDC(hdc, hwnd=0) 638 | { 639 | Ptr := A_PtrSize ? "UPtr" : "UInt" 640 | 641 | return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc) 642 | } 643 | 644 | ;##################################################################################### 645 | 646 | ; Function DeleteDC 647 | ; Description The DeleteDC function deletes the specified device context (DC) 648 | ; 649 | ; hdc A handle to the device context 650 | ; 651 | ; return If the function succeeds, the return value is nonzero 652 | ; 653 | ; notes An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC 654 | 655 | DeleteDC(hdc) 656 | { 657 | return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc) 658 | } 659 | ;##################################################################################### 660 | 661 | ; Function Gdip_LibraryVersion 662 | ; Description Get the current library version 663 | ; 664 | ; return the library version 665 | ; 666 | ; notes This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts 667 | 668 | Gdip_LibraryVersion() 669 | { 670 | return 1.45 671 | } 672 | 673 | ;##################################################################################### 674 | 675 | ; Function: Gdip_BitmapFromBRA 676 | ; Description: Gets a pointer to a gdi+ bitmap from a BRA file 677 | ; 678 | ; BRAFromMemIn The variable for a BRA file read to memory 679 | ; File The name of the file, or its number that you would like (This depends on alternate parameter) 680 | ; Alternate Changes whether the File parameter is the file name or its number 681 | ; 682 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 683 | ; -1 = The BRA variable is empty 684 | ; -2 = The BRA has an incorrect header 685 | ; -3 = The BRA has information missing 686 | ; -4 = Could not find file inside the BRA 687 | 688 | Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0) 689 | { 690 | Static FName = "ObjRelease" 691 | 692 | if !BRAFromMemIn 693 | return -1 694 | Loop, Parse, BRAFromMemIn, `n 695 | { 696 | if (A_Index = 1) 697 | { 698 | StringSplit, Header, A_LoopField, | 699 | if (Header0 != 4 || Header2 != "BRA!") 700 | return -2 701 | } 702 | else if (A_Index = 2) 703 | { 704 | StringSplit, Info, A_LoopField, | 705 | if (Info0 != 3) 706 | return -3 707 | } 708 | else 709 | break 710 | } 711 | if !Alternate 712 | StringReplace, File, File, \, \\, All 713 | RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo) 714 | if !FileInfo 715 | return -4 716 | 717 | hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr) 718 | pData := DllCall("GlobalLock", Ptr, hData, Ptr) 719 | DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2) 720 | DllCall("GlobalUnlock", Ptr, hData) 721 | DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream) 722 | DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap) 723 | If (A_PtrSize) 724 | %FName%(pStream) 725 | Else 726 | DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream) 727 | return pBitmap 728 | } 729 | 730 | ;##################################################################################### 731 | 732 | ; Function Gdip_DrawRectangle 733 | ; Description This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap 734 | ; 735 | ; pGraphics Pointer to the Graphics of a bitmap 736 | ; pPen Pointer to a pen 737 | ; x x-coordinate of the top left of the rectangle 738 | ; y y-coordinate of the top left of the rectangle 739 | ; w width of the rectanlge 740 | ; h height of the rectangle 741 | ; 742 | ; return status enumeration. 0 = success 743 | ; 744 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 745 | 746 | Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) 747 | { 748 | Ptr := A_PtrSize ? "UPtr" : "UInt" 749 | 750 | return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h) 751 | } 752 | 753 | ;##################################################################################### 754 | 755 | ; Function Gdip_DrawRoundedRectangle 756 | ; Description This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap 757 | ; 758 | ; pGraphics Pointer to the Graphics of a bitmap 759 | ; pPen Pointer to a pen 760 | ; x x-coordinate of the top left of the rounded rectangle 761 | ; y y-coordinate of the top left of the rounded rectangle 762 | ; w width of the rectanlge 763 | ; h height of the rectangle 764 | ; r radius of the rounded corners 765 | ; 766 | ; return status enumeration. 0 = success 767 | ; 768 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 769 | 770 | Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r) 771 | { 772 | Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) 773 | Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) 774 | Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) 775 | Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) 776 | E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) 777 | Gdip_ResetClip(pGraphics) 778 | Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) 779 | Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) 780 | Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r) 781 | Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r) 782 | Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r) 783 | Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r) 784 | Gdip_ResetClip(pGraphics) 785 | return E 786 | } 787 | 788 | ;##################################################################################### 789 | 790 | ; Function Gdip_DrawEllipse 791 | ; Description This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap 792 | ; 793 | ; pGraphics Pointer to the Graphics of a bitmap 794 | ; pPen Pointer to a pen 795 | ; x x-coordinate of the top left of the rectangle the ellipse will be drawn into 796 | ; y y-coordinate of the top left of the rectangle the ellipse will be drawn into 797 | ; w width of the ellipse 798 | ; h height of the ellipse 799 | ; 800 | ; return status enumeration. 0 = success 801 | ; 802 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 803 | 804 | Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h) 805 | { 806 | Ptr := A_PtrSize ? "UPtr" : "UInt" 807 | 808 | return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h) 809 | } 810 | 811 | ;##################################################################################### 812 | 813 | ; Function Gdip_DrawBezier 814 | ; Description This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap 815 | ; 816 | ; pGraphics Pointer to the Graphics of a bitmap 817 | ; pPen Pointer to a pen 818 | ; x1 x-coordinate of the start of the bezier 819 | ; y1 y-coordinate of the start of the bezier 820 | ; x2 x-coordinate of the first arc of the bezier 821 | ; y2 y-coordinate of the first arc of the bezier 822 | ; x3 x-coordinate of the second arc of the bezier 823 | ; y3 y-coordinate of the second arc of the bezier 824 | ; x4 x-coordinate of the end of the bezier 825 | ; y4 y-coordinate of the end of the bezier 826 | ; 827 | ; return status enumeration. 0 = success 828 | ; 829 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 830 | 831 | Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4) 832 | { 833 | Ptr := A_PtrSize ? "UPtr" : "UInt" 834 | 835 | return DllCall("gdiplus\GdipDrawBezier" 836 | , Ptr, pgraphics 837 | , Ptr, pPen 838 | , "float", x1 839 | , "float", y1 840 | , "float", x2 841 | , "float", y2 842 | , "float", x3 843 | , "float", y3 844 | , "float", x4 845 | , "float", y4) 846 | } 847 | 848 | ;##################################################################################### 849 | 850 | ; Function Gdip_DrawArc 851 | ; Description This function uses a pen to draw the outline of an arc into the Graphics of a bitmap 852 | ; 853 | ; pGraphics Pointer to the Graphics of a bitmap 854 | ; pPen Pointer to a pen 855 | ; x x-coordinate of the start of the arc 856 | ; y y-coordinate of the start of the arc 857 | ; w width of the arc 858 | ; h height of the arc 859 | ; StartAngle specifies the angle between the x-axis and the starting point of the arc 860 | ; SweepAngle specifies the angle between the starting and ending points of the arc 861 | ; 862 | ; return status enumeration. 0 = success 863 | ; 864 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 865 | 866 | Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 867 | { 868 | Ptr := A_PtrSize ? "UPtr" : "UInt" 869 | 870 | return DllCall("gdiplus\GdipDrawArc" 871 | , Ptr, pGraphics 872 | , Ptr, pPen 873 | , "float", x 874 | , "float", y 875 | , "float", w 876 | , "float", h 877 | , "float", StartAngle 878 | , "float", SweepAngle) 879 | } 880 | 881 | ;##################################################################################### 882 | 883 | ; Function Gdip_DrawPie 884 | ; Description This function uses a pen to draw the outline of a pie into the Graphics of a bitmap 885 | ; 886 | ; pGraphics Pointer to the Graphics of a bitmap 887 | ; pPen Pointer to a pen 888 | ; x x-coordinate of the start of the pie 889 | ; y y-coordinate of the start of the pie 890 | ; w width of the pie 891 | ; h height of the pie 892 | ; StartAngle specifies the angle between the x-axis and the starting point of the pie 893 | ; SweepAngle specifies the angle between the starting and ending points of the pie 894 | ; 895 | ; return status enumeration. 0 = success 896 | ; 897 | ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width 898 | 899 | Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 900 | { 901 | Ptr := A_PtrSize ? "UPtr" : "UInt" 902 | 903 | return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle) 904 | } 905 | 906 | ;##################################################################################### 907 | 908 | ; Function Gdip_DrawLine 909 | ; Description This function uses a pen to draw a line into the Graphics of a bitmap 910 | ; 911 | ; pGraphics Pointer to the Graphics of a bitmap 912 | ; pPen Pointer to a pen 913 | ; x1 x-coordinate of the start of the line 914 | ; y1 y-coordinate of the start of the line 915 | ; x2 x-coordinate of the end of the line 916 | ; y2 y-coordinate of the end of the line 917 | ; 918 | ; return status enumeration. 0 = success 919 | 920 | Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2) 921 | { 922 | Ptr := A_PtrSize ? "UPtr" : "UInt" 923 | 924 | return DllCall("gdiplus\GdipDrawLine" 925 | , Ptr, pGraphics 926 | , Ptr, pPen 927 | , "float", x1 928 | , "float", y1 929 | , "float", x2 930 | , "float", y2) 931 | } 932 | 933 | ;##################################################################################### 934 | 935 | ; Function Gdip_DrawLines 936 | ; Description This function uses a pen to draw a series of joined lines into the Graphics of a bitmap 937 | ; 938 | ; pGraphics Pointer to the Graphics of a bitmap 939 | ; pPen Pointer to a pen 940 | ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... 941 | ; 942 | ; return status enumeration. 0 = success 943 | 944 | Gdip_DrawLines(pGraphics, pPen, Points) 945 | { 946 | Ptr := A_PtrSize ? "UPtr" : "UInt" 947 | StringSplit, Points, Points, | 948 | VarSetCapacity(PointF, 8*Points0) 949 | Loop, %Points0% 950 | { 951 | StringSplit, Coord, Points%A_Index%, `, 952 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 953 | } 954 | return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0) 955 | } 956 | 957 | ;##################################################################################### 958 | 959 | ; Function Gdip_FillRectangle 960 | ; Description This function uses a brush to fill a rectangle in the Graphics of a bitmap 961 | ; 962 | ; pGraphics Pointer to the Graphics of a bitmap 963 | ; pBrush Pointer to a brush 964 | ; x x-coordinate of the top left of the rectangle 965 | ; y y-coordinate of the top left of the rectangle 966 | ; w width of the rectanlge 967 | ; h height of the rectangle 968 | ; 969 | ; return status enumeration. 0 = success 970 | 971 | Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) 972 | { 973 | Ptr := A_PtrSize ? "UPtr" : "UInt" 974 | 975 | return DllCall("gdiplus\GdipFillRectangle" 976 | , Ptr, pGraphics 977 | , Ptr, pBrush 978 | , "float", x 979 | , "float", y 980 | , "float", w 981 | , "float", h) 982 | } 983 | 984 | ;##################################################################################### 985 | 986 | ; Function Gdip_FillRoundedRectangle 987 | ; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap 988 | ; 989 | ; pGraphics Pointer to the Graphics of a bitmap 990 | ; pBrush Pointer to a brush 991 | ; x x-coordinate of the top left of the rounded rectangle 992 | ; y y-coordinate of the top left of the rounded rectangle 993 | ; w width of the rectanlge 994 | ; h height of the rectangle 995 | ; r radius of the rounded corners 996 | ; 997 | ; return status enumeration. 0 = success 998 | 999 | Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r) 1000 | { 1001 | Region := Gdip_GetClipRegion(pGraphics) 1002 | Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) 1003 | Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) 1004 | Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) 1005 | Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) 1006 | E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) 1007 | Gdip_SetClipRegion(pGraphics, Region, 0) 1008 | Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) 1009 | Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) 1010 | Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r) 1011 | Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r) 1012 | Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r) 1013 | Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r) 1014 | Gdip_SetClipRegion(pGraphics, Region, 0) 1015 | Gdip_DeleteRegion(Region) 1016 | return E 1017 | } 1018 | 1019 | ;##################################################################################### 1020 | 1021 | ; Function Gdip_FillPolygon 1022 | ; Description This function uses a brush to fill a polygon in the Graphics of a bitmap 1023 | ; 1024 | ; pGraphics Pointer to the Graphics of a bitmap 1025 | ; pBrush Pointer to a brush 1026 | ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... 1027 | ; 1028 | ; return status enumeration. 0 = success 1029 | ; 1030 | ; notes Alternate will fill the polygon as a whole, wheras winding will fill each new "segment" 1031 | ; Alternate = 0 1032 | ; Winding = 1 1033 | 1034 | Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0) 1035 | { 1036 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1037 | 1038 | StringSplit, Points, Points, | 1039 | VarSetCapacity(PointF, 8*Points0) 1040 | Loop, %Points0% 1041 | { 1042 | StringSplit, Coord, Points%A_Index%, `, 1043 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 1044 | } 1045 | return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode) 1046 | } 1047 | 1048 | ;##################################################################################### 1049 | 1050 | ; Function Gdip_FillPie 1051 | ; Description This function uses a brush to fill a pie in the Graphics of a bitmap 1052 | ; 1053 | ; pGraphics Pointer to the Graphics of a bitmap 1054 | ; pBrush Pointer to a brush 1055 | ; x x-coordinate of the top left of the pie 1056 | ; y y-coordinate of the top left of the pie 1057 | ; w width of the pie 1058 | ; h height of the pie 1059 | ; StartAngle specifies the angle between the x-axis and the starting point of the pie 1060 | ; SweepAngle specifies the angle between the starting and ending points of the pie 1061 | ; 1062 | ; return status enumeration. 0 = success 1063 | 1064 | Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle) 1065 | { 1066 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1067 | 1068 | return DllCall("gdiplus\GdipFillPie" 1069 | , Ptr, pGraphics 1070 | , Ptr, pBrush 1071 | , "float", x 1072 | , "float", y 1073 | , "float", w 1074 | , "float", h 1075 | , "float", StartAngle 1076 | , "float", SweepAngle) 1077 | } 1078 | 1079 | ;##################################################################################### 1080 | 1081 | ; Function Gdip_FillEllipse 1082 | ; Description This function uses a brush to fill an ellipse in the Graphics of a bitmap 1083 | ; 1084 | ; pGraphics Pointer to the Graphics of a bitmap 1085 | ; pBrush Pointer to a brush 1086 | ; x x-coordinate of the top left of the ellipse 1087 | ; y y-coordinate of the top left of the ellipse 1088 | ; w width of the ellipse 1089 | ; h height of the ellipse 1090 | ; 1091 | ; return status enumeration. 0 = success 1092 | 1093 | Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h) 1094 | { 1095 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1096 | 1097 | return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h) 1098 | } 1099 | 1100 | ;##################################################################################### 1101 | 1102 | ; Function Gdip_FillRegion 1103 | ; Description This function uses a brush to fill a region in the Graphics of a bitmap 1104 | ; 1105 | ; pGraphics Pointer to the Graphics of a bitmap 1106 | ; pBrush Pointer to a brush 1107 | ; Region Pointer to a Region 1108 | ; 1109 | ; return status enumeration. 0 = success 1110 | ; 1111 | ; notes You can create a region Gdip_CreateRegion() and then add to this 1112 | 1113 | Gdip_FillRegion(pGraphics, pBrush, Region) 1114 | { 1115 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1116 | 1117 | return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region) 1118 | } 1119 | 1120 | ;##################################################################################### 1121 | 1122 | ; Function Gdip_FillPath 1123 | ; Description This function uses a brush to fill a path in the Graphics of a bitmap 1124 | ; 1125 | ; pGraphics Pointer to the Graphics of a bitmap 1126 | ; pBrush Pointer to a brush 1127 | ; Region Pointer to a Path 1128 | ; 1129 | ; return status enumeration. 0 = success 1130 | 1131 | Gdip_FillPath(pGraphics, pBrush, Path) 1132 | { 1133 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1134 | 1135 | return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path) 1136 | } 1137 | 1138 | ;##################################################################################### 1139 | 1140 | ; Function Gdip_DrawImagePointsRect 1141 | ; Description This function draws a bitmap into the Graphics of another bitmap and skews it 1142 | ; 1143 | ; pGraphics Pointer to the Graphics of a bitmap 1144 | ; pBitmap Pointer to a bitmap to be drawn 1145 | ; Points Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap 1146 | ; sx x-coordinate of source upper-left corner 1147 | ; sy y-coordinate of source upper-left corner 1148 | ; sw width of source rectangle 1149 | ; sh height of source rectangle 1150 | ; Matrix a matrix used to alter image attributes when drawing 1151 | ; 1152 | ; return status enumeration. 0 = success 1153 | ; 1154 | ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used 1155 | ; Matrix can be omitted to just draw with no alteration to ARGB 1156 | ; Matrix may be passed as a digit from 0 - 1 to change just transparency 1157 | ; Matrix can be passed as a matrix with any delimiter 1158 | 1159 | Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1) 1160 | { 1161 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1162 | 1163 | StringSplit, Points, Points, | 1164 | VarSetCapacity(PointF, 8*Points0) 1165 | Loop, %Points0% 1166 | { 1167 | StringSplit, Coord, Points%A_Index%, `, 1168 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 1169 | } 1170 | 1171 | if (Matrix&1 = "") 1172 | ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) 1173 | else if (Matrix != 1) 1174 | ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1") 1175 | 1176 | if (sx = "" && sy = "" && sw = "" && sh = "") 1177 | { 1178 | sx := 0, sy := 0 1179 | sw := Gdip_GetImageWidth(pBitmap) 1180 | sh := Gdip_GetImageHeight(pBitmap) 1181 | } 1182 | 1183 | E := DllCall("gdiplus\GdipDrawImagePointsRect" 1184 | , Ptr, pGraphics 1185 | , Ptr, pBitmap 1186 | , Ptr, &PointF 1187 | , "int", Points0 1188 | , "float", sx 1189 | , "float", sy 1190 | , "float", sw 1191 | , "float", sh 1192 | , "int", 2 1193 | , Ptr, ImageAttr 1194 | , Ptr, 0 1195 | , Ptr, 0) 1196 | if ImageAttr 1197 | Gdip_DisposeImageAttributes(ImageAttr) 1198 | return E 1199 | } 1200 | 1201 | ;##################################################################################### 1202 | 1203 | ; Function Gdip_DrawImage 1204 | ; Description This function draws a bitmap into the Graphics of another bitmap 1205 | ; 1206 | ; pGraphics Pointer to the Graphics of a bitmap 1207 | ; pBitmap Pointer to a bitmap to be drawn 1208 | ; dx x-coord of destination upper-left corner 1209 | ; dy y-coord of destination upper-left corner 1210 | ; dw width of destination image 1211 | ; dh height of destination image 1212 | ; sx x-coordinate of source upper-left corner 1213 | ; sy y-coordinate of source upper-left corner 1214 | ; sw width of source image 1215 | ; sh height of source image 1216 | ; Matrix a matrix used to alter image attributes when drawing 1217 | ; 1218 | ; return status enumeration. 0 = success 1219 | ; 1220 | ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used 1221 | ; Gdip_DrawImage performs faster 1222 | ; Matrix can be omitted to just draw with no alteration to ARGB 1223 | ; Matrix may be passed as a digit from 0 - 1 to change just transparency 1224 | ; Matrix can be passed as a matrix with any delimiter. For example: 1225 | ; MatrixBright= 1226 | ; ( 1227 | ; 1.5 |0 |0 |0 |0 1228 | ; 0 |1.5 |0 |0 |0 1229 | ; 0 |0 |1.5 |0 |0 1230 | ; 0 |0 |0 |1 |0 1231 | ; 0.05 |0.05 |0.05 |0 |1 1232 | ; ) 1233 | ; 1234 | ; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1 1235 | ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1 1236 | ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1 1237 | 1238 | Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1) 1239 | { 1240 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1241 | 1242 | if (Matrix&1 = "") 1243 | ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) 1244 | else if (Matrix != 1) 1245 | ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1") 1246 | 1247 | if (sx = "" && sy = "" && sw = "" && sh = "") 1248 | { 1249 | if (dx = "" && dy = "" && dw = "" && dh = "") 1250 | { 1251 | sx := dx := 0, sy := dy := 0 1252 | sw := dw := Gdip_GetImageWidth(pBitmap) 1253 | sh := dh := Gdip_GetImageHeight(pBitmap) 1254 | } 1255 | else 1256 | { 1257 | sx := sy := 0 1258 | sw := Gdip_GetImageWidth(pBitmap) 1259 | sh := Gdip_GetImageHeight(pBitmap) 1260 | } 1261 | } 1262 | 1263 | E := DllCall("gdiplus\GdipDrawImageRectRect" 1264 | , Ptr, pGraphics 1265 | , Ptr, pBitmap 1266 | , "float", dx 1267 | , "float", dy 1268 | , "float", dw 1269 | , "float", dh 1270 | , "float", sx 1271 | , "float", sy 1272 | , "float", sw 1273 | , "float", sh 1274 | , "int", 2 1275 | , Ptr, ImageAttr 1276 | , Ptr, 0 1277 | , Ptr, 0) 1278 | if ImageAttr 1279 | Gdip_DisposeImageAttributes(ImageAttr) 1280 | return E 1281 | } 1282 | 1283 | ;##################################################################################### 1284 | 1285 | ; Function Gdip_SetImageAttributesColorMatrix 1286 | ; Description This function creates an image matrix ready for drawing 1287 | ; 1288 | ; Matrix a matrix used to alter image attributes when drawing 1289 | ; passed with any delimeter 1290 | ; 1291 | ; return returns an image matrix on sucess or 0 if it fails 1292 | ; 1293 | ; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1 1294 | ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1 1295 | ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1 1296 | 1297 | Gdip_SetImageAttributesColorMatrix(Matrix) 1298 | { 1299 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1300 | 1301 | VarSetCapacity(ColourMatrix, 100, 0) 1302 | Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|") 1303 | StringSplit, Matrix, Matrix, | 1304 | Loop, 25 1305 | { 1306 | Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1 1307 | NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float") 1308 | } 1309 | DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr) 1310 | DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0) 1311 | return ImageAttr 1312 | } 1313 | 1314 | ;##################################################################################### 1315 | 1316 | ; Function Gdip_GraphicsFromImage 1317 | ; Description This function gets the graphics for a bitmap used for drawing functions 1318 | ; 1319 | ; pBitmap Pointer to a bitmap to get the pointer to its graphics 1320 | ; 1321 | ; return returns a pointer to the graphics of a bitmap 1322 | ; 1323 | ; notes a bitmap can be drawn into the graphics of another bitmap 1324 | 1325 | Gdip_GraphicsFromImage(pBitmap) 1326 | { 1327 | DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics) 1328 | return pGraphics 1329 | } 1330 | 1331 | ;##################################################################################### 1332 | 1333 | ; Function Gdip_GraphicsFromHDC 1334 | ; Description This function gets the graphics from the handle to a device context 1335 | ; 1336 | ; hdc This is the handle to the device context 1337 | ; 1338 | ; return returns a pointer to the graphics of a bitmap 1339 | ; 1340 | ; notes You can draw a bitmap into the graphics of another bitmap 1341 | 1342 | Gdip_GraphicsFromHDC(hdc) 1343 | { 1344 | DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics) 1345 | return pGraphics 1346 | } 1347 | 1348 | ;##################################################################################### 1349 | 1350 | ; Function Gdip_GetDC 1351 | ; Description This function gets the device context of the passed Graphics 1352 | ; 1353 | ; hdc This is the handle to the device context 1354 | ; 1355 | ; return returns the device context for the graphics of a bitmap 1356 | 1357 | Gdip_GetDC(pGraphics) 1358 | { 1359 | DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc) 1360 | return hdc 1361 | } 1362 | 1363 | ;##################################################################################### 1364 | 1365 | ; Function Gdip_ReleaseDC 1366 | ; Description This function releases a device context from use for further use 1367 | ; 1368 | ; pGraphics Pointer to the graphics of a bitmap 1369 | ; hdc This is the handle to the device context 1370 | ; 1371 | ; return status enumeration. 0 = success 1372 | 1373 | Gdip_ReleaseDC(pGraphics, hdc) 1374 | { 1375 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1376 | 1377 | return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc) 1378 | } 1379 | 1380 | ;##################################################################################### 1381 | 1382 | ; Function Gdip_GraphicsClear 1383 | ; Description Clears the graphics of a bitmap ready for further drawing 1384 | ; 1385 | ; pGraphics Pointer to the graphics of a bitmap 1386 | ; ARGB The colour to clear the graphics to 1387 | ; 1388 | ; return status enumeration. 0 = success 1389 | ; 1390 | ; notes By default this will make the background invisible 1391 | ; Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics 1392 | 1393 | Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff) 1394 | { 1395 | return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB) 1396 | } 1397 | 1398 | ;##################################################################################### 1399 | 1400 | ; Function Gdip_BlurBitmap 1401 | ; Description Gives a pointer to a blurred bitmap from a pointer to a bitmap 1402 | ; 1403 | ; pBitmap Pointer to a bitmap to be blurred 1404 | ; Blur The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur) 1405 | ; 1406 | ; return If the function succeeds, the return value is a pointer to the new blurred bitmap 1407 | ; -1 = The blur parameter is outside the range 1-100 1408 | ; 1409 | ; notes This function will not dispose of the original bitmap 1410 | 1411 | Gdip_BlurBitmap(pBitmap, Blur) 1412 | { 1413 | if (Blur > 100) || (Blur < 1) 1414 | return -1 1415 | 1416 | sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap) 1417 | dWidth := sWidth//Blur, dHeight := sHeight//Blur 1418 | 1419 | pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight) 1420 | G1 := Gdip_GraphicsFromImage(pBitmap1) 1421 | Gdip_SetInterpolationMode(G1, 7) 1422 | Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight) 1423 | 1424 | Gdip_DeleteGraphics(G1) 1425 | 1426 | pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight) 1427 | G2 := Gdip_GraphicsFromImage(pBitmap2) 1428 | Gdip_SetInterpolationMode(G2, 7) 1429 | Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight) 1430 | 1431 | Gdip_DeleteGraphics(G2) 1432 | Gdip_DisposeImage(pBitmap1) 1433 | return pBitmap2 1434 | } 1435 | 1436 | ;##################################################################################### 1437 | 1438 | ; Function: Gdip_SaveBitmapToFile 1439 | ; Description: Saves a bitmap to a file in any supported format onto disk 1440 | ; 1441 | ; pBitmap Pointer to a bitmap 1442 | ; sOutput The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG 1443 | ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality 1444 | ; 1445 | ; return If the function succeeds, the return value is zero, otherwise: 1446 | ; -1 = Extension supplied is not a supported file format 1447 | ; -2 = Could not get a list of encoders on system 1448 | ; -3 = Could not find matching encoder for specified file format 1449 | ; -4 = Could not get WideChar name of output file 1450 | ; -5 = Could not save file to disk 1451 | ; 1452 | ; notes This function will use the extension supplied from the sOutput parameter to determine the output format 1453 | 1454 | Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75) 1455 | { 1456 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1457 | 1458 | SplitPath, sOutput,,, Extension 1459 | if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG 1460 | return -1 1461 | Extension := "." Extension 1462 | 1463 | DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize) 1464 | VarSetCapacity(ci, nSize) 1465 | DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci) 1466 | if !(nCount && nSize) 1467 | return -2 1468 | 1469 | If (A_IsUnicode){ 1470 | StrGet_Name := "StrGet" 1471 | Loop, %nCount% 1472 | { 1473 | sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16") 1474 | if !InStr(sString, "*" Extension) 1475 | continue 1476 | 1477 | pCodec := &ci+idx 1478 | break 1479 | } 1480 | } else { 1481 | Loop, %nCount% 1482 | { 1483 | Location := NumGet(ci, 76*(A_Index-1)+44) 1484 | nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0) 1485 | VarSetCapacity(sString, nSize) 1486 | DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0) 1487 | if !InStr(sString, "*" Extension) 1488 | continue 1489 | 1490 | pCodec := &ci+76*(A_Index-1) 1491 | break 1492 | } 1493 | } 1494 | 1495 | if !pCodec 1496 | return -3 1497 | 1498 | if (Quality != 75) 1499 | { 1500 | Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality 1501 | if Extension in .JPG,.JPEG,.JPE,.JFIF 1502 | { 1503 | DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize) 1504 | VarSetCapacity(EncoderParameters, nSize, 0) 1505 | DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters) 1506 | Loop, % NumGet(EncoderParameters, "UInt") ;% 1507 | { 1508 | elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0) 1509 | if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6) 1510 | { 1511 | p := elem+&EncoderParameters-pad-4 1512 | NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt") 1513 | break 1514 | } 1515 | } 1516 | } 1517 | } 1518 | 1519 | if (!A_IsUnicode) 1520 | { 1521 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0) 1522 | VarSetCapacity(wOutput, nSize*2) 1523 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize) 1524 | VarSetCapacity(wOutput, -1) 1525 | if !VarSetCapacity(wOutput) 1526 | return -4 1527 | E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0) 1528 | } 1529 | else 1530 | E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0) 1531 | return E ? -5 : 0 1532 | } 1533 | 1534 | ;##################################################################################### 1535 | 1536 | ; Function Gdip_GetPixel 1537 | ; Description Gets the ARGB of a pixel in a bitmap 1538 | ; 1539 | ; pBitmap Pointer to a bitmap 1540 | ; x x-coordinate of the pixel 1541 | ; y y-coordinate of the pixel 1542 | ; 1543 | ; return Returns the ARGB value of the pixel 1544 | 1545 | Gdip_GetPixel(pBitmap, x, y) 1546 | { 1547 | DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB) 1548 | return ARGB 1549 | } 1550 | 1551 | ;##################################################################################### 1552 | 1553 | ; Function Gdip_SetPixel 1554 | ; Description Sets the ARGB of a pixel in a bitmap 1555 | ; 1556 | ; pBitmap Pointer to a bitmap 1557 | ; x x-coordinate of the pixel 1558 | ; y y-coordinate of the pixel 1559 | ; 1560 | ; return status enumeration. 0 = success 1561 | 1562 | Gdip_SetPixel(pBitmap, x, y, ARGB) 1563 | { 1564 | return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB) 1565 | } 1566 | 1567 | ;##################################################################################### 1568 | 1569 | ; Function Gdip_GetImageWidth 1570 | ; Description Gives the width of a bitmap 1571 | ; 1572 | ; pBitmap Pointer to a bitmap 1573 | ; 1574 | ; return Returns the width in pixels of the supplied bitmap 1575 | 1576 | Gdip_GetImageWidth(pBitmap) 1577 | { 1578 | DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width) 1579 | return Width 1580 | } 1581 | 1582 | ;##################################################################################### 1583 | 1584 | ; Function Gdip_GetImageHeight 1585 | ; Description Gives the height of a bitmap 1586 | ; 1587 | ; pBitmap Pointer to a bitmap 1588 | ; 1589 | ; return Returns the height in pixels of the supplied bitmap 1590 | 1591 | Gdip_GetImageHeight(pBitmap) 1592 | { 1593 | DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height) 1594 | return Height 1595 | } 1596 | 1597 | ;##################################################################################### 1598 | 1599 | ; Function Gdip_GetDimensions 1600 | ; Description Gives the width and height of a bitmap 1601 | ; 1602 | ; pBitmap Pointer to a bitmap 1603 | ; Width ByRef variable. This variable will be set to the width of the bitmap 1604 | ; Height ByRef variable. This variable will be set to the height of the bitmap 1605 | ; 1606 | ; return No return value 1607 | ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height 1608 | 1609 | Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height) 1610 | { 1611 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1612 | DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width) 1613 | DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height) 1614 | } 1615 | 1616 | ;##################################################################################### 1617 | 1618 | Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height) 1619 | { 1620 | Gdip_GetImageDimensions(pBitmap, Width, Height) 1621 | } 1622 | 1623 | ;##################################################################################### 1624 | 1625 | Gdip_GetImagePixelFormat(pBitmap) 1626 | { 1627 | DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format) 1628 | return Format 1629 | } 1630 | 1631 | ;##################################################################################### 1632 | 1633 | ; Function Gdip_GetDpiX 1634 | ; Description Gives the horizontal dots per inch of the graphics of a bitmap 1635 | ; 1636 | ; pBitmap Pointer to a bitmap 1637 | ; Width ByRef variable. This variable will be set to the width of the bitmap 1638 | ; Height ByRef variable. This variable will be set to the height of the bitmap 1639 | ; 1640 | ; return No return value 1641 | ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height 1642 | 1643 | Gdip_GetDpiX(pGraphics) 1644 | { 1645 | DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix) 1646 | return Round(dpix) 1647 | } 1648 | 1649 | ;##################################################################################### 1650 | 1651 | Gdip_GetDpiY(pGraphics) 1652 | { 1653 | DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy) 1654 | return Round(dpiy) 1655 | } 1656 | 1657 | ;##################################################################################### 1658 | 1659 | Gdip_GetImageHorizontalResolution(pBitmap) 1660 | { 1661 | DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix) 1662 | return Round(dpix) 1663 | } 1664 | 1665 | ;##################################################################################### 1666 | 1667 | Gdip_GetImageVerticalResolution(pBitmap) 1668 | { 1669 | DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy) 1670 | return Round(dpiy) 1671 | } 1672 | 1673 | ;##################################################################################### 1674 | 1675 | Gdip_BitmapSetResolution(pBitmap, dpix, dpiy) 1676 | { 1677 | return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy) 1678 | } 1679 | 1680 | ;##################################################################################### 1681 | 1682 | Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="") 1683 | { 1684 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1685 | , PtrA := A_PtrSize ? "UPtr*" : "UInt*" 1686 | 1687 | SplitPath, sFile,,, ext 1688 | if ext in exe,dll 1689 | { 1690 | Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16 1691 | BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4)) 1692 | 1693 | VarSetCapacity(buf, BufSize, 0) 1694 | Loop, Parse, Sizes, | 1695 | { 1696 | DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0) 1697 | 1698 | if !hIcon 1699 | continue 1700 | 1701 | if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf) 1702 | { 1703 | DestroyIcon(hIcon) 1704 | continue 1705 | } 1706 | 1707 | hbmMask := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4)) 1708 | hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4)) 1709 | if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf)) 1710 | { 1711 | DestroyIcon(hIcon) 1712 | continue 1713 | } 1714 | break 1715 | } 1716 | if !hIcon 1717 | return -1 1718 | 1719 | Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int") 1720 | hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) 1721 | if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3) 1722 | { 1723 | DestroyIcon(hIcon) 1724 | return -2 1725 | } 1726 | 1727 | VarSetCapacity(dib, 104) 1728 | DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize 1729 | Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding 1730 | DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld) 1731 | pBitmap := Gdip_CreateBitmap(Width, Height) 1732 | G := Gdip_GraphicsFromImage(pBitmap) 1733 | , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height) 1734 | SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) 1735 | Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld) 1736 | DestroyIcon(hIcon) 1737 | } 1738 | else 1739 | { 1740 | if (!A_IsUnicode) 1741 | { 1742 | VarSetCapacity(wFile, 1024) 1743 | DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512) 1744 | DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap) 1745 | } 1746 | else 1747 | DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap) 1748 | } 1749 | 1750 | return pBitmap 1751 | } 1752 | 1753 | ;##################################################################################### 1754 | 1755 | Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0) 1756 | { 1757 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1758 | 1759 | DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap) 1760 | return pBitmap 1761 | } 1762 | 1763 | ;##################################################################################### 1764 | 1765 | Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff) 1766 | { 1767 | DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background) 1768 | return hbm 1769 | } 1770 | 1771 | ;##################################################################################### 1772 | 1773 | Gdip_CreateBitmapFromHICON(hIcon) 1774 | { 1775 | DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap) 1776 | return pBitmap 1777 | } 1778 | 1779 | ;##################################################################################### 1780 | 1781 | Gdip_CreateHICONFromBitmap(pBitmap) 1782 | { 1783 | DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon) 1784 | return hIcon 1785 | } 1786 | 1787 | ;##################################################################################### 1788 | 1789 | Gdip_CreateBitmap(Width, Height, Format=0x26200A) 1790 | { 1791 | DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap) 1792 | Return pBitmap 1793 | } 1794 | 1795 | ;##################################################################################### 1796 | 1797 | Gdip_CreateBitmapFromClipboard() 1798 | { 1799 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1800 | 1801 | if !DllCall("OpenClipboard", Ptr, 0) 1802 | return -1 1803 | if !DllCall("IsClipboardFormatAvailable", "uint", 8) 1804 | return -2 1805 | if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr) 1806 | return -3 1807 | if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap) 1808 | return -4 1809 | if !DllCall("CloseClipboard") 1810 | return -5 1811 | DeleteObject(hBitmap) 1812 | return pBitmap 1813 | } 1814 | 1815 | ;##################################################################################### 1816 | 1817 | Gdip_SetBitmapToClipboard(pBitmap) 1818 | { 1819 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1820 | off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24 1821 | 1822 | hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) 1823 | DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 96 : 84, 0), Ptr, &oi) 1824 | hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, off1+NumGet(oi, off1, "UInt")-4, Ptr) 1825 | pdib := DllCall("GlobalLock", Ptr, hdib, Ptr) 1826 | DllCall("RtlMoveMemory", Ptr, pdib, "uint", &oi+off2, Ptr, 40) 1827 | DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4)), Ptr, NumGet(oi, off1, "UInt")) 1828 | DllCall("GlobalUnlock", Ptr, hdib) 1829 | DllCall("DeleteObject", Ptr, hBitmap) 1830 | DllCall("OpenClipboard", Ptr, 0) 1831 | DllCall("EmptyClipboard") 1832 | DllCall("SetClipboardData", "uint", 8, Ptr, hdib) 1833 | DllCall("CloseClipboard") 1834 | } 1835 | 1836 | ;##################################################################################### 1837 | 1838 | Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A) 1839 | { 1840 | DllCall("gdiplus\GdipCloneBitmapArea" 1841 | , "float", x 1842 | , "float", y 1843 | , "float", w 1844 | , "float", h 1845 | , "int", Format 1846 | , A_PtrSize ? "UPtr" : "UInt", pBitmap 1847 | , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest) 1848 | return pBitmapDest 1849 | } 1850 | 1851 | ;##################################################################################### 1852 | ; Create resources 1853 | ;##################################################################################### 1854 | 1855 | Gdip_CreatePen(ARGB, w) 1856 | { 1857 | DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen) 1858 | return pPen 1859 | } 1860 | 1861 | ;##################################################################################### 1862 | 1863 | Gdip_CreatePenFromBrush(pBrush, w) 1864 | { 1865 | DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen) 1866 | return pPen 1867 | } 1868 | 1869 | ;##################################################################################### 1870 | 1871 | Gdip_BrushCreateSolid(ARGB=0xff000000) 1872 | { 1873 | DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush) 1874 | return pBrush 1875 | } 1876 | 1877 | ;##################################################################################### 1878 | 1879 | ; HatchStyleHorizontal = 0 1880 | ; HatchStyleVertical = 1 1881 | ; HatchStyleForwardDiagonal = 2 1882 | ; HatchStyleBackwardDiagonal = 3 1883 | ; HatchStyleCross = 4 1884 | ; HatchStyleDiagonalCross = 5 1885 | ; HatchStyle05Percent = 6 1886 | ; HatchStyle10Percent = 7 1887 | ; HatchStyle20Percent = 8 1888 | ; HatchStyle25Percent = 9 1889 | ; HatchStyle30Percent = 10 1890 | ; HatchStyle40Percent = 11 1891 | ; HatchStyle50Percent = 12 1892 | ; HatchStyle60Percent = 13 1893 | ; HatchStyle70Percent = 14 1894 | ; HatchStyle75Percent = 15 1895 | ; HatchStyle80Percent = 16 1896 | ; HatchStyle90Percent = 17 1897 | ; HatchStyleLightDownwardDiagonal = 18 1898 | ; HatchStyleLightUpwardDiagonal = 19 1899 | ; HatchStyleDarkDownwardDiagonal = 20 1900 | ; HatchStyleDarkUpwardDiagonal = 21 1901 | ; HatchStyleWideDownwardDiagonal = 22 1902 | ; HatchStyleWideUpwardDiagonal = 23 1903 | ; HatchStyleLightVertical = 24 1904 | ; HatchStyleLightHorizontal = 25 1905 | ; HatchStyleNarrowVertical = 26 1906 | ; HatchStyleNarrowHorizontal = 27 1907 | ; HatchStyleDarkVertical = 28 1908 | ; HatchStyleDarkHorizontal = 29 1909 | ; HatchStyleDashedDownwardDiagonal = 30 1910 | ; HatchStyleDashedUpwardDiagonal = 31 1911 | ; HatchStyleDashedHorizontal = 32 1912 | ; HatchStyleDashedVertical = 33 1913 | ; HatchStyleSmallConfetti = 34 1914 | ; HatchStyleLargeConfetti = 35 1915 | ; HatchStyleZigZag = 36 1916 | ; HatchStyleWave = 37 1917 | ; HatchStyleDiagonalBrick = 38 1918 | ; HatchStyleHorizontalBrick = 39 1919 | ; HatchStyleWeave = 40 1920 | ; HatchStylePlaid = 41 1921 | ; HatchStyleDivot = 42 1922 | ; HatchStyleDottedGrid = 43 1923 | ; HatchStyleDottedDiamond = 44 1924 | ; HatchStyleShingle = 45 1925 | ; HatchStyleTrellis = 46 1926 | ; HatchStyleSphere = 47 1927 | ; HatchStyleSmallGrid = 48 1928 | ; HatchStyleSmallCheckerBoard = 49 1929 | ; HatchStyleLargeCheckerBoard = 50 1930 | ; HatchStyleOutlinedDiamond = 51 1931 | ; HatchStyleSolidDiamond = 52 1932 | ; HatchStyleTotal = 53 1933 | Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0) 1934 | { 1935 | DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush) 1936 | return pBrush 1937 | } 1938 | 1939 | ;##################################################################################### 1940 | 1941 | Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="") 1942 | { 1943 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1944 | , PtrA := A_PtrSize ? "UPtr*" : "UInt*" 1945 | 1946 | if !(w && h) 1947 | DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush) 1948 | else 1949 | DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush) 1950 | return pBrush 1951 | } 1952 | 1953 | ;##################################################################################### 1954 | 1955 | ; WrapModeTile = 0 1956 | ; WrapModeTileFlipX = 1 1957 | ; WrapModeTileFlipY = 2 1958 | ; WrapModeTileFlipXY = 3 1959 | ; WrapModeClamp = 4 1960 | Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1) 1961 | { 1962 | Ptr := A_PtrSize ? "UPtr" : "UInt" 1963 | 1964 | CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2) 1965 | DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush) 1966 | return LGpBrush 1967 | } 1968 | 1969 | ;##################################################################################### 1970 | 1971 | ; LinearGradientModeHorizontal = 0 1972 | ; LinearGradientModeVertical = 1 1973 | ; LinearGradientModeForwardDiagonal = 2 1974 | ; LinearGradientModeBackwardDiagonal = 3 1975 | Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1) 1976 | { 1977 | CreateRectF(RectF, x, y, w, h) 1978 | DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush) 1979 | return LGpBrush 1980 | } 1981 | 1982 | ;##################################################################################### 1983 | 1984 | Gdip_CloneBrush(pBrush) 1985 | { 1986 | DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone) 1987 | return pBrushClone 1988 | } 1989 | 1990 | ;##################################################################################### 1991 | ; Delete resources 1992 | ;##################################################################################### 1993 | 1994 | Gdip_DeletePen(pPen) 1995 | { 1996 | return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen) 1997 | } 1998 | 1999 | ;##################################################################################### 2000 | 2001 | Gdip_DeleteBrush(pBrush) 2002 | { 2003 | return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush) 2004 | } 2005 | 2006 | ;##################################################################################### 2007 | 2008 | Gdip_DisposeImage(pBitmap) 2009 | { 2010 | return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap) 2011 | } 2012 | 2013 | ;##################################################################################### 2014 | 2015 | Gdip_DeleteGraphics(pGraphics) 2016 | { 2017 | return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics) 2018 | } 2019 | 2020 | ;##################################################################################### 2021 | 2022 | Gdip_DisposeImageAttributes(ImageAttr) 2023 | { 2024 | return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr) 2025 | } 2026 | 2027 | ;##################################################################################### 2028 | 2029 | Gdip_DeleteFont(hFont) 2030 | { 2031 | return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont) 2032 | } 2033 | 2034 | ;##################################################################################### 2035 | 2036 | Gdip_DeleteStringFormat(hFormat) 2037 | { 2038 | return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat) 2039 | } 2040 | 2041 | ;##################################################################################### 2042 | 2043 | Gdip_DeleteFontFamily(hFamily) 2044 | { 2045 | return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily) 2046 | } 2047 | 2048 | ;##################################################################################### 2049 | 2050 | Gdip_DeleteMatrix(Matrix) 2051 | { 2052 | return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix) 2053 | } 2054 | 2055 | ;##################################################################################### 2056 | ; Text functions 2057 | ;##################################################################################### 2058 | 2059 | Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0) 2060 | { 2061 | IWidth := Width, IHeight:= Height 2062 | 2063 | RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos) 2064 | RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos) 2065 | RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width) 2066 | RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height) 2067 | RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour) 2068 | RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos) 2069 | RegExMatch(Options, "i)NoWrap", NoWrap) 2070 | RegExMatch(Options, "i)R(\d)", Rendering) 2071 | RegExMatch(Options, "i)S(\d+)(p*)", Size) 2072 | 2073 | if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2)) 2074 | PassBrush := 1, pBrush := Colour2 2075 | 2076 | if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2) 2077 | return -1 2078 | 2079 | Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout" 2080 | Loop, Parse, Styles, | 2081 | { 2082 | if RegExMatch(Options, "\b" A_loopField) 2083 | Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8 2084 | } 2085 | 2086 | Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right" 2087 | Loop, Parse, Alignments, | 2088 | { 2089 | if RegExMatch(Options, "\b" A_loopField) 2090 | Align |= A_Index//2.1 ; 0|0|1|1|2|2 2091 | } 2092 | 2093 | xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0 2094 | ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0 2095 | Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth 2096 | Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight 2097 | if !PassBrush 2098 | Colour := "0x" (Colour2 ? Colour2 : "ff000000") 2099 | Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4 2100 | Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12 2101 | 2102 | hFamily := Gdip_FontFamilyCreate(Font) 2103 | hFont := Gdip_FontCreate(hFamily, Size, Style) 2104 | FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000 2105 | hFormat := Gdip_StringFormatCreate(FormatStyle) 2106 | pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour) 2107 | if !(hFamily && hFont && hFormat && pBrush && pGraphics) 2108 | return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0 2109 | 2110 | CreateRectF(RC, xpos, ypos, Width, Height) 2111 | Gdip_SetStringFormatAlign(hFormat, Align) 2112 | Gdip_SetTextRenderingHint(pGraphics, Rendering) 2113 | ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) 2114 | 2115 | if vPos 2116 | { 2117 | StringSplit, ReturnRC, ReturnRC, | 2118 | 2119 | if (vPos = "vCentre") || (vPos = "vCenter") 2120 | ypos += (Height-ReturnRC4)//2 2121 | else if (vPos = "Top") || (vPos = "Up") 2122 | ypos := 0 2123 | else if (vPos = "Bottom") || (vPos = "Down") 2124 | ypos := Height-ReturnRC4 2125 | 2126 | CreateRectF(RC, xpos, ypos, Width, ReturnRC4) 2127 | ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) 2128 | } 2129 | 2130 | if !Measure 2131 | E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC) 2132 | 2133 | if !PassBrush 2134 | Gdip_DeleteBrush(pBrush) 2135 | Gdip_DeleteStringFormat(hFormat) 2136 | Gdip_DeleteFont(hFont) 2137 | Gdip_DeleteFontFamily(hFamily) 2138 | return E ? E : ReturnRC 2139 | } 2140 | 2141 | ;##################################################################################### 2142 | 2143 | Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF) 2144 | { 2145 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2146 | 2147 | if (!A_IsUnicode) 2148 | { 2149 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0) 2150 | VarSetCapacity(wString, nSize*2) 2151 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize) 2152 | } 2153 | 2154 | return DllCall("gdiplus\GdipDrawString" 2155 | , Ptr, pGraphics 2156 | , Ptr, A_IsUnicode ? &sString : &wString 2157 | , "int", -1 2158 | , Ptr, hFont 2159 | , Ptr, &RectF 2160 | , Ptr, hFormat 2161 | , Ptr, pBrush) 2162 | } 2163 | 2164 | ;##################################################################################### 2165 | 2166 | Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF) 2167 | { 2168 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2169 | 2170 | VarSetCapacity(RC, 16) 2171 | if !A_IsUnicode 2172 | { 2173 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0) 2174 | VarSetCapacity(wString, nSize*2) 2175 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize) 2176 | } 2177 | 2178 | DllCall("gdiplus\GdipMeasureString" 2179 | , Ptr, pGraphics 2180 | , Ptr, A_IsUnicode ? &sString : &wString 2181 | , "int", -1 2182 | , Ptr, hFont 2183 | , Ptr, &RectF 2184 | , Ptr, hFormat 2185 | , Ptr, &RC 2186 | , "uint*", Chars 2187 | , "uint*", Lines) 2188 | 2189 | return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0 2190 | } 2191 | 2192 | ; Near = 0 2193 | ; Center = 1 2194 | ; Far = 2 2195 | Gdip_SetStringFormatAlign(hFormat, Align) 2196 | { 2197 | return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align) 2198 | } 2199 | 2200 | ; StringFormatFlagsDirectionRightToLeft = 0x00000001 2201 | ; StringFormatFlagsDirectionVertical = 0x00000002 2202 | ; StringFormatFlagsNoFitBlackBox = 0x00000004 2203 | ; StringFormatFlagsDisplayFormatControl = 0x00000020 2204 | ; StringFormatFlagsNoFontFallback = 0x00000400 2205 | ; StringFormatFlagsMeasureTrailingSpaces = 0x00000800 2206 | ; StringFormatFlagsNoWrap = 0x00001000 2207 | ; StringFormatFlagsLineLimit = 0x00002000 2208 | ; StringFormatFlagsNoClip = 0x00004000 2209 | Gdip_StringFormatCreate(Format=0, Lang=0) 2210 | { 2211 | DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat) 2212 | return hFormat 2213 | } 2214 | 2215 | ; Regular = 0 2216 | ; Bold = 1 2217 | ; Italic = 2 2218 | ; BoldItalic = 3 2219 | ; Underline = 4 2220 | ; Strikeout = 8 2221 | Gdip_FontCreate(hFamily, Size, Style=0) 2222 | { 2223 | DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont) 2224 | return hFont 2225 | } 2226 | 2227 | Gdip_FontFamilyCreate(Font) 2228 | { 2229 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2230 | 2231 | if (!A_IsUnicode) 2232 | { 2233 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0) 2234 | VarSetCapacity(wFont, nSize*2) 2235 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize) 2236 | } 2237 | 2238 | DllCall("gdiplus\GdipCreateFontFamilyFromName" 2239 | , Ptr, A_IsUnicode ? &Font : &wFont 2240 | , "uint", 0 2241 | , A_PtrSize ? "UPtr*" : "UInt*", hFamily) 2242 | 2243 | return hFamily 2244 | } 2245 | 2246 | ;##################################################################################### 2247 | ; Matrix functions 2248 | ;##################################################################################### 2249 | 2250 | Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y) 2251 | { 2252 | DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix) 2253 | return Matrix 2254 | } 2255 | 2256 | Gdip_CreateMatrix() 2257 | { 2258 | DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix) 2259 | return Matrix 2260 | } 2261 | 2262 | ;##################################################################################### 2263 | ; GraphicsPath functions 2264 | ;##################################################################################### 2265 | 2266 | ; Alternate = 0 2267 | ; Winding = 1 2268 | Gdip_CreatePath(BrushMode=0) 2269 | { 2270 | DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path) 2271 | return Path 2272 | } 2273 | 2274 | Gdip_AddPathEllipse(Path, x, y, w, h) 2275 | { 2276 | return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h) 2277 | } 2278 | 2279 | Gdip_AddPathPolygon(Path, Points) 2280 | { 2281 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2282 | 2283 | StringSplit, Points, Points, | 2284 | VarSetCapacity(PointF, 8*Points0) 2285 | Loop, %Points0% 2286 | { 2287 | StringSplit, Coord, Points%A_Index%, `, 2288 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 2289 | } 2290 | 2291 | return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0) 2292 | } 2293 | 2294 | Gdip_DeletePath(Path) 2295 | { 2296 | return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path) 2297 | } 2298 | 2299 | ;##################################################################################### 2300 | ; Quality functions 2301 | ;##################################################################################### 2302 | 2303 | ; SystemDefault = 0 2304 | ; SingleBitPerPixelGridFit = 1 2305 | ; SingleBitPerPixel = 2 2306 | ; AntiAliasGridFit = 3 2307 | ; AntiAlias = 4 2308 | Gdip_SetTextRenderingHint(pGraphics, RenderingHint) 2309 | { 2310 | return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint) 2311 | } 2312 | 2313 | ; Default = 0 2314 | ; LowQuality = 1 2315 | ; HighQuality = 2 2316 | ; Bilinear = 3 2317 | ; Bicubic = 4 2318 | ; NearestNeighbor = 5 2319 | ; HighQualityBilinear = 6 2320 | ; HighQualityBicubic = 7 2321 | Gdip_SetInterpolationMode(pGraphics, InterpolationMode) 2322 | { 2323 | return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode) 2324 | } 2325 | 2326 | ; Default = 0 2327 | ; HighSpeed = 1 2328 | ; HighQuality = 2 2329 | ; None = 3 2330 | ; AntiAlias = 4 2331 | Gdip_SetSmoothingMode(pGraphics, SmoothingMode) 2332 | { 2333 | return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode) 2334 | } 2335 | 2336 | ; CompositingModeSourceOver = 0 (blended) 2337 | ; CompositingModeSourceCopy = 1 (overwrite) 2338 | Gdip_SetCompositingMode(pGraphics, CompositingMode=0) 2339 | { 2340 | return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode) 2341 | } 2342 | 2343 | ;##################################################################################### 2344 | ; Extra functions 2345 | ;##################################################################################### 2346 | 2347 | Gdip_Startup() 2348 | { 2349 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2350 | 2351 | if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr) 2352 | DllCall("LoadLibrary", "str", "gdiplus") 2353 | VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1) 2354 | DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0) 2355 | return pToken 2356 | } 2357 | 2358 | Gdip_Shutdown(pToken) 2359 | { 2360 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2361 | 2362 | DllCall("gdiplus\GdiplusShutdown", Ptr, pToken) 2363 | if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr) 2364 | DllCall("FreeLibrary", Ptr, hModule) 2365 | return 0 2366 | } 2367 | 2368 | ; Prepend = 0; The new operation is applied before the old operation. 2369 | ; Append = 1; The new operation is applied after the old operation. 2370 | Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0) 2371 | { 2372 | return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder) 2373 | } 2374 | 2375 | Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0) 2376 | { 2377 | return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder) 2378 | } 2379 | 2380 | Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0) 2381 | { 2382 | return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder) 2383 | } 2384 | 2385 | Gdip_ResetWorldTransform(pGraphics) 2386 | { 2387 | return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics) 2388 | } 2389 | 2390 | Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation) 2391 | { 2392 | pi := 3.14159, TAngle := Angle*(pi/180) 2393 | 2394 | Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360) 2395 | if ((Bound >= 0) && (Bound <= 90)) 2396 | xTranslation := Height*Sin(TAngle), yTranslation := 0 2397 | else if ((Bound > 90) && (Bound <= 180)) 2398 | xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle) 2399 | else if ((Bound > 180) && (Bound <= 270)) 2400 | xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle)) 2401 | else if ((Bound > 270) && (Bound <= 360)) 2402 | xTranslation := 0, yTranslation := -Width*Sin(TAngle) 2403 | } 2404 | 2405 | Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight) 2406 | { 2407 | pi := 3.14159, TAngle := Angle*(pi/180) 2408 | if !(Width && Height) 2409 | return -1 2410 | RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle))) 2411 | RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle))) 2412 | } 2413 | 2414 | ; RotateNoneFlipNone = 0 2415 | ; Rotate90FlipNone = 1 2416 | ; Rotate180FlipNone = 2 2417 | ; Rotate270FlipNone = 3 2418 | ; RotateNoneFlipX = 4 2419 | ; Rotate90FlipX = 5 2420 | ; Rotate180FlipX = 6 2421 | ; Rotate270FlipX = 7 2422 | ; RotateNoneFlipY = Rotate180FlipX 2423 | ; Rotate90FlipY = Rotate270FlipX 2424 | ; Rotate180FlipY = RotateNoneFlipX 2425 | ; Rotate270FlipY = Rotate90FlipX 2426 | ; RotateNoneFlipXY = Rotate180FlipNone 2427 | ; Rotate90FlipXY = Rotate270FlipNone 2428 | ; Rotate180FlipXY = RotateNoneFlipNone 2429 | ; Rotate270FlipXY = Rotate90FlipNone 2430 | 2431 | Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1) 2432 | { 2433 | return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType) 2434 | } 2435 | 2436 | ; Replace = 0 2437 | ; Intersect = 1 2438 | ; Union = 2 2439 | ; Xor = 3 2440 | ; Exclude = 4 2441 | ; Complement = 5 2442 | Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0) 2443 | { 2444 | return DllCall("gdiplus\GdipSetClipRect", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode) 2445 | } 2446 | 2447 | Gdip_SetClipPath(pGraphics, Path, CombineMode=0) 2448 | { 2449 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2450 | return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode) 2451 | } 2452 | 2453 | Gdip_ResetClip(pGraphics) 2454 | { 2455 | return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics) 2456 | } 2457 | 2458 | Gdip_GetClipRegion(pGraphics) 2459 | { 2460 | Region := Gdip_CreateRegion() 2461 | DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", Region) 2462 | return Region 2463 | } 2464 | 2465 | Gdip_SetClipRegion(pGraphics, Region, CombineMode=0) 2466 | { 2467 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2468 | 2469 | return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode) 2470 | } 2471 | 2472 | Gdip_CreateRegion() 2473 | { 2474 | DllCall("gdiplus\GdipCreateRegion", A_PtrSize ? "UPtr*" : "UInt*", Region) 2475 | return Region 2476 | } 2477 | 2478 | Gdip_DeleteRegion(Region) 2479 | { 2480 | return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region) 2481 | } 2482 | 2483 | ;##################################################################################### 2484 | ; BitmapLockBits 2485 | ;##################################################################################### 2486 | 2487 | Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a) 2488 | { 2489 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2490 | 2491 | CreateRect(Rect, x, y, w, h) 2492 | VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0) 2493 | E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData) 2494 | Stride := NumGet(BitmapData, 8, "Int") 2495 | Scan0 := NumGet(BitmapData, 16, Ptr) 2496 | return E 2497 | } 2498 | 2499 | ;##################################################################################### 2500 | 2501 | Gdip_UnlockBits(pBitmap, ByRef BitmapData) 2502 | { 2503 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2504 | 2505 | return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData) 2506 | } 2507 | 2508 | ;##################################################################################### 2509 | 2510 | Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride) 2511 | { 2512 | Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt") 2513 | } 2514 | 2515 | ;##################################################################################### 2516 | 2517 | Gdip_GetLockBitPixel(Scan0, x, y, Stride) 2518 | { 2519 | return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt") 2520 | } 2521 | 2522 | ;##################################################################################### 2523 | 2524 | Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize) 2525 | { 2526 | static PixelateBitmap 2527 | 2528 | Ptr := A_PtrSize ? "UPtr" : "UInt" 2529 | 2530 | if (!PixelateBitmap) 2531 | { 2532 | if A_PtrSize != 8 ; x86 machine code 2533 | MCode_PixelateBitmap = 2534 | (LTrim Join 2535 | 558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4 2536 | 397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4 2537 | 8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF 2538 | 4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D 2539 | C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8 2540 | 8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945 2541 | 148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F 2542 | B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7 2543 | F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB 2544 | 038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55 2545 | 1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7 2546 | FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D 2547 | D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B 2548 | 45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9 2549 | 89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C 2550 | 0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8 2551 | 75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8 2552 | 8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F 2553 | B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B 2554 | 451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639 2555 | 75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811 2556 | 8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800 2557 | ) 2558 | else ; x64 machine code 2559 | MCode_PixelateBitmap = 2560 | (LTrim Join 2561 | 4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C 2562 | 448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05 2563 | 4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF 2564 | C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C 2565 | 24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000 2566 | 004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800 2567 | 0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533 2568 | DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6 2569 | 024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3 2570 | 99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841 2571 | 8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD 2572 | 4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480 2573 | 000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33 2574 | ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602 2575 | 4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3 2576 | 99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541 2577 | 8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C 2578 | 2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585 2579 | FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248 2580 | 83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399 2581 | F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541 2582 | 0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2 2583 | 413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3 2584 | ) 2585 | 2586 | VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2) 2587 | Loop % StrLen(MCode_PixelateBitmap)//2 ;% 2588 | NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar") 2589 | DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0) 2590 | } 2591 | 2592 | Gdip_GetImageDimensions(pBitmap, Width, Height) 2593 | 2594 | if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut)) 2595 | return -1 2596 | if (BlockSize > Width || BlockSize > Height) 2597 | return -2 2598 | 2599 | E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1) 2600 | E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2) 2601 | if (E1 || E2) 2602 | return -3 2603 | 2604 | E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize) 2605 | 2606 | Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2) 2607 | return 0 2608 | } 2609 | 2610 | ;##################################################################################### 2611 | 2612 | Gdip_ToARGB(A, R, G, B) 2613 | { 2614 | return (A << 24) | (R << 16) | (G << 8) | B 2615 | } 2616 | 2617 | ;##################################################################################### 2618 | 2619 | Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B) 2620 | { 2621 | A := (0xff000000 & ARGB) >> 24 2622 | R := (0x00ff0000 & ARGB) >> 16 2623 | G := (0x0000ff00 & ARGB) >> 8 2624 | B := 0x000000ff & ARGB 2625 | } 2626 | 2627 | ;##################################################################################### 2628 | 2629 | Gdip_AFromARGB(ARGB) 2630 | { 2631 | return (0xff000000 & ARGB) >> 24 2632 | } 2633 | 2634 | ;##################################################################################### 2635 | 2636 | Gdip_RFromARGB(ARGB) 2637 | { 2638 | return (0x00ff0000 & ARGB) >> 16 2639 | } 2640 | 2641 | ;##################################################################################### 2642 | 2643 | Gdip_GFromARGB(ARGB) 2644 | { 2645 | return (0x0000ff00 & ARGB) >> 8 2646 | } 2647 | 2648 | ;##################################################################################### 2649 | 2650 | Gdip_BFromARGB(ARGB) 2651 | { 2652 | return 0x000000ff & ARGB 2653 | } 2654 | 2655 | ;##################################################################################### 2656 | 2657 | StrGetB(Address, Length=-1, Encoding=0) 2658 | { 2659 | ; Flexible parameter handling: 2660 | if Length is not integer 2661 | Encoding := Length, Length := -1 2662 | 2663 | ; Check for obvious errors. 2664 | if (Address+0 < 1024) 2665 | return 2666 | 2667 | ; Ensure 'Encoding' contains a numeric identifier. 2668 | if Encoding = UTF-16 2669 | Encoding = 1200 2670 | else if Encoding = UTF-8 2671 | Encoding = 65001 2672 | else if SubStr(Encoding,1,2)="CP" 2673 | Encoding := SubStr(Encoding,3) 2674 | 2675 | if !Encoding ; "" or 0 2676 | { 2677 | ; No conversion necessary, but we might not want the whole string. 2678 | if (Length == -1) 2679 | Length := DllCall("lstrlen", "uint", Address) 2680 | VarSetCapacity(String, Length) 2681 | DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1) 2682 | } 2683 | else if Encoding = 1200 ; UTF-16 2684 | { 2685 | char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0) 2686 | VarSetCapacity(String, char_count) 2687 | DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0) 2688 | } 2689 | else if Encoding is integer 2690 | { 2691 | ; Convert from target encoding to UTF-16 then to the active code page. 2692 | char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0) 2693 | VarSetCapacity(String, char_count * 2) 2694 | char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2) 2695 | String := StrGetB(&String, char_count, 1200) 2696 | } 2697 | 2698 | return String 2699 | } --------------------------------------------------------------------------------