├── .gitignore ├── keylogger.ico ├── keylogger.xcf ├── TODO ├── inspiration ├── keylog-small.ahk ├── keylog-small-ctrl-chars.ahk ├── all-keys.ahk └── Gdip.ahk ├── Makefile ├── README.md ├── count-strokes.awk └── keylogger.ahk /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | -------------------------------------------------------------------------------- /keylogger.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nbirnel/keylogger/HEAD/keylogger.ico -------------------------------------------------------------------------------- /keylogger.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nbirnel/keylogger/HEAD/keylogger.xcf -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | add a better location for log file 2 | make an icon 3 | add a quick 'turn off and on' hotkey 4 | 5 | -------------------------------------------------------------------------------- /inspiration/keylog-small.ahk: -------------------------------------------------------------------------------- 1 | Loop { ; Smallest keylogger I can come up with. Key strokes are saved to key.log, opens in notepad. 2 | Input, key, V T5, 3 | FileAppend, %key%, key.log 4 | } -------------------------------------------------------------------------------- /inspiration/keylog-small-ctrl-chars.ahk: -------------------------------------------------------------------------------- 1 | Loop { ; Smallest keylogger I can come up with. Key strokes are saved to key.log, opens in notepad. 2 | Input, key, V I C M T5, 3 | FileAppend, %key%, key.log 4 | } 5 | -------------------------------------------------------------------------------- /inspiration/all-keys.ahk: -------------------------------------------------------------------------------- 1 | SetFormat, Integer, H 2 | Loop, 0x7f 3 | Hotkey, % "*~" . chr(A_Index), LogKey 4 | Return 5 | LogKey: 6 | Key := RegExReplace(asc(SubStr(A_ThisHotkey,0)),"^0x") 7 | FileAppend, % (StrLen(Key) == 1 ? "0" : "") . Key, Log.log 8 | Return -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC="/cygdrive/c/Program Files (x86)/AutoHotkey/Compiler/Ahk2Exe.exe" 2 | PROG=keylogger 3 | 4 | ${PROG}.exe : ${PROG}.ahk ${PROG}.ico 5 | ${CC} /in ${PROG}.ahk /icon ${PROG}.ico 6 | 7 | test : ${PROG}.exe 8 | ./${PROG}.exe & 9 | 10 | .PHONY : test 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | keylogger 2 | 3 | A keylogger for Windows. 4 | Keylogger records all of your keystrokes and mouse clicks. 5 | It is not meant for surveilance, 6 | but rather for analyzing workflows. 7 | It does not capture the clipboard, 8 | or make screen shots. 9 | 10 | This is working as is, 11 | but needs some tidying up. 12 | -------------------------------------------------------------------------------- /count-strokes.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | BEGIN { 4 | FS = " " 5 | current_repeats=1 6 | errors=0 7 | windowchanges=0 8 | mouseevents=0 9 | keyevents=0 10 | unique_keyevents=0 11 | possible_autorepeats=0 12 | uniq_wins=0 13 | } 14 | 15 | { 16 | # ASCII 30 octal 036 Record Separator for window focus 17 | if ($0 ~ /^/) { 18 | windowchanges++ 19 | winid[$3]++ 20 | # ASCII 31 octal 037 Unit Separator for mouse clicks 21 | } else if ($0 ~ /^/) { 22 | is_mouse_key_switch("m") 23 | mouseevents++ 24 | } else if ($0 ~ /^$/) { 25 | errors++ 26 | } else { 27 | is_mouse_key_switch("k") 28 | keyevents++ 29 | 30 | if ($0 == lastkey) { 31 | possible_autorepeats++ 32 | current_repeats++ 33 | if (current_repeats == 2) { 34 | possible_autorepeat_events++ 35 | } 36 | } else { 37 | current_repeats=1 38 | unique_keyevents++ 39 | } 40 | 41 | lastkey=$0 42 | } 43 | } 44 | 45 | END { 46 | printf("%s: %d\n", "errors", errors) 47 | printf("%s: %d\n", "mouse_key_switch", mouse_key_switch) 48 | printf("%s: %d\n", "windowchanges", windowchanges) 49 | for (win in winid) 50 | uniq_wins++ 51 | printf("%s: %d\n", "uniq_wins", uniq_wins) 52 | printf("%s: %d\n", "mouseevents", mouseevents) 53 | printf("%s: %d\n", "keyevents", keyevents) 54 | printf("%s: %d\n", "unique_keyevents", unique_keyevents) 55 | printf("%s: %d\n", "possible_autorepeat_events", possible_autorepeat_events) 56 | printf("%s: %d\n", "possible_autorepeats", possible_autorepeats) 57 | printf("%s: %d\n", "events", NR - errors) 58 | } 59 | 60 | function is_mouse_key_switch(mk) { 61 | if (mouse_key != mk) { 62 | mouse_key_switch++ 63 | } 64 | mouse_key = mk 65 | } 66 | 67 | -------------------------------------------------------------------------------- /keylogger.ahk: -------------------------------------------------------------------------------- 1 | ; modified from: 2 | ; http://www.autohotkey.com/board/topic/30294-simple-key-stroke-recorder/ 3 | ; 4 | 5 | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 6 | logdir = %A_AppData%\keylogger 7 | FileCreateDir, %logdir% 8 | 9 | doublequote = `" 10 | 11 | getlog(logdir) { 12 | FormatTime, time, , yyyy-MM-dd-HH-mm-ss 13 | newlog = %logdir%\%time%.txt 14 | return %newlog% 15 | } 16 | 17 | keyevent(key) { 18 | global log 19 | FileAppend, %key%`n, *%log% 20 | ;previousnewline = 0 21 | } 22 | 23 | mouseevent(message) { 24 | global log 25 | WinGetActiveTitle, Title 26 | WinGet, ProcessName, ProcessName, A 27 | MouseGetPos, x, y, window, controln 28 | 29 | ; ASCII 31 octal 037 Unit Separator 30 | FileAppend, %A_Tab%{%message%}%A_Tab%%x%%A_Tab%%y%%A_Tab%%ProcessName%%A_Tab%%Title%%A_Tab%%controln%`n, *%log% 31 | } 32 | 33 | getwin() { 34 | global log 35 | FormatTime, time, , yyyy-MM-dd-HH-mm-ss 36 | WinGetActiveTitle, Title 37 | WinGet, win_proc, ProcessName, A 38 | WinGet, uniq_id, ID, A 39 | ; ASCII 30 octal 036 Record Separator 40 | if %uniq_id% 41 | FileAppend, %A_Tab%%time%%A_Tab%%uniq_id%%A_Tab%%win_proc%%A_Tab%%Title%`n, *%log% 42 | } 43 | 44 | make_menu() { 45 | Menu, TRAY, NoStandard 46 | Menu, TRAY, add, YOU ARE BEING LOGGED - help, help_handler 47 | Menu, TRAY, add, 48 | Menu, TRAY, add, Start new logfile, newlog_handler 49 | Menu, TRAY, add, About Keylogger, about_handler 50 | Menu, TRAY, add, Exit, exit_handler 51 | } 52 | 53 | log := getlog(logdir) 54 | make_menu() 55 | getwin() 56 | 57 | Loop { 58 | WinWaitNotActive, % "ahk_id " WinActive("A") 59 | getwin() 60 | } 61 | 62 | ~a::keyevent("a") 63 | ~#a::keyevent("a") 64 | ~!a::keyevent("a") 65 | ~^a::keyevent("a") 66 | ~b::keyevent("b") 67 | ~#b::keyevent("b") 68 | ~!b::keyevent("b") 69 | ~^b::keyevent("b") 70 | ~c::keyevent("c") 71 | ~#c::keyevent("c") 72 | ~!c::keyevent("c") 73 | ~^c::keyevent("c") 74 | ~d::keyevent("d") 75 | ~#d::keyevent("d") 76 | ~!d::keyevent("d") 77 | ~^d::keyevent("d") 78 | ~e::keyevent("e") 79 | ~#e::keyevent("e") 80 | ~!e::keyevent("e") 81 | ~^e::keyevent("e") 82 | ~f::keyevent("f") 83 | ~#f::keyevent("f") 84 | ~!f::keyevent("f") 85 | ~^f::keyevent("f") 86 | ~g::keyevent("g") 87 | ~#g::keyevent("g") 88 | ~!g::keyevent("g") 89 | ~^g::keyevent("g") 90 | ~h::keyevent("h") 91 | ~#h::keyevent("h") 92 | ~!h::keyevent("h") 93 | ~^h::keyevent("h") 94 | ~i::keyevent("i") 95 | ~#i::keyevent("i") 96 | ~!i::keyevent("i") 97 | ~^i::keyevent("i") 98 | ~j::keyevent("j") 99 | ~#j::keyevent("j") 100 | ~!j::keyevent("j") 101 | ~^j::keyevent("j") 102 | ~k::keyevent("k") 103 | ~#k::keyevent("k") 104 | ~!k::keyevent("k") 105 | ~^k::keyevent("k") 106 | ~l::keyevent("l") 107 | ~#l::keyevent("l") 108 | ~!l::keyevent("l") 109 | ~^l::keyevent("l") 110 | ~m::keyevent("m") 111 | ~#m::keyevent("m") 112 | ~!m::keyevent("m") 113 | ~^m::keyevent("m") 114 | ~n::keyevent("n") 115 | ~#n::keyevent("n") 116 | ~!n::keyevent("n") 117 | ~^n::keyevent("n") 118 | ~o::keyevent("o") 119 | ~#o::keyevent("o") 120 | ~!o::keyevent("o") 121 | ~^o::keyevent("o") 122 | ~p::keyevent("p") 123 | ~#p::keyevent("p") 124 | ~!p::keyevent("p") 125 | ~^p::keyevent("p") 126 | ~q::keyevent("q") 127 | ~#q::keyevent("q") 128 | ~!q::keyevent("q") 129 | ~^q::keyevent("q") 130 | ~r::keyevent("r") 131 | ~#r::keyevent("r") 132 | ~!r::keyevent("r") 133 | ~^r::keyevent("r") 134 | ~s::keyevent("s") 135 | ~#s::keyevent("s") 136 | ~!s::keyevent("s") 137 | ~^s::keyevent("s") 138 | ~t::keyevent("t") 139 | ~#t::keyevent("t") 140 | ~!t::keyevent("t") 141 | ~^t::keyevent("t") 142 | ~u::keyevent("u") 143 | ~#u::keyevent("u") 144 | ~!u::keyevent("u") 145 | ~^u::keyevent("u") 146 | ~v::keyevent("v") 147 | ~#v::keyevent("v") 148 | ~!v::keyevent("v") 149 | ~^v::keyevent("v") 150 | ~w::keyevent("w") 151 | ~#w::keyevent("w") 152 | ~!w::keyevent("w") 153 | ~^w::keyevent("w") 154 | ~x::keyevent("x") 155 | ~#x::keyevent("x") 156 | ~!x::keyevent("x") 157 | ~^x::keyevent("x") 158 | ~y::keyevent("y") 159 | ~#y::keyevent("y") 160 | ~!y::keyevent("y") 161 | ~^y::keyevent("y") 162 | ~z::keyevent("z") 163 | ~#z::keyevent("z") 164 | ~!z::keyevent("z") 165 | ~^z::keyevent("z") 166 | ~+A::keyevent("A") 167 | ~#+A::keyevent("A") 168 | ~!+A::keyevent("A") 169 | ~^+A::keyevent("A") 170 | ~+B::keyevent("B") 171 | ~#+B::keyevent("B") 172 | ~!+B::keyevent("B") 173 | ~^+B::keyevent("B") 174 | ~+C::keyevent("C") 175 | ~#+C::keyevent("C") 176 | ~!+C::keyevent("C") 177 | ~^+C::keyevent("C") 178 | ~+D::keyevent("D") 179 | ~#+D::keyevent("D") 180 | ~!+D::keyevent("D") 181 | ~^+D::keyevent("D") 182 | ~+E::keyevent("E") 183 | ~#+E::keyevent("E") 184 | ~!+E::keyevent("E") 185 | ~^+E::keyevent("E") 186 | ~+G::keyevent("G") 187 | ~#+G::keyevent("G") 188 | ~!+G::keyevent("G") 189 | ~^+G::keyevent("G") 190 | ~+H::keyevent("H") 191 | ~#+H::keyevent("H") 192 | ~!+H::keyevent("H") 193 | ~^+H::keyevent("H") 194 | ~+I::keyevent("I") 195 | ~#+I::keyevent("I") 196 | ~!+I::keyevent("I") 197 | ~^+I::keyevent("I") 198 | ~+J::keyevent("J") 199 | ~#+J::keyevent("J") 200 | ~!+J::keyevent("J") 201 | ~^+J::keyevent("J") 202 | ~+K::keyevent("K") 203 | ~#+K::keyevent("K") 204 | ~!+K::keyevent("K") 205 | ~^+K::keyevent("K") 206 | ~+L::keyevent("L") 207 | ~#+L::keyevent("L") 208 | ~!+L::keyevent("L") 209 | ~^+L::keyevent("L") 210 | ~+M::keyevent("M") 211 | ~#+M::keyevent("M") 212 | ~!+M::keyevent("M") 213 | ~^+M::keyevent("M") 214 | ~+N::keyevent("N") 215 | ~#+N::keyevent("N") 216 | ~!+N::keyevent("N") 217 | ~^+N::keyevent("N") 218 | ~+O::keyevent("O") 219 | ~#+O::keyevent("O") 220 | ~!+O::keyevent("O") 221 | ~^+O::keyevent("O") 222 | ~+P::keyevent("P") 223 | ~#+P::keyevent("P") 224 | ~!+P::keyevent("P") 225 | ~^+P::keyevent("P") 226 | ~+Q::keyevent("Q") 227 | ~#+Q::keyevent("Q") 228 | ~!+Q::keyevent("Q") 229 | ~^+Q::keyevent("Q") 230 | ~+R::keyevent("R") 231 | ~#+R::keyevent("R") 232 | ~!+R::keyevent("R") 233 | ~^+R::keyevent("R") 234 | ~+S::keyevent("S") 235 | ~#+S::keyevent("S") 236 | ~!+S::keyevent("S") 237 | ~^+S::keyevent("S") 238 | ~+T::keyevent("T") 239 | ~#+T::keyevent("T") 240 | ~!+T::keyevent("T") 241 | ~^+T::keyevent("T") 242 | ~+U::keyevent("U") 243 | ~#+U::keyevent("U") 244 | ~!+U::keyevent("U") 245 | ~^+U::keyevent("U") 246 | ~+V::keyevent("V") 247 | ~#+V::keyevent("V") 248 | ~!+V::keyevent("V") 249 | ~^+V::keyevent("V") 250 | ~+W::keyevent("W") 251 | ~#+W::keyevent("W") 252 | ~!+W::keyevent("W") 253 | ~^+W::keyevent("W") 254 | ~+X::keyevent("X") 255 | ~#+X::keyevent("X") 256 | ~!+X::keyevent("X") 257 | ~^+X::keyevent("X") 258 | ~+Y::keyevent("Y") 259 | ~#+Y::keyevent("Y") 260 | ~!+Y::keyevent("Y") 261 | ~^+Y::keyevent("Y") 262 | ~+Z::keyevent("Z") 263 | ~#+Z::keyevent("Z") 264 | ~!+Z::keyevent("Z") 265 | ~^+Z::keyevent("Z") 266 | ~`::keyevent("``") 267 | ~#`::keyevent("``") 268 | ~!`::keyevent("``") 269 | ~^`::keyevent("``") 270 | ~!::keyevent("{!}") 271 | ~#!::keyevent("{!}") 272 | ~!!::keyevent("{!}") 273 | ~^!::keyevent("{!}") 274 | ~@::keyevent("@") 275 | ~#@::keyevent("@") 276 | ~!@::keyevent("@") 277 | ~^@::keyevent("@") 278 | ~#::keyevent("{#}") 279 | ~##::keyevent("{#}") 280 | ~!#::keyevent("{#}") 281 | ~^#::keyevent("{#}") 282 | ~$::keyevent("$") 283 | ~#$::keyevent("$") 284 | ~!$::keyevent("$") 285 | ~^$::keyevent("$") 286 | ~^::keyevent("{^}") 287 | ~#^::keyevent("{^}") 288 | ~!^::keyevent("{^}") 289 | ~^^::keyevent("{^}") 290 | ~&::keyevent("&") 291 | ~#&::keyevent("&") 292 | ~!&::keyevent("&") 293 | ~^&::keyevent("&") 294 | ~*::keyevent("*") 295 | ~#*::keyevent("*") 296 | ~!*::keyevent("*") 297 | ~^*::keyevent("*") 298 | ~(::keyevent("(") 299 | ~#(::keyevent("(") 300 | ~!(::keyevent("(") 301 | ~^(::keyevent("(") 302 | ~)::keyevent(")") 303 | ~#)::keyevent(")") 304 | ~!)::keyevent(")") 305 | ~^)::keyevent(")") 306 | ~-::keyevent("-") 307 | ~#-::keyevent("-") 308 | ~!-::keyevent("-") 309 | ~^-::keyevent("-") 310 | ~_::keyevent("_") 311 | ~#_::keyevent("_") 312 | ~!_::keyevent("_") 313 | ~^_::keyevent("_") 314 | ~=::keyevent("=") 315 | ~#=::keyevent("=") 316 | ~!=::keyevent("=") 317 | ~^=::keyevent("=") 318 | ~+::keyevent("{+}") 319 | ~#+::keyevent("{+}") 320 | ~!+::keyevent("{+}") 321 | ~^+::keyevent("{+}") 322 | ~[::keyevent("[") 323 | ~#[::keyevent("[") 324 | ~![::keyevent("[") 325 | ~^[::keyevent("[") 326 | ~{::keyevent("{{}") 327 | ~#{::keyevent("{{}") 328 | ~!{::keyevent("{{}") 329 | ~^{::keyevent("{{}") 330 | ~]::keyevent("]") 331 | ~#]::keyevent("]") 332 | ~!]::keyevent("]") 333 | ~^]::keyevent("]") 334 | ~}::keyevent("{}}") 335 | ~#}::keyevent("{}}") 336 | ~!}::keyevent("{}}") 337 | ~^}::keyevent("{}}") 338 | ~\::keyevent("\") 339 | ~#\::keyevent("\") 340 | ~!\::keyevent("\") 341 | ~^\::keyevent("\") 342 | ~|::keyevent("|") 343 | ~#|::keyevent("|") 344 | ~!|::keyevent("|") 345 | ~^|::keyevent("|") 346 | ~+;::keyevent(":") 347 | ~#+;::keyevent(":") 348 | ~!+;::keyevent(":") 349 | ~^+;::keyevent(":") 350 | ~;::keyevent("`;") 351 | ~#;::keyevent("`;") 352 | ~!;::keyevent("`;") 353 | ~^;::keyevent("`;") 354 | ~SC028::keyevent("'") 355 | ~#SC028::keyevent("'") 356 | ~!SC028::keyevent("'") 357 | ~^SC028::keyevent("'") 358 | ~+SC028::keyevent(doublequote) 359 | ~#+SC028::keyevent(doublequote) 360 | ~!+SC028::keyevent(doublequote) 361 | ~^+SC028::keyevent(doublequote) 362 | ~,::keyevent(",") 363 | ~#,::keyevent(",") 364 | ~!,::keyevent(",") 365 | ~^,::keyevent(",") 366 | ~.::keyevent(".") 367 | ~#.::keyevent(".") 368 | ~!.::keyevent(".") 369 | ~^.::keyevent(".") 370 | ~<::keyevent("<") 371 | ~#<::keyevent("<") 372 | ~!<::keyevent("<") 373 | ~^<::keyevent("<") 374 | ~>::keyevent(">") 375 | ~#>::keyevent(">") 376 | ~!>::keyevent(">") 377 | ~^>::keyevent(">") 378 | ~/::keyevent("/") 379 | ~#/::keyevent("/") 380 | ~!/::keyevent("/") 381 | ~^/::keyevent("/") 382 | ~?::keyevent("?") 383 | ~#?::keyevent("?") 384 | ~!?::keyevent("?") 385 | ~^?::keyevent("?") 386 | ~1::keyevent("1") 387 | ~#1::keyevent("1") 388 | ~!1::keyevent("1") 389 | ~^1::keyevent("1") 390 | ~2::keyevent("2") 391 | ~#2::keyevent("2") 392 | ~!2::keyevent("2") 393 | ~^2::keyevent("2") 394 | ~3::keyevent("3") 395 | ~#3::keyevent("3") 396 | ~!3::keyevent("3") 397 | ~^3::keyevent("3") 398 | ~4::keyevent("4") 399 | ~#4::keyevent("4") 400 | ~!4::keyevent("4") 401 | ~^4::keyevent("4") 402 | ~5::keyevent("5") 403 | ~#5::keyevent("5") 404 | ~!5::keyevent("5") 405 | ~^5::keyevent("5") 406 | ~6::keyevent("6") 407 | ~#6::keyevent("6") 408 | ~!6::keyevent("6") 409 | ~^6::keyevent("6") 410 | ~7::keyevent("7") 411 | ~#7::keyevent("7") 412 | ~!7::keyevent("7") 413 | ~^7::keyevent("7") 414 | ~8::keyevent("8") 415 | ~#8::keyevent("8") 416 | ~!8::keyevent("8") 417 | ~^8::keyevent("8") 418 | ~9::keyevent("9") 419 | ~#9::keyevent("9") 420 | ~!9::keyevent("9") 421 | ~^9::keyevent("9") 422 | ~0::keyevent("0") 423 | ~#0::keyevent("0") 424 | ~!0::keyevent("0") 425 | ~^0::keyevent("0") 426 | ~Space::keyevent(A_Space) 427 | ~#Space::keyevent(A_Space) 428 | ~!Space::keyevent(A_Space) 429 | ~^Space::keyevent(A_Space) 430 | ~Tab::keyevent("{Tab}") 431 | ~#Tab::keyevent("{Tab}") 432 | ~!Tab::keyevent("{Tab}") 433 | ~^Tab::keyevent("{Tab}") 434 | ~Enter::keyevent("{Enter}") 435 | ~#Enter::keyevent("{Enter}") 436 | ~!Enter::keyevent("{Enter}") 437 | ~^Enter::keyevent("{Enter}") 438 | ~Esc::keyevent("{Esc}") 439 | ~#Esc::keyevent("{Esc}") 440 | ~!Esc::keyevent("{Esc}") 441 | ~^Esc::keyevent("{Esc}") 442 | ~SC00E::keyevent("{BS}") 443 | ~#SC00E::keyevent("{BS}") 444 | ~!SC00E::keyevent("{BS}") 445 | ~^SC00E::keyevent("{BS}") 446 | ~Pause::keyevent("{Pause}") 447 | ~#Pause::keyevent("{Pause}") 448 | ~!Pause::keyevent("{Pause}") 449 | ~^Pause::keyevent("{Pause}") 450 | ~ScrollLock::keyevent("{ScrollLock}") 451 | ~#ScrollLock::keyevent("{ScrollLock}") 452 | ~!ScrollLock::keyevent("{ScrollLock}") 453 | ~^ScrollLock::keyevent("{ScrollLock}") 454 | ~Delete::keyevent("{Delete}") 455 | ~#Delete::keyevent("{Delete}") 456 | ~!Delete::keyevent("{Delete}") 457 | ~^Delete::keyevent("{Delete}") 458 | ~Insert::keyevent("{Insert}") 459 | ~#Insert::keyevent("{Insert}") 460 | ~!Insert::keyevent("{Insert}") 461 | ~^Insert::keyevent("{Insert}") 462 | ~Home::keyevent("{Home}") 463 | ~#Home::keyevent("{Home}") 464 | ~!Home::keyevent("{Home}") 465 | ~^Home::keyevent("{Home}") 466 | ~End::keyevent("{End}") 467 | ~#End::keyevent("{End}") 468 | ~!End::keyevent("{End}") 469 | ~^End::keyevent("{End}") 470 | ~PgUp::keyevent("{PgUp}") 471 | ~#PgUp::keyevent("{PgUp}") 472 | ~!PgUp::keyevent("{PgUp}") 473 | ~^PgUp::keyevent("{PgUp}") 474 | ~PgDn::keyevent("{PgDn}") 475 | ~#PgDn::keyevent("{PgDn}") 476 | ~!PgDn::keyevent("{PgDn}") 477 | ~^PgDn::keyevent("{PgDn}") 478 | ~Up::keyevent("{Up}") 479 | ~#Up::keyevent("{Up}") 480 | ~!Up::keyevent("{Up}") 481 | ~^Up::keyevent("{Up}") 482 | ~Down::keyevent("{Down}") 483 | ~#Down::keyevent("{Down}") 484 | ~!Down::keyevent("{Down}") 485 | ~^Down::keyevent("{Down}") 486 | ~Left::keyevent("{Left}") 487 | ~#Left::keyevent("{Left}") 488 | ~!Left::keyevent("{Left}") 489 | ~^Left::keyevent("{Left}") 490 | ~Right::keyevent("{Right}") 491 | ~#Right::keyevent("{Right}") 492 | ~!Right::keyevent("{Right}") 493 | ~^Right::keyevent("{Right}") 494 | ~CapsLock::keyevent("{CapsLock}") 495 | ~#CapsLock::keyevent("{CapsLock}") 496 | ~!CapsLock::keyevent("{CapsLock}") 497 | ~^CapsLock::keyevent("{CapsLock}") 498 | ~NumLock::keyevent("{NumLock}") 499 | ~#NumLock::keyevent("{NumLock}") 500 | ~!NumLock::keyevent("{NumLock}") 501 | ~^NumLock::keyevent("{NumLock}") 502 | ~Numpad0::keyevent("{Numpad0}") 503 | ~#Numpad0::keyevent("{Numpad0}") 504 | ~!Numpad0::keyevent("{Numpad0}") 505 | ~^Numpad0::keyevent("{Numpad0}") 506 | ~Numpad1::keyevent("{Numpad1}") 507 | ~#Numpad1::keyevent("{Numpad1}") 508 | ~!Numpad1::keyevent("{Numpad1}") 509 | ~^Numpad1::keyevent("{Numpad1}") 510 | ~Numpad2::keyevent("{Numpad2}") 511 | ~#Numpad2::keyevent("{Numpad2}") 512 | ~!Numpad2::keyevent("{Numpad2}") 513 | ~^Numpad2::keyevent("{Numpad2}") 514 | ~Numpad3::keyevent("{Numpad3}") 515 | ~#Numpad3::keyevent("{Numpad3}") 516 | ~!Numpad3::keyevent("{Numpad3}") 517 | ~^Numpad3::keyevent("{Numpad3}") 518 | ~Numpad4::keyevent("{Numpad4}") 519 | ~#Numpad4::keyevent("{Numpad4}") 520 | ~!Numpad4::keyevent("{Numpad4}") 521 | ~^Numpad4::keyevent("{Numpad4}") 522 | ~Numpad5::keyevent("{Numpad5}") 523 | ~#Numpad5::keyevent("{Numpad5}") 524 | ~!Numpad5::keyevent("{Numpad5}") 525 | ~^Numpad5::keyevent("{Numpad5}") 526 | ~Numpad6::keyevent("{Numpad6}") 527 | ~#Numpad6::keyevent("{Numpad6}") 528 | ~!Numpad6::keyevent("{Numpad6}") 529 | ~^Numpad6::keyevent("{Numpad6}") 530 | ~Numpad7::keyevent("{Numpad7}") 531 | ~#Numpad7::keyevent("{Numpad7}") 532 | ~!Numpad7::keyevent("{Numpad7}") 533 | ~^Numpad7::keyevent("{Numpad7}") 534 | ~Numpad8::keyevent("{Numpad8}") 535 | ~#Numpad8::keyevent("{Numpad8}") 536 | ~!Numpad8::keyevent("{Numpad8}") 537 | ~^Numpad8::keyevent("{Numpad8}") 538 | ~Numpad9::keyevent("{Numpad9}") 539 | ~#Numpad9::keyevent("{Numpad9}") 540 | ~!Numpad9::keyevent("{Numpad9}") 541 | ~^Numpad9::keyevent("{Numpad9}") 542 | ~NumpadAdd::keyevent("{NumpadAdd}") 543 | ~#NumpadAdd::keyevent("{NumpadAdd}") 544 | ~!NumpadAdd::keyevent("{NumpadAdd}") 545 | ~^NumpadAdd::keyevent("{NumpadAdd}") 546 | ~NumpadClear::keyevent("{NumpadClear}") 547 | ~#NumpadClear::keyevent("{NumpadClear}") 548 | ~!NumpadClear::keyevent("{NumpadClear}") 549 | ~^NumpadClear::keyevent("{NumpadClear}") 550 | ~NumpadDel::keyevent("{NumpadDel}") 551 | ~#NumpadDel::keyevent("{NumpadDel}") 552 | ~!NumpadDel::keyevent("{NumpadDel}") 553 | ~^NumpadDel::keyevent("{NumpadDel}") 554 | ~NumpadDiv::keyevent("{NumpadDiv}") 555 | ~#NumpadDiv::keyevent("{NumpadDiv}") 556 | ~!NumpadDiv::keyevent("{NumpadDiv}") 557 | ~^NumpadDiv::keyevent("{NumpadDiv}") 558 | ~NumpadDot::keyevent("{NumpadDot}") 559 | ~#NumpadDot::keyevent("{NumpadDot}") 560 | ~!NumpadDot::keyevent("{NumpadDot}") 561 | ~^NumpadDot::keyevent("{NumpadDot}") 562 | ~NumpadDown::keyevent("{NumpadDown}") 563 | ~#NumpadDown::keyevent("{NumpadDown}") 564 | ~!NumpadDown::keyevent("{NumpadDown}") 565 | ~^NumpadDown::keyevent("{NumpadDown}") 566 | ~NumpadEnd::keyevent("{NumpadEnd}") 567 | ~#NumpadEnd::keyevent("{NumpadEnd}") 568 | ~!NumpadEnd::keyevent("{NumpadEnd}") 569 | ~^NumpadEnd::keyevent("{NumpadEnd}") 570 | ~NumpadEnter::keyevent("{NumpadEnter}") 571 | ~#NumpadEnter::keyevent("{NumpadEnter}") 572 | ~!NumpadEnter::keyevent("{NumpadEnter}") 573 | ~^NumpadEnter::keyevent("{NumpadEnter}") 574 | ~NumpadHome::keyevent("{NumpadHome}") 575 | ~#NumpadHome::keyevent("{NumpadHome}") 576 | ~!NumpadHome::keyevent("{NumpadHome}") 577 | ~^NumpadHome::keyevent("{NumpadHome}") 578 | ~NumpadIns::keyevent("{NumpadIns}") 579 | ~#NumpadIns::keyevent("{NumpadIns}") 580 | ~!NumpadIns::keyevent("{NumpadIns}") 581 | ~^NumpadIns::keyevent("{NumpadIns}") 582 | ~NumpadLeft::keyevent("{NumpadLeft}") 583 | ~#NumpadLeft::keyevent("{NumpadLeft}") 584 | ~!NumpadLeft::keyevent("{NumpadLeft}") 585 | ~^NumpadLeft::keyevent("{NumpadLeft}") 586 | ~NumpadMult::keyevent("{NumpadMult}") 587 | ~#NumpadMult::keyevent("{NumpadMult}") 588 | ~!NumpadMult::keyevent("{NumpadMult}") 589 | ~^NumpadMult::keyevent("{NumpadMult}") 590 | ~NumpadPgDn::keyevent("{NumpadPgDn}") 591 | ~#NumpadPgDn::keyevent("{NumpadPgDn}") 592 | ~!NumpadPgDn::keyevent("{NumpadPgDn}") 593 | ~^NumpadPgDn::keyevent("{NumpadPgDn}") 594 | ~NumpadPgUp::keyevent("{NumpadPgUp}") 595 | ~#NumpadPgUp::keyevent("{NumpadPgUp}") 596 | ~!NumpadPgUp::keyevent("{NumpadPgUp}") 597 | ~^NumpadPgUp::keyevent("{NumpadPgUp}") 598 | ~NumpadRight::keyevent("{NumpadRight}") 599 | ~#NumpadRight::keyevent("{NumpadRight}") 600 | ~!NumpadRight::keyevent("{NumpadRight}") 601 | ~^NumpadRight::keyevent("{NumpadRight}") 602 | ~NumpadSub::keyevent("{NumpadSub}") 603 | ~#NumpadSub::keyevent("{NumpadSub}") 604 | ~!NumpadSub::keyevent("{NumpadSub}") 605 | ~^NumpadSub::keyevent("{NumpadSub}") 606 | ~NumpadUp::keyevent("{NumpadUp}") 607 | ~#NumpadUp::keyevent("{NumpadUp}") 608 | ~!NumpadUp::keyevent("{NumpadUp}") 609 | ~^NumpadUp::keyevent("{NumpadUp}") 610 | ~F1::keyevent("{F1}") 611 | ~#F1::keyevent("{F1}") 612 | ~!F1::keyevent("{F1}") 613 | ~^F1::keyevent("{F1}") 614 | ~F2::keyevent("{F2}") 615 | ~#F2::keyevent("{F2}") 616 | ~!F2::keyevent("{F2}") 617 | ~^F2::keyevent("{F2}") 618 | ~F3::keyevent("{F3}") 619 | ~#F3::keyevent("{F3}") 620 | ~!F3::keyevent("{F3}") 621 | ~^F3::keyevent("{F3}") 622 | ~F4::keyevent("{F4}") 623 | ~#F4::keyevent("{F4}") 624 | ~!F4::keyevent("{F4}") 625 | ~^F4::keyevent("{F4}") 626 | ~F5::keyevent("{F5}") 627 | ~#F5::keyevent("{F5}") 628 | ~!F5::keyevent("{F5}") 629 | ~^F5::keyevent("{F5}") 630 | ~F6::keyevent("{F6}") 631 | ~#F6::keyevent("{F6}") 632 | ~!F6::keyevent("{F6}") 633 | ~^F6::keyevent("{F6}") 634 | ~F7::keyevent("{F7}") 635 | ~#F7::keyevent("{F7}") 636 | ~!F7::keyevent("{F7}") 637 | ~^F7::keyevent("{F7}") 638 | ~F8::keyevent("{F8}") 639 | ~#F8::keyevent("{F8}") 640 | ~!F8::keyevent("{F8}") 641 | ~^F8::keyevent("{F8}") 642 | ~F9::keyevent("{F9}") 643 | ~#F9::keyevent("{F9}") 644 | ~!F9::keyevent("{F9}") 645 | ~^F9::keyevent("{F9}") 646 | ~F10::keyevent("{F10}") 647 | ~#F10::keyevent("{F10}") 648 | ~!F10::keyevent("{F10}") 649 | ~^F10::keyevent("{F10}") 650 | ~F11::keyevent("{F11}") 651 | ~#F11::keyevent("{F11}") 652 | ~!F11::keyevent("{F11}") 653 | ~^F11::keyevent("{F11}") 654 | ~F12::keyevent("{F12}") 655 | ~#F12::keyevent("{F12}") 656 | ~!F12::keyevent("{F12}") 657 | ~^F12::keyevent("{F12}") 658 | ~F13::keyevent("{F13}") 659 | ~#F13::keyevent("{F13}") 660 | ~!F13::keyevent("{F13}") 661 | ~^F13::keyevent("{F13}") 662 | ~F14::keyevent("{F14}") 663 | ~#F14::keyevent("{F14}") 664 | ~!F14::keyevent("{F14}") 665 | ~^F14::keyevent("{F14}") 666 | ~F15::keyevent("{F15}") 667 | ~#F15::keyevent("{F15}") 668 | ~!F15::keyevent("{F15}") 669 | ~^F15::keyevent("{F15}") 670 | ~F16::keyevent("{F16}") 671 | ~#F16::keyevent("{F16}") 672 | ~!F16::keyevent("{F16}") 673 | ~^F16::keyevent("{F16}") 674 | ~F17::keyevent("{F17}") 675 | ~#F17::keyevent("{F17}") 676 | ~!F17::keyevent("{F17}") 677 | ~^F17::keyevent("{F17}") 678 | ~F18::keyevent("{F18}") 679 | ~#F18::keyevent("{F18}") 680 | ~!F18::keyevent("{F18}") 681 | ~^F18::keyevent("{F18}") 682 | ~F19::keyevent("{F19}") 683 | ~#F19::keyevent("{F19}") 684 | ~!F19::keyevent("{F19}") 685 | ~^F19::keyevent("{F19}") 686 | ~F20::keyevent("{F20}") 687 | ~#F20::keyevent("{F20}") 688 | ~!F20::keyevent("{F20}") 689 | ~^F20::keyevent("{F20}") 690 | ~F21::keyevent("{F21}") 691 | ~#F21::keyevent("{F21}") 692 | ~!F21::keyevent("{F21}") 693 | ~^F21::keyevent("{F21}") 694 | ~F22::keyevent("{F22}") 695 | ~#F22::keyevent("{F22}") 696 | ~!F22::keyevent("{F22}") 697 | ~^F22::keyevent("{F22}") 698 | ~F23::keyevent("{F23}") 699 | ~#F23::keyevent("{F23}") 700 | ~!F23::keyevent("{F23}") 701 | ~^F23::keyevent("{F23}") 702 | ~F24::keyevent("{F24}") 703 | ~#F24::keyevent("{F24}") 704 | ~!F24::keyevent("{F24}") 705 | ~^F24::keyevent("{F24}") 706 | ~AppsKey::keyevent("{AppsKey}") 707 | ~#AppsKey::keyevent("{AppsKey}") 708 | ~!AppsKey::keyevent("{AppsKey}") 709 | ~^AppsKey::keyevent("{AppsKey}") 710 | 711 | ~PrintScreen::keyevent("{PrintScreen}") 712 | ~#PrintScreen::keyevent("{PrintScreen}") 713 | ~!PrintScreen::keyevent("{PrintScreen}") 714 | ~^PrintScreen::keyevent("{PrintScreen}") 715 | 716 | ~LWin::keyevent("{LWin}") 717 | ~RWin::keyevent("{RWin}") 718 | ~LControl::keyevent("{LControl}") 719 | ~RControl::keyevent("{RControl}") 720 | ~LShift::keyevent("{LShift}") 721 | ~RShift::keyevent("{RShift}") 722 | ~LAlt::keyevent("{LAlt}") 723 | ~RAlt::keyevent("{RAlt}") 724 | 725 | ~LButton::mouseevent("LButton") 726 | ~#LButton::mouseevent("LButton") 727 | ~!LButton::mouseevent("LButton") 728 | ~^LButton::mouseevent("LButton") 729 | ~MButton::mouseevent("MButton") 730 | ~#MButton::mouseevent("MButton") 731 | ~!MButton::mouseevent("MButton") 732 | ~^MButton::mouseevent("MButton") 733 | ~RButton::mouseevent("RButton") 734 | ~#RButton::mouseevent("RButton") 735 | ~!RButton::mouseevent("RButton") 736 | ~^RButton::mouseevent("RButton") 737 | ~WheelDown::mouseevent("WheelDown") 738 | ~#WheelDown::mouseevent("WheelDown") 739 | ~!WheelDown::mouseevent("WheelDown") 740 | ~^WheelDown::mouseevent("WheelDown") 741 | ~WheelUp::mouseevent("WheelUp") 742 | ~#WheelUp::mouseevent("WheelUp") 743 | ~!WheelUp::mouseevent("WheelUp") 744 | ~^WheelUp::mouseevent("WheelUp") 745 | ~WheelLeft::mouseevent("WheelLeft") 746 | ~#WheelLeft::mouseevent("WheelLeft") 747 | ~!WheelLeft::mouseevent("WheelLeft") 748 | ~^WheelLeft::mouseevent("WheelLeft") 749 | ~WheelRight::mouseevent("WheelRight") 750 | ~#WheelRight::mouseevent("WheelRight") 751 | ~!WheelRight::mouseevent("WheelRight") 752 | ~^WheelRight::mouseevent("WheelRight") 753 | 754 | newlog_handler: 755 | log := getlog(logdir) 756 | return 757 | 758 | about_handler: 759 | aboutmsg = 760 | ( 761 | keylogger Copyright 2013 Noah Birnel (nbirnel at gmail dot com) 762 | This program is not intended for spying. 763 | You are licensed to use it for capturing your own keystrokes. 764 | ) 765 | MsgBox %aboutmsg% 766 | return 767 | 768 | exit_handler: 769 | ExitApp 770 | return 771 | 772 | help_handler: 773 | helpmsg = 774 | ( 775 | All of your mouse clicks and key presses are being logged to %log% 776 | ) 777 | MsgBox %helpmsg% 778 | return 779 | -------------------------------------------------------------------------------- /inspiration/Gdip.ahk: -------------------------------------------------------------------------------- 1 | ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11 2 | ; 3 | ;##################################################################################### 4 | ;##################################################################################### 5 | ; STATUS ENUMERATION 6 | ; Return values for functions specified to have status enumerated return type 7 | ;##################################################################################### 8 | ; 9 | ; Ok = = 0 10 | ; GenericError = 1 11 | ; InvalidParameter = 2 12 | ; OutOfMemory = 3 13 | ; ObjectBusy = 4 14 | ; InsufficientBuffer = 5 15 | ; NotImplemented = 6 16 | ; Win32Error = 7 17 | ; WrongState = 8 18 | ; Aborted = 9 19 | ; FileNotFound = 10 20 | ; ValueOverflow = 11 21 | ; AccessDenied = 12 22 | ; UnknownImageFormat = 13 23 | ; FontFamilyNotFound = 14 24 | ; FontStyleNotFound = 15 25 | ; NotTrueTypeFont = 16 26 | ; UnsupportedGdiplusVersion = 17 27 | ; GdiplusNotInitialized = 18 28 | ; PropertyNotFound = 19 29 | ; PropertyNotSupported = 20 30 | ; ProfileNotFound = 21 31 | ; 32 | ;##################################################################################### 33 | ;##################################################################################### 34 | ; FUNCTIONS 35 | ;##################################################################################### 36 | ; 37 | ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) 38 | ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") 39 | ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="") 40 | ; SetImage(hwnd, hBitmap) 41 | ; Gdip_BitmapFromScreen(Screen=0, Raster="") 42 | ; CreateRectF(ByRef RectF, x, y, w, h) 43 | ; CreateSizeF(ByRef SizeF, w, h) 44 | ; CreateDIBSection 45 | ; 46 | ;##################################################################################### 47 | 48 | ; Function: UpdateLayeredWindow 49 | ; Description: Updates a layered window with the handle to the DC of a gdi bitmap 50 | ; 51 | ; hwnd Handle of the layered window to update 52 | ; hdc Handle to the DC of the GDI bitmap to update the window with 53 | ; Layeredx x position to place the window 54 | ; Layeredy y position to place the window 55 | ; Layeredw Width of the window 56 | ; Layeredh Height of the window 57 | ; Alpha Default = 255 : The transparency (0-255) to set the window transparency 58 | ; 59 | ; return If the function succeeds, the return value is nonzero 60 | ; 61 | ; notes If x or y omitted, then layered window will use its current coordinates 62 | ; If w or h omitted then current width and height will be used 63 | 64 | UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) 65 | { 66 | if ((x != "") && (y != "")) 67 | VarSetCapacity(pt, 8), NumPut(x, pt, 0), NumPut(y, pt, 4) 68 | 69 | if (w = "") ||(h = "") 70 | WinGetPos,,, w, h, ahk_id %hwnd% 71 | 72 | return DllCall("UpdateLayeredWindow", "uint", hwnd, "uint", 0, "uint", ((x = "") && (y = "")) ? 0 : &pt 73 | , "int64*", w|h<<32, "uint", hdc, "int64*", 0, "uint", 0, "uint*", Alpha<<16|1<<24, "uint", 2) 74 | } 75 | 76 | ;##################################################################################### 77 | 78 | ; Function BitBlt 79 | ; Description The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle 80 | ; of pixels from the specified source device context into a destination device context. 81 | ; 82 | ; dDC handle to destination DC 83 | ; dx x-coord of destination upper-left corner 84 | ; dy y-coord of destination upper-left corner 85 | ; dw width of the area to copy 86 | ; dh height of the area to copy 87 | ; sDC handle to source DC 88 | ; sx x-coordinate of source upper-left corner 89 | ; sy y-coordinate of source upper-left corner 90 | ; Raster raster operation code 91 | ; 92 | ; return If the function succeeds, the return value is nonzero 93 | ; 94 | ; notes If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle 95 | ; 96 | ; BLACKNESS = 0x00000042 97 | ; NOTSRCERASE = 0x001100A6 98 | ; NOTSRCCOPY = 0x00330008 99 | ; SRCERASE = 0x00440328 100 | ; DSTINVERT = 0x00550009 101 | ; PATINVERT = 0x005A0049 102 | ; SRCINVERT = 0x00660046 103 | ; SRCAND = 0x008800C6 104 | ; MERGEPAINT = 0x00BB0226 105 | ; MERGECOPY = 0x00C000CA 106 | ; SRCCOPY = 0x00CC0020 107 | ; SRCPAINT = 0x00EE0086 108 | ; PATCOPY = 0x00F00021 109 | ; PATPAINT = 0x00FB0A09 110 | ; WHITENESS = 0x00FF0062 111 | ; CAPTUREBLT = 0x40000000 112 | ; NOMIRRORBITMAP = 0x80000000 113 | 114 | BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") 115 | { 116 | return DllCall("gdi32\BitBlt", "uint", dDC, "int", dx, "int", dy, "int", dw, "int", dh 117 | , "uint", sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020) 118 | } 119 | 120 | ;##################################################################################### 121 | 122 | ; Function StretchBlt 123 | ; Description The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, 124 | ; stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. 125 | ; The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context. 126 | ; 127 | ; ddc handle to destination DC 128 | ; dx x-coord of destination upper-left corner 129 | ; dy y-coord of destination upper-left corner 130 | ; dw width of destination rectangle 131 | ; dh height of destination rectangle 132 | ; sdc handle to source DC 133 | ; sx x-coordinate of source upper-left corner 134 | ; sy y-coordinate of source upper-left corner 135 | ; sw width of source rectangle 136 | ; sh height of source rectangle 137 | ; Raster raster operation code 138 | ; 139 | ; return If the function succeeds, the return value is nonzero 140 | ; 141 | ; notes If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt 142 | 143 | StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="") 144 | { 145 | return DllCall("gdi32\StretchBlt", "uint", ddc, "int", dx, "int", dy, "int", dw, "int", dh 146 | , "uint", sdc, "int", sx, "int", sy, "int", sw, "int", sh, "uint", Raster ? Raster : 0x00CC0020) 147 | } 148 | 149 | ;##################################################################################### 150 | 151 | ; Function SetStretchBltMode 152 | ; Description The SetStretchBltMode function sets the bitmap stretching mode in the specified device context 153 | ; 154 | ; hdc handle to the DC 155 | ; iStretchMode The stretching mode, describing how the target will be stretched 156 | ; 157 | ; return If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0 158 | ; 159 | ; STRETCH_ANDSCANS = 0x01 160 | ; STRETCH_ORSCANS = 0x02 161 | ; STRETCH_DELETESCANS = 0x03 162 | ; STRETCH_HALFTONE = 0x04 163 | 164 | SetStretchBltMode(hdc, iStretchMode=4) 165 | { 166 | return DllCall("gdi32\SetStretchBltMode", "uint", hdc, "int", iStretchMode) 167 | } 168 | 169 | ;##################################################################################### 170 | 171 | ; Function SetImage 172 | ; Description Associates a new image with a static control 173 | ; 174 | ; hwnd handle of the control to update 175 | ; hBitmap a gdi bitmap to associate the static control with 176 | ; 177 | ; return If the function succeeds, the return value is nonzero 178 | 179 | SetImage(hwnd, hBitmap) 180 | { 181 | SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd% 182 | E := ErrorLevel 183 | DeleteObject(E) 184 | return E 185 | } 186 | 187 | ;##################################################################################### 188 | 189 | ; Function SetSysColorToControl 190 | ; Description Sets a solid colour to a control 191 | ; 192 | ; hwnd handle of the control to update 193 | ; SysColor A system colour to set to the control 194 | ; 195 | ; return If the function succeeds, the return value is zero 196 | ; 197 | ; notes A control must have the 0xE style set to it so it is recognised as a bitmap 198 | ; By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control 199 | ; 200 | ; COLOR_3DDKSHADOW = 21 201 | ; COLOR_3DFACE = 15 202 | ; COLOR_3DHIGHLIGHT = 20 203 | ; COLOR_3DHILIGHT = 20 204 | ; COLOR_3DLIGHT = 22 205 | ; COLOR_3DSHADOW = 16 206 | ; COLOR_ACTIVEBORDER = 10 207 | ; COLOR_ACTIVECAPTION = 2 208 | ; COLOR_APPWORKSPACE = 12 209 | ; COLOR_BACKGROUND = 1 210 | ; COLOR_BTNFACE = 15 211 | ; COLOR_BTNHIGHLIGHT = 20 212 | ; COLOR_BTNHILIGHT = 20 213 | ; COLOR_BTNSHADOW = 16 214 | ; COLOR_BTNTEXT = 18 215 | ; COLOR_CAPTIONTEXT = 9 216 | ; COLOR_DESKTOP = 1 217 | ; COLOR_GRADIENTACTIVECAPTION = 27 218 | ; COLOR_GRADIENTINACTIVECAPTION = 28 219 | ; COLOR_GRAYTEXT = 17 220 | ; COLOR_HIGHLIGHT = 13 221 | ; COLOR_HIGHLIGHTTEXT = 14 222 | ; COLOR_HOTLIGHT = 26 223 | ; COLOR_INACTIVEBORDER = 11 224 | ; COLOR_INACTIVECAPTION = 3 225 | ; COLOR_INACTIVECAPTIONTEXT = 19 226 | ; COLOR_INFOBK = 24 227 | ; COLOR_INFOTEXT = 23 228 | ; COLOR_MENU = 4 229 | ; COLOR_MENUHILIGHT = 29 230 | ; COLOR_MENUBAR = 30 231 | ; COLOR_MENUTEXT = 7 232 | ; COLOR_SCROLLBAR = 0 233 | ; COLOR_WINDOW = 5 234 | ; COLOR_WINDOWFRAME = 6 235 | ; COLOR_WINDOWTEXT = 8 236 | 237 | SetSysColorToControl(hwnd, SysColor=15) 238 | { 239 | WinGetPos,,, w, h, ahk_id %hwnd% 240 | bc := DllCall("GetSysColor", "Int", SysColor) 241 | pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16)) 242 | pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap) 243 | Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h) 244 | hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) 245 | SetImage(hwnd, hBitmap) 246 | Gdip_DeleteBrush(pBrushClear) 247 | Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap) 248 | return 0 249 | } 250 | 251 | ;##################################################################################### 252 | 253 | ; Function Gdip_BitmapFromScreen 254 | ; Description Gets a gdi+ bitmap from the screen 255 | ; 256 | ; Screen 0 = All screens 257 | ; Any numerical value = Just that screen 258 | ; x|y|w|h = Take specific coordinates with a width and height 259 | ; Raster raster operation code 260 | ; 261 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 262 | ; -1: one or more of x,y,w,h not passed properly 263 | ; 264 | ; notes If no raster operation is specified, then SRCCOPY is used to the returned bitmap 265 | 266 | Gdip_BitmapFromScreen(Screen=0, Raster="") 267 | { 268 | if (Screen = 0) 269 | { 270 | Sysget, x, 76 271 | Sysget, y, 77 272 | Sysget, w, 78 273 | Sysget, h, 79 274 | } 275 | else if (SubStr(Screen, 1, 5) = "hwnd:") 276 | { 277 | Screen := SubStr(Screen, 6) 278 | if !WinExist( "ahk_id " Screen) 279 | return -2 280 | WinGetPos,,, w, h, ahk_id %Screen% 281 | x := y := 0 282 | hhdc := GetDCEx(Screen, 3) 283 | } 284 | else if (Screen&1 != "") 285 | { 286 | Sysget, M, Monitor, %Screen% 287 | x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop 288 | } 289 | else 290 | { 291 | StringSplit, S, Screen, | 292 | x := S1, y := S2, w := S3, h := S4 293 | } 294 | 295 | if (x = "") || (y = "") || (w = "") || (h = "") 296 | return -1 297 | 298 | chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC() 299 | BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster) 300 | ReleaseDC(hhdc) 301 | 302 | pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) 303 | SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc) 304 | return pBitmap 305 | } 306 | 307 | ;##################################################################################### 308 | 309 | ; Function Gdip_BitmapFromHWND 310 | ; Description Uses PrintWindow to get a handle to the specified window and return a bitmap from it 311 | ; 312 | ; hwnd handle to the window to get a bitmap from 313 | ; 314 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 315 | ; 316 | ; notes Window must not be not minimised in order to get a handle to it's client area 317 | 318 | Gdip_BitmapFromHWND(hwnd) 319 | { 320 | WinGetPos,,, Width, Height, ahk_id %hwnd% 321 | hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) 322 | PrintWindow(hwnd, hdc) 323 | pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) 324 | SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) 325 | return pBitmap 326 | } 327 | 328 | ;##################################################################################### 329 | 330 | ; Function CreateRectF 331 | ; Description Creates a RectF object, containing a the coordinates and dimensions of a rectangle 332 | ; 333 | ; RectF Name to call the RectF object 334 | ; x x-coordinate of the upper left corner of the rectangle 335 | ; y y-coordinate of the upper left corner of the rectangle 336 | ; w Width of the rectangle 337 | ; h Height of the rectangle 338 | ; 339 | ; return No return value 340 | 341 | CreateRectF(ByRef RectF, x, y, w, h) 342 | { 343 | VarSetCapacity(RectF, 16) 344 | NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float") 345 | } 346 | 347 | ;##################################################################################### 348 | 349 | ; Function CreateRect 350 | ; Description Creates a Rect object, containing a the coordinates and dimensions of a rectangle 351 | ; 352 | ; RectF Name to call the RectF object 353 | ; x x-coordinate of the upper left corner of the rectangle 354 | ; y y-coordinate of the upper left corner of the rectangle 355 | ; w Width of the rectangle 356 | ; h Height of the rectangle 357 | ; 358 | ; return No return value 359 | 360 | CreateRect(ByRef Rect, x, y, w, h) 361 | { 362 | VarSetCapacity(Rect, 16) 363 | NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint") 364 | } 365 | ;##################################################################################### 366 | 367 | ; Function CreateSizeF 368 | ; Description Creates a SizeF object, containing an 2 values 369 | ; 370 | ; SizeF Name to call the SizeF object 371 | ; w w-value for the SizeF object 372 | ; h h-value for the SizeF object 373 | ; 374 | ; return No Return value 375 | 376 | CreateSizeF(ByRef SizeF, w, h) 377 | { 378 | VarSetCapacity(SizeF, 8) 379 | NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float") 380 | } 381 | ;##################################################################################### 382 | 383 | ; Function CreatePointF 384 | ; Description Creates a SizeF object, containing an 2 values 385 | ; 386 | ; SizeF Name to call the SizeF object 387 | ; w w-value for the SizeF object 388 | ; h h-value for the SizeF object 389 | ; 390 | ; return No Return value 391 | 392 | CreatePointF(ByRef PointF, x, y) 393 | { 394 | VarSetCapacity(PointF, 8) 395 | NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float") 396 | } 397 | ;##################################################################################### 398 | 399 | ; Function CreateDIBSection 400 | ; Description The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly 401 | ; 402 | ; w width of the bitmap to create 403 | ; h height of the bitmap to create 404 | ; hdc a handle to the device context to use the palette from 405 | ; bpp bits per pixel (32 = ARGB) 406 | ; ppvBits A pointer to a variable that receives a pointer to the location of the DIB bit values 407 | ; 408 | ; return returns a DIB. A gdi bitmap 409 | ; 410 | ; notes ppvBits will receive the location of the pixels in the DIB 411 | 412 | CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0) 413 | { 414 | hdc2 := hdc ? hdc : GetDC() 415 | VarSetCapacity(bi, 40, 0) 416 | NumPut(w, bi, 4), NumPut(h, bi, 8), NumPut(40, bi, 0), NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16), NumPut(bpp, bi, 14, "ushort") 417 | hbm := DllCall("CreateDIBSection", "uint" , hdc2, "uint" , &bi, "uint" , 0, "uint*", ppvBits, "uint" , 0, "uint" , 0) 418 | 419 | if !hdc 420 | ReleaseDC(hdc2) 421 | return hbm 422 | } 423 | 424 | ;##################################################################################### 425 | 426 | ; Function PrintWindow 427 | ; Description The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC 428 | ; 429 | ; hwnd A handle to the window that will be copied 430 | ; hdc A handle to the device context 431 | ; Flags Drawing options 432 | ; 433 | ; return If the function succeeds, it returns a nonzero value 434 | ; 435 | ; PW_CLIENTONLY = 1 436 | 437 | PrintWindow(hwnd, hdc, Flags=0) 438 | { 439 | return DllCall("PrintWindow", "uint", hwnd, "uint", hdc, "uint", Flags) 440 | } 441 | 442 | ;##################################################################################### 443 | 444 | ; Function DestroyIcon 445 | ; Description Destroys an icon and frees any memory the icon occupied 446 | ; 447 | ; hIcon Handle to the icon to be destroyed. The icon must not be in use 448 | ; 449 | ; return If the function succeeds, the return value is nonzero 450 | 451 | DestroyIcon(hIcon) 452 | { 453 | return DllCall("DestroyIcon", "uint", hIcon) 454 | } 455 | 456 | ;##################################################################################### 457 | 458 | PaintDesktop(hdc) 459 | { 460 | return DllCall("PaintDesktop", "uint", hdc) 461 | } 462 | 463 | ;##################################################################################### 464 | 465 | CreateCompatibleBitmap(hdc, w, h) 466 | { 467 | return DllCall("gdi32\CreateCompatibleBitmap", "uint", hdc, "int", w, "int", h) 468 | } 469 | 470 | ;##################################################################################### 471 | 472 | ; Function CreateCompatibleDC 473 | ; Description This function creates a memory device context (DC) compatible with the specified device 474 | ; 475 | ; hdc Handle to an existing device context 476 | ; 477 | ; return returns the handle to a device context or 0 on failure 478 | ; 479 | ; notes If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen 480 | 481 | CreateCompatibleDC(hdc=0) 482 | { 483 | return DllCall("CreateCompatibleDC", "uint", hdc) 484 | } 485 | 486 | ;##################################################################################### 487 | 488 | ; Function SelectObject 489 | ; Description The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type 490 | ; 491 | ; hdc Handle to a DC 492 | ; hgdiobj A handle to the object to be selected into the DC 493 | ; 494 | ; return If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced 495 | ; 496 | ; notes The specified object must have been created by using one of the following functions 497 | ; Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time) 498 | ; Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush 499 | ; Font - CreateFont, CreateFontIndirect 500 | ; Pen - CreatePen, CreatePenIndirect 501 | ; Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect 502 | ; 503 | ; notes If the selected object is a region and the function succeeds, the return value is one of the following value 504 | ; 505 | ; SIMPLEREGION = 2 Region consists of a single rectangle 506 | ; COMPLEXREGION = 3 Region consists of more than one rectangle 507 | ; NULLREGION = 1 Region is empty 508 | 509 | SelectObject(hdc, hgdiobj) 510 | { 511 | return DllCall("SelectObject", "uint", hdc, "uint", hgdiobj) 512 | } 513 | 514 | ;##################################################################################### 515 | 516 | ; Function DeleteObject 517 | ; Description This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object 518 | ; After the object is deleted, the specified handle is no longer valid 519 | ; 520 | ; hObject Handle to a logical pen, brush, font, bitmap, region, or palette to delete 521 | ; 522 | ; return Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context 523 | 524 | DeleteObject(hObject) 525 | { 526 | return DllCall("DeleteObject", "uint", hObject) 527 | } 528 | 529 | ;##################################################################################### 530 | 531 | ; Function GetDC 532 | ; Description This function retrieves a handle to a display device context (DC) for the client area of the specified window. 533 | ; The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window. 534 | ; 535 | ; 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 536 | ; 537 | ; return The handle the device context for the specified window's client area indicates success. NULL indicates failure 538 | 539 | GetDC(hwnd=0) 540 | { 541 | return DllCall("GetDC", "uint", hwnd) 542 | } 543 | 544 | ;##################################################################################### 545 | 546 | ; DCX_CACHE = 0x2 547 | ; DCX_CLIPCHILDREN = 0x8 548 | ; DCX_CLIPSIBLINGS = 0x10 549 | ; DCX_EXCLUDERGN = 0x40 550 | ; DCX_EXCLUDEUPDATE = 0x100 551 | ; DCX_INTERSECTRGN = 0x80 552 | ; DCX_INTERSECTUPDATE = 0x200 553 | ; DCX_LOCKWINDOWUPDATE = 0x400 554 | ; DCX_NORECOMPUTE = 0x100000 555 | ; DCX_NORESETATTRS = 0x4 556 | ; DCX_PARENTCLIP = 0x20 557 | ; DCX_VALIDATE = 0x200000 558 | ; DCX_WINDOW = 0x1 559 | 560 | GetDCEx(hwnd, flags=0, hrgnClip=0) 561 | { 562 | return DllCall("GetDCEx", "uint", hwnd, "uint", hrgnClip, "int", flags) 563 | } 564 | 565 | ;##################################################################################### 566 | 567 | ; Function ReleaseDC 568 | ; 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 569 | ; 570 | ; hdc Handle to the device context to be released 571 | ; hwnd Handle to the window whose device context is to be released 572 | ; 573 | ; return 1 = released 574 | ; 0 = not released 575 | ; 576 | ; 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 577 | ; 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. 578 | 579 | ReleaseDC(hdc, hwnd=0) 580 | { 581 | return DllCall("ReleaseDC", "uint", hwnd, "uint", hdc) 582 | } 583 | 584 | ;##################################################################################### 585 | 586 | ; Function DeleteDC 587 | ; Description The DeleteDC function deletes the specified device context (DC) 588 | ; 589 | ; hdc A handle to the device context 590 | ; 591 | ; return If the function succeeds, the return value is nonzero 592 | ; 593 | ; 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 594 | 595 | DeleteDC(hdc) 596 | { 597 | return DllCall("DeleteDC", "uint", hdc) 598 | } 599 | ;##################################################################################### 600 | 601 | ; Function Gdip_LibraryVersion 602 | ; Description Get the current library version 603 | ; 604 | ; return the library version 605 | ; 606 | ; notes This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts 607 | 608 | Gdip_LibraryVersion() 609 | { 610 | return 1.45 611 | } 612 | 613 | ;##################################################################################### 614 | 615 | ; Function: Gdip_BitmapFromBRA 616 | ; Description: Gets a pointer to a gdi+ bitmap from a BRA file 617 | ; 618 | ; BRAFromMemIn The variable for a BRA file read to memory 619 | ; File The name of the file, or its number that you would like (This depends on alternate parameter) 620 | ; Alternate Changes whether the File parameter is the file name or its number 621 | ; 622 | ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap 623 | ; -1 = The BRA variable is empty 624 | ; -2 = The BRA has an incorrect header 625 | ; -3 = The BRA has information missing 626 | ; -4 = Could not find file inside the BRA 627 | 628 | Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0) 629 | { 630 | if !BRAFromMemIn 631 | return -1 632 | Loop, Parse, BRAFromMemIn, `n 633 | { 634 | if (A_Index = 1) 635 | { 636 | StringSplit, Header, A_LoopField, | 637 | if (Header0 != 4 || Header2 != "BRA!") 638 | return -2 639 | } 640 | else if (A_Index = 2) 641 | { 642 | StringSplit, Info, A_LoopField, | 643 | if (Info0 != 3) 644 | return -3 645 | } 646 | else 647 | break 648 | } 649 | if !Alternate 650 | StringReplace, File, File, \, \\, All 651 | RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo) 652 | if !FileInfo 653 | return -4 654 | 655 | hData := DllCall("GlobalAlloc", "uint", 2, "uint", FileInfo2) 656 | pData := DllCall("GlobalLock", "uint", hData) 657 | DllCall("RtlMoveMemory", "uint", pData, "uint", &BRAFromMemIn+Info2+FileInfo1, "uint", FileInfo2) 658 | DllCall("GlobalUnlock", "uint", hData) 659 | DllCall("ole32\CreateStreamOnHGlobal", "uint", hData, "int", 1, "uint*", pStream) 660 | DllCall("gdiplus\GdipCreateBitmapFromStream", "uint", pStream, "uint*", pBitmap) 661 | DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream) 662 | return pBitmap 663 | } 664 | 665 | ;##################################################################################### 666 | 667 | ; Function Gdip_DrawRectangle 668 | ; Description This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap 669 | ; 670 | ; pGraphics Pointer to the Graphics of a bitmap 671 | ; pPen Pointer to a pen 672 | ; x x-coordinate of the top left of the rectangle 673 | ; y y-coordinate of the top left of the rectangle 674 | ; w width of the rectanlge 675 | ; h height of the rectangle 676 | ; 677 | ; return status enumeration. 0 = success 678 | ; 679 | ; 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 680 | 681 | Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) 682 | { 683 | return DllCall("gdiplus\GdipDrawRectangle", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h) 684 | } 685 | 686 | ;##################################################################################### 687 | 688 | ; Function Gdip_DrawRoundedRectangle 689 | ; Description This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap 690 | ; 691 | ; pGraphics Pointer to the Graphics of a bitmap 692 | ; pPen Pointer to a pen 693 | ; x x-coordinate of the top left of the rounded rectangle 694 | ; y y-coordinate of the top left of the rounded rectangle 695 | ; w width of the rectanlge 696 | ; h height of the rectangle 697 | ; r radius of the rounded corners 698 | ; 699 | ; return status enumeration. 0 = success 700 | ; 701 | ; 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 702 | 703 | Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r) 704 | { 705 | Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) 706 | Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) 707 | Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) 708 | Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) 709 | E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) 710 | Gdip_ResetClip(pGraphics) 711 | Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) 712 | Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) 713 | Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r) 714 | Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r) 715 | Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r) 716 | Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r) 717 | Gdip_ResetClip(pGraphics) 718 | return E 719 | } 720 | 721 | ;##################################################################################### 722 | 723 | ; Function Gdip_DrawEllipse 724 | ; Description This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap 725 | ; 726 | ; pGraphics Pointer to the Graphics of a bitmap 727 | ; pPen Pointer to a pen 728 | ; x x-coordinate of the top left of the rectangle the ellipse will be drawn into 729 | ; y y-coordinate of the top left of the rectangle the ellipse will be drawn into 730 | ; w width of the ellipse 731 | ; h height of the ellipse 732 | ; 733 | ; return status enumeration. 0 = success 734 | ; 735 | ; 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 736 | 737 | Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h) 738 | { 739 | return DllCall("gdiplus\GdipDrawEllipse", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h) 740 | } 741 | 742 | ;##################################################################################### 743 | 744 | ; Function Gdip_DrawBezier 745 | ; Description This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap 746 | ; 747 | ; pGraphics Pointer to the Graphics of a bitmap 748 | ; pPen Pointer to a pen 749 | ; x1 x-coordinate of the start of the bezier 750 | ; y1 y-coordinate of the start of the bezier 751 | ; x2 x-coordinate of the first arc of the bezier 752 | ; y2 y-coordinate of the first arc of the bezier 753 | ; x3 x-coordinate of the second arc of the bezier 754 | ; y3 y-coordinate of the second arc of the bezier 755 | ; x4 x-coordinate of the end of the bezier 756 | ; y4 y-coordinate of the end of the bezier 757 | ; 758 | ; return status enumeration. 0 = success 759 | ; 760 | ; 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 761 | 762 | Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4) 763 | { 764 | return DllCall("gdiplus\GdipDrawBezier", "uint", pgraphics, "uint", pPen 765 | , "float", x1, "float", y1, "float", x2, "float", y2 766 | , "float", x3, "float", y3, "float", x4, "float", y4) 767 | } 768 | 769 | ;##################################################################################### 770 | 771 | ; Function Gdip_DrawArc 772 | ; Description This function uses a pen to draw the outline of an arc into the Graphics of a bitmap 773 | ; 774 | ; pGraphics Pointer to the Graphics of a bitmap 775 | ; pPen Pointer to a pen 776 | ; x x-coordinate of the start of the arc 777 | ; y y-coordinate of the start of the arc 778 | ; w width of the arc 779 | ; h height of the arc 780 | ; StartAngle specifies the angle between the x-axis and the starting point of the arc 781 | ; SweepAngle specifies the angle between the starting and ending points of the arc 782 | ; 783 | ; return status enumeration. 0 = success 784 | ; 785 | ; 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 786 | 787 | Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 788 | { 789 | return DllCall("gdiplus\GdipDrawArc", "uint", pGraphics, "uint", pPen, "float", x 790 | , "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle) 791 | } 792 | 793 | ;##################################################################################### 794 | 795 | ; Function Gdip_DrawPie 796 | ; Description This function uses a pen to draw the outline of a pie into the Graphics of a bitmap 797 | ; 798 | ; pGraphics Pointer to the Graphics of a bitmap 799 | ; pPen Pointer to a pen 800 | ; x x-coordinate of the start of the pie 801 | ; y y-coordinate of the start of the pie 802 | ; w width of the pie 803 | ; h height of the pie 804 | ; StartAngle specifies the angle between the x-axis and the starting point of the pie 805 | ; SweepAngle specifies the angle between the starting and ending points of the pie 806 | ; 807 | ; return status enumeration. 0 = success 808 | ; 809 | ; 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 810 | 811 | Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 812 | { 813 | return DllCall("gdiplus\GdipDrawPie", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle) 814 | } 815 | 816 | ;##################################################################################### 817 | 818 | ; Function Gdip_DrawLine 819 | ; Description This function uses a pen to draw a line into the Graphics of a bitmap 820 | ; 821 | ; pGraphics Pointer to the Graphics of a bitmap 822 | ; pPen Pointer to a pen 823 | ; x1 x-coordinate of the start of the line 824 | ; y1 y-coordinate of the start of the line 825 | ; x2 x-coordinate of the end of the line 826 | ; y2 y-coordinate of the end of the line 827 | ; 828 | ; return status enumeration. 0 = success 829 | 830 | Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2) 831 | { 832 | return DllCall("gdiplus\GdipDrawLine", "uint", pGraphics, "uint", pPen 833 | , "float", x1, "float", y1, "float", x2, "float", y2) 834 | } 835 | 836 | ;##################################################################################### 837 | 838 | ; Function Gdip_DrawLines 839 | ; Description This function uses a pen to draw a series of joined lines into the Graphics of a bitmap 840 | ; 841 | ; pGraphics Pointer to the Graphics of a bitmap 842 | ; pPen Pointer to a pen 843 | ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... 844 | ; 845 | ; return status enumeration. 0 = success 846 | 847 | Gdip_DrawLines(pGraphics, pPen, Points) 848 | { 849 | StringSplit, Points, Points, | 850 | VarSetCapacity(PointF, 8*Points0) 851 | Loop, %Points0% 852 | { 853 | StringSplit, Coord, Points%A_Index%, `, 854 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 855 | } 856 | return DllCall("gdiplus\GdipDrawLines", "uint", pGraphics, "uint", pPen, "uint", &PointF, "int", Points0) 857 | } 858 | 859 | ;##################################################################################### 860 | 861 | ; Function Gdip_FillRectangle 862 | ; Description This function uses a brush to fill a rectangle in the Graphics of a bitmap 863 | ; 864 | ; pGraphics Pointer to the Graphics of a bitmap 865 | ; pBrush Pointer to a brush 866 | ; x x-coordinate of the top left of the rectangle 867 | ; y y-coordinate of the top left of the rectangle 868 | ; w width of the rectanlge 869 | ; h height of the rectangle 870 | ; 871 | ; return status enumeration. 0 = success 872 | 873 | Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) 874 | { 875 | return DllCall("gdiplus\GdipFillRectangle", "uint", pGraphics, "int", pBrush 876 | , "float", x, "float", y, "float", w, "float", h) 877 | } 878 | 879 | ;##################################################################################### 880 | 881 | ; Function Gdip_FillRoundedRectangle 882 | ; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap 883 | ; 884 | ; pGraphics Pointer to the Graphics of a bitmap 885 | ; pBrush Pointer to a brush 886 | ; x x-coordinate of the top left of the rounded rectangle 887 | ; y y-coordinate of the top left of the rounded rectangle 888 | ; w width of the rectanlge 889 | ; h height of the rectangle 890 | ; r radius of the rounded corners 891 | ; 892 | ; return status enumeration. 0 = success 893 | 894 | Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r) 895 | { 896 | Region := Gdip_GetClipRegion(pGraphics) 897 | Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) 898 | Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) 899 | Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) 900 | Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) 901 | E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) 902 | Gdip_SetClipRegion(pGraphics, Region, 0) 903 | Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) 904 | Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) 905 | Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r) 906 | Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r) 907 | Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r) 908 | Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r) 909 | Gdip_SetClipRegion(pGraphics, Region, 0) 910 | Gdip_DeleteRegion(Region) 911 | return E 912 | } 913 | 914 | ;##################################################################################### 915 | 916 | ; Function Gdip_FillPolygon 917 | ; Description This function uses a brush to fill a polygon in the Graphics of a bitmap 918 | ; 919 | ; pGraphics Pointer to the Graphics of a bitmap 920 | ; pBrush Pointer to a brush 921 | ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... 922 | ; 923 | ; return status enumeration. 0 = success 924 | ; 925 | ; notes Alternate will fill the polygon as a whole, wheras winding will fill each new "segment" 926 | ; Alternate = 0 927 | ; Winding = 1 928 | 929 | Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0) 930 | { 931 | StringSplit, Points, Points, | 932 | VarSetCapacity(PointF, 8*Points0) 933 | Loop, %Points0% 934 | { 935 | StringSplit, Coord, Points%A_Index%, `, 936 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 937 | } 938 | return DllCall("gdiplus\GdipFillPolygon", "uint", pGraphics, "uint", pBrush, "uint", &PointF, "int", Points0, "int", FillMode) 939 | } 940 | 941 | ;##################################################################################### 942 | 943 | ; Function Gdip_FillPie 944 | ; Description This function uses a brush to fill a pie in the Graphics of a bitmap 945 | ; 946 | ; pGraphics Pointer to the Graphics of a bitmap 947 | ; pBrush Pointer to a brush 948 | ; x x-coordinate of the top left of the pie 949 | ; y y-coordinate of the top left of the pie 950 | ; w width of the pie 951 | ; h height of the pie 952 | ; StartAngle specifies the angle between the x-axis and the starting point of the pie 953 | ; SweepAngle specifies the angle between the starting and ending points of the pie 954 | ; 955 | ; return status enumeration. 0 = success 956 | 957 | Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle) 958 | { 959 | return DllCall("gdiplus\GdipFillPie", "uint", pGraphics, "uint", pBrush 960 | , "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle) 961 | } 962 | 963 | ;##################################################################################### 964 | 965 | ; Function Gdip_FillEllipse 966 | ; Description This function uses a brush to fill an ellipse in the Graphics of a bitmap 967 | ; 968 | ; pGraphics Pointer to the Graphics of a bitmap 969 | ; pBrush Pointer to a brush 970 | ; x x-coordinate of the top left of the ellipse 971 | ; y y-coordinate of the top left of the ellipse 972 | ; w width of the ellipse 973 | ; h height of the ellipse 974 | ; 975 | ; return status enumeration. 0 = success 976 | 977 | Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h) 978 | { 979 | return DllCall("gdiplus\GdipFillEllipse", "uint", pGraphics, "uint", pBrush, "float", x, "float", y, "float", w, "float", h) 980 | } 981 | 982 | ;##################################################################################### 983 | 984 | ; Function Gdip_FillRegion 985 | ; Description This function uses a brush to fill a region in the Graphics of a bitmap 986 | ; 987 | ; pGraphics Pointer to the Graphics of a bitmap 988 | ; pBrush Pointer to a brush 989 | ; Region Pointer to a Region 990 | ; 991 | ; return status enumeration. 0 = success 992 | ; 993 | ; notes You can create a region Gdip_CreateRegion() and then add to this 994 | 995 | Gdip_FillRegion(pGraphics, pBrush, Region) 996 | { 997 | return DllCall("gdiplus\GdipFillRegion", "uint", pGraphics, "uint", pBrush, "uint", Region) 998 | } 999 | 1000 | ;##################################################################################### 1001 | 1002 | ; Function Gdip_FillPath 1003 | ; Description This function uses a brush to fill a path in the Graphics of a bitmap 1004 | ; 1005 | ; pGraphics Pointer to the Graphics of a bitmap 1006 | ; pBrush Pointer to a brush 1007 | ; Region Pointer to a Path 1008 | ; 1009 | ; return status enumeration. 0 = success 1010 | 1011 | Gdip_FillPath(pGraphics, pBrush, Path) 1012 | { 1013 | return DllCall("gdiplus\GdipFillPath", "uint", pGraphics, "uint", pBrush, "uint", Path) 1014 | } 1015 | 1016 | ;##################################################################################### 1017 | 1018 | ; Function Gdip_DrawImagePointsRect 1019 | ; Description This function draws a bitmap into the Graphics of another bitmap and skews it 1020 | ; 1021 | ; pGraphics Pointer to the Graphics of a bitmap 1022 | ; pBitmap Pointer to a bitmap to be drawn 1023 | ; Points Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap 1024 | ; sx x-coordinate of source upper-left corner 1025 | ; sy y-coordinate of source upper-left corner 1026 | ; sw width of source rectangle 1027 | ; sh height of source rectangle 1028 | ; Matrix a matrix used to alter image attributes when drawing 1029 | ; 1030 | ; return status enumeration. 0 = success 1031 | ; 1032 | ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used 1033 | ; Matrix can be omitted to just draw with no alteration to ARGB 1034 | ; Matrix may be passed as a digit from 0 - 1 to change just transparency 1035 | ; Matrix can be passed as a matrix with any delimiter 1036 | 1037 | Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1) 1038 | { 1039 | StringSplit, Points, Points, | 1040 | VarSetCapacity(PointF, 8*Points0) 1041 | Loop, %Points0% 1042 | { 1043 | StringSplit, Coord, Points%A_Index%, `, 1044 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 1045 | } 1046 | 1047 | if (Matrix&1 = "") 1048 | ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) 1049 | else if (Matrix != 1) 1050 | 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") 1051 | 1052 | if (sx = "" && sy = "" && sw = "" && sh = "") 1053 | { 1054 | sx := 0, sy := 0 1055 | sw := Gdip_GetImageWidth(pBitmap) 1056 | sh := Gdip_GetImageHeight(pBitmap) 1057 | } 1058 | 1059 | E := DllCall("gdiplus\GdipDrawImagePointsRect", "uint", pGraphics, "uint", pBitmap 1060 | , "uint", &PointF, "int", Points0, "float", sx, "float", sy, "float", sw, "float", sh 1061 | , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0) 1062 | if ImageAttr 1063 | Gdip_DisposeImageAttributes(ImageAttr) 1064 | return E 1065 | } 1066 | 1067 | ;##################################################################################### 1068 | 1069 | ; Function Gdip_DrawImage 1070 | ; Description This function draws a bitmap into the Graphics of another bitmap 1071 | ; 1072 | ; pGraphics Pointer to the Graphics of a bitmap 1073 | ; pBitmap Pointer to a bitmap to be drawn 1074 | ; dx x-coord of destination upper-left corner 1075 | ; dy y-coord of destination upper-left corner 1076 | ; dw width of destination image 1077 | ; dh height of destination image 1078 | ; sx x-coordinate of source upper-left corner 1079 | ; sy y-coordinate of source upper-left corner 1080 | ; sw width of source image 1081 | ; sh height of source image 1082 | ; Matrix a matrix used to alter image attributes when drawing 1083 | ; 1084 | ; return status enumeration. 0 = success 1085 | ; 1086 | ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used 1087 | ; Gdip_DrawImage performs faster 1088 | ; Matrix can be omitted to just draw with no alteration to ARGB 1089 | ; Matrix may be passed as a digit from 0 - 1 to change just transparency 1090 | ; Matrix can be passed as a matrix with any delimiter. For example: 1091 | ; MatrixBright= 1092 | ; ( 1093 | ; 1.5 |0 |0 |0 |0 1094 | ; 0 |1.5 |0 |0 |0 1095 | ; 0 |0 |1.5 |0 |0 1096 | ; 0 |0 |0 |1 |0 1097 | ; 0.05 |0.05 |0.05 |0 |1 1098 | ; ) 1099 | ; 1100 | ; 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 1101 | ; 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 1102 | ; 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 1103 | 1104 | Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1) 1105 | { 1106 | if (Matrix&1 = "") 1107 | ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) 1108 | else if (Matrix != 1) 1109 | 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") 1110 | 1111 | if (sx = "" && sy = "" && sw = "" && sh = "") 1112 | { 1113 | if (dx = "" && dy = "" && dw = "" && dh = "") 1114 | { 1115 | sx := dx := 0, sy := dy := 0 1116 | sw := dw := Gdip_GetImageWidth(pBitmap) 1117 | sh := dh := Gdip_GetImageHeight(pBitmap) 1118 | } 1119 | else 1120 | { 1121 | sx := sy := 0 1122 | sw := Gdip_GetImageWidth(pBitmap) 1123 | sh := Gdip_GetImageHeight(pBitmap) 1124 | } 1125 | } 1126 | 1127 | E := DllCall("gdiplus\GdipDrawImageRectRect", "uint", pGraphics, "uint", pBitmap 1128 | , "float", dx, "float", dy, "float", dw, "float", dh 1129 | , "float", sx, "float", sy, "float", sw, "float", sh 1130 | , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0) 1131 | if ImageAttr 1132 | Gdip_DisposeImageAttributes(ImageAttr) 1133 | return E 1134 | } 1135 | 1136 | ;##################################################################################### 1137 | 1138 | ; Function Gdip_SetImageAttributesColorMatrix 1139 | ; Description This function creates an image matrix ready for drawing 1140 | ; 1141 | ; Matrix a matrix used to alter image attributes when drawing 1142 | ; passed with any delimeter 1143 | ; 1144 | ; return returns an image matrix on sucess or 0 if it fails 1145 | ; 1146 | ; 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 1147 | ; 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 1148 | ; 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 1149 | 1150 | Gdip_SetImageAttributesColorMatrix(Matrix) 1151 | { 1152 | VarSetCapacity(ColourMatrix, 100, 0) 1153 | Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|") 1154 | StringSplit, Matrix, Matrix, | 1155 | Loop, 25 1156 | { 1157 | Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1 1158 | NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float") 1159 | } 1160 | DllCall("gdiplus\GdipCreateImageAttributes", "uint*", ImageAttr) 1161 | DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "uint", ImageAttr, "int", 1, "int", 1, "uint", &ColourMatrix, "int", 0, "int", 0) 1162 | return ImageAttr 1163 | } 1164 | 1165 | ;##################################################################################### 1166 | 1167 | ; Function Gdip_GraphicsFromImage 1168 | ; Description This function gets the graphics for a bitmap used for drawing functions 1169 | ; 1170 | ; pBitmap Pointer to a bitmap to get the pointer to its graphics 1171 | ; 1172 | ; return returns a pointer to the graphics of a bitmap 1173 | ; 1174 | ; notes a bitmap can be drawn into the graphics of another bitmap 1175 | 1176 | Gdip_GraphicsFromImage(pBitmap) 1177 | { 1178 | DllCall("gdiplus\GdipGetImageGraphicsContext", "uint", pBitmap, "uint*", pGraphics) 1179 | return pGraphics 1180 | } 1181 | 1182 | ;##################################################################################### 1183 | 1184 | ; Function Gdip_GraphicsFromHDC 1185 | ; Description This function gets the graphics from the handle to a device context 1186 | ; 1187 | ; hdc This is the handle to the device context 1188 | ; 1189 | ; return returns a pointer to the graphics of a bitmap 1190 | ; 1191 | ; notes You can draw a bitmap into the graphics of another bitmap 1192 | 1193 | Gdip_GraphicsFromHDC(hdc) 1194 | { 1195 | DllCall("gdiplus\GdipCreateFromHDC", "uint", hdc, "uint*", pGraphics) 1196 | return pGraphics 1197 | } 1198 | 1199 | ;##################################################################################### 1200 | 1201 | ; Function Gdip_GetDC 1202 | ; Description This function gets the device context of the passed Graphics 1203 | ; 1204 | ; hdc This is the handle to the device context 1205 | ; 1206 | ; return returns the device context for the graphics of a bitmap 1207 | 1208 | Gdip_GetDC(pGraphics) 1209 | { 1210 | DllCall("gdiplus\GdipGetDC", "uint", pGraphics, "uint*", hdc) 1211 | return hdc 1212 | } 1213 | 1214 | ;##################################################################################### 1215 | 1216 | ; Function Gdip_ReleaseDC 1217 | ; Description This function releases a device context from use for further use 1218 | ; 1219 | ; pGraphics Pointer to the graphics of a bitmap 1220 | ; hdc This is the handle to the device context 1221 | ; 1222 | ; return status enumeration. 0 = success 1223 | 1224 | Gdip_ReleaseDC(pGraphics, hdc) 1225 | { 1226 | return DllCall("gdiplus\GdipReleaseDC", "uint", pGraphics, "uint", hdc) 1227 | } 1228 | 1229 | ;##################################################################################### 1230 | 1231 | ; Function Gdip_GraphicsClear 1232 | ; Description Clears the graphics of a bitmap ready for further drawing 1233 | ; 1234 | ; pGraphics Pointer to the graphics of a bitmap 1235 | ; ARGB The colour to clear the graphics to 1236 | ; 1237 | ; return status enumeration. 0 = success 1238 | ; 1239 | ; notes By default this will make the background invisible 1240 | ; Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics 1241 | 1242 | Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff) 1243 | { 1244 | return DllCall("gdiplus\GdipGraphicsClear", "uint", pGraphics, "int", ARGB) 1245 | } 1246 | 1247 | ;##################################################################################### 1248 | 1249 | ; Function Gdip_BlurBitmap 1250 | ; Description Gives a pointer to a blurred bitmap from a pointer to a bitmap 1251 | ; 1252 | ; pBitmap Pointer to a bitmap to be blurred 1253 | ; Blur The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur) 1254 | ; 1255 | ; return If the function succeeds, the return value is a pointer to the new blurred bitmap 1256 | ; -1 = The blur parameter is outside the range 1-100 1257 | ; 1258 | ; notes This function will not dispose of the original bitmap 1259 | 1260 | Gdip_BlurBitmap(pBitmap, Blur) 1261 | { 1262 | if (Blur > 100) || (Blur < 1) 1263 | return -1 1264 | 1265 | sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap) 1266 | dWidth := sWidth//Blur, dHeight := sHeight//Blur 1267 | 1268 | pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight) 1269 | G1 := Gdip_GraphicsFromImage(pBitmap1) 1270 | Gdip_SetInterpolationMode(G1, 7) 1271 | Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight) 1272 | 1273 | Gdip_DeleteGraphics(G1) 1274 | 1275 | pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight) 1276 | G2 := Gdip_GraphicsFromImage(pBitmap2) 1277 | Gdip_SetInterpolationMode(G2, 7) 1278 | Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight) 1279 | 1280 | Gdip_DeleteGraphics(G2) 1281 | Gdip_DisposeImage(pBitmap1) 1282 | return pBitmap2 1283 | } 1284 | 1285 | ;##################################################################################### 1286 | 1287 | ; Function: Gdip_SaveBitmapToFile 1288 | ; Description: Saves a bitmap to a file in any supported format onto disk 1289 | ; 1290 | ; pBitmap Pointer to a bitmap 1291 | ; 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 1292 | ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality 1293 | ; 1294 | ; return If the function succeeds, the return value is zero, otherwise: 1295 | ; -1 = Extension supplied is not a supported file format 1296 | ; -2 = Could not get a list of encoders on system 1297 | ; -3 = Could not find matching encoder for specified file format 1298 | ; -4 = Could not get WideChar name of output file 1299 | ; -5 = Could not save file to disk 1300 | ; 1301 | ; notes This function will use the extension supplied from the sOutput parameter to determine the output format 1302 | 1303 | Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75) 1304 | { 1305 | SplitPath, sOutput,,, Extension 1306 | if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG 1307 | return -1 1308 | Extension := "." Extension 1309 | 1310 | DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize) 1311 | VarSetCapacity(ci, nSize) 1312 | DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "uint", &ci) 1313 | if !(nCount && nSize) 1314 | return -2 1315 | 1316 | Loop, %nCount% 1317 | { 1318 | Location := NumGet(ci, 76*(A_Index-1)+44) 1319 | if !A_IsUnicode 1320 | { 1321 | nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0) 1322 | VarSetCapacity(sString, nSize) 1323 | DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0) 1324 | if !InStr(sString, "*" Extension) 1325 | continue 1326 | } 1327 | else 1328 | { 1329 | nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0) 1330 | sString := "" 1331 | Loop, %nSize% 1332 | sString .= Chr(NumGet(Location+0, 2*(A_Index-1), "char")) 1333 | if !InStr(sString, "*" Extension) 1334 | continue 1335 | } 1336 | pCodec := &ci+76*(A_Index-1) 1337 | break 1338 | } 1339 | if !pCodec 1340 | return -3 1341 | 1342 | if (Quality != 75) 1343 | { 1344 | Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality 1345 | if Extension in .JPG,.JPEG,.JPE,.JFIF 1346 | { 1347 | DllCall("gdiplus\GdipGetEncoderParameterListSize", "uint", pBitmap, "uint", pCodec, "uint*", nSize) 1348 | VarSetCapacity(EncoderParameters, nSize, 0) 1349 | DllCall("gdiplus\GdipGetEncoderParameterList", "uint", pBitmap, "uint", pCodec, "uint", nSize, "uint", &EncoderParameters) 1350 | Loop, % NumGet(EncoderParameters) ;% 1351 | { 1352 | if (NumGet(EncoderParameters, (28*(A_Index-1))+20) = 1) && (NumGet(EncoderParameters, (28*(A_Index-1))+24) = 6) 1353 | { 1354 | p := (28*(A_Index-1))+&EncoderParameters 1355 | NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20))) 1356 | break 1357 | } 1358 | } 1359 | } 1360 | } 1361 | 1362 | if !A_IsUnicode 1363 | { 1364 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", 0, "int", 0) 1365 | VarSetCapacity(wOutput, nSize*2) 1366 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", &wOutput, "int", nSize) 1367 | VarSetCapacity(wOutput, -1) 1368 | if !VarSetCapacity(wOutput) 1369 | return -4 1370 | E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &wOutput, "uint", pCodec, "uint", p ? p : 0) 1371 | } 1372 | else 1373 | E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &sOutput, "uint", pCodec, "uint", p ? p : 0) 1374 | return E ? -5 : 0 1375 | } 1376 | 1377 | ;##################################################################################### 1378 | 1379 | ; Function Gdip_GetPixel 1380 | ; Description Gets the ARGB of a pixel in a bitmap 1381 | ; 1382 | ; pBitmap Pointer to a bitmap 1383 | ; x x-coordinate of the pixel 1384 | ; y y-coordinate of the pixel 1385 | ; 1386 | ; return Returns the ARGB value of the pixel 1387 | 1388 | Gdip_GetPixel(pBitmap, x, y) 1389 | { 1390 | DllCall("gdiplus\GdipBitmapGetPixel", "uint", pBitmap, "int", x, "int", y, "uint*", ARGB) 1391 | return ARGB 1392 | } 1393 | 1394 | ;##################################################################################### 1395 | 1396 | ; Function Gdip_SetPixel 1397 | ; Description Sets the ARGB of a pixel in a bitmap 1398 | ; 1399 | ; pBitmap Pointer to a bitmap 1400 | ; x x-coordinate of the pixel 1401 | ; y y-coordinate of the pixel 1402 | ; 1403 | ; return status enumeration. 0 = success 1404 | 1405 | Gdip_SetPixel(pBitmap, x, y, ARGB) 1406 | { 1407 | return DllCall("gdiplus\GdipBitmapSetPixel", "uint", pBitmap, "int", x, "int", y, "int", ARGB) 1408 | } 1409 | 1410 | ;##################################################################################### 1411 | 1412 | ; Function Gdip_GetImageWidth 1413 | ; Description Gives the width of a bitmap 1414 | ; 1415 | ; pBitmap Pointer to a bitmap 1416 | ; 1417 | ; return Returns the width in pixels of the supplied bitmap 1418 | 1419 | Gdip_GetImageWidth(pBitmap) 1420 | { 1421 | DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width) 1422 | return Width 1423 | } 1424 | 1425 | ;##################################################################################### 1426 | 1427 | ; Function Gdip_GetImageHeight 1428 | ; Description Gives the height of a bitmap 1429 | ; 1430 | ; pBitmap Pointer to a bitmap 1431 | ; 1432 | ; return Returns the height in pixels of the supplied bitmap 1433 | 1434 | Gdip_GetImageHeight(pBitmap) 1435 | { 1436 | DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height) 1437 | return Height 1438 | } 1439 | 1440 | ;##################################################################################### 1441 | 1442 | ; Function Gdip_GetDimensions 1443 | ; Description Gives the width and height of a bitmap 1444 | ; 1445 | ; pBitmap Pointer to a bitmap 1446 | ; Width ByRef variable. This variable will be set to the width of the bitmap 1447 | ; Height ByRef variable. This variable will be set to the height of the bitmap 1448 | ; 1449 | ; return No return value 1450 | ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height 1451 | 1452 | Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height) 1453 | { 1454 | DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width) 1455 | DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height) 1456 | } 1457 | 1458 | ;##################################################################################### 1459 | 1460 | Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height) 1461 | { 1462 | Gdip_GetImageDimensions(pBitmap, Width, Height) 1463 | } 1464 | 1465 | ;##################################################################################### 1466 | 1467 | Gdip_GetImagePixelFormat(pBitmap) 1468 | { 1469 | DllCall("gdiplus\GdipGetImagePixelFormat", "uint", pBitmap, "uint*", Format) 1470 | return Format 1471 | } 1472 | 1473 | ;##################################################################################### 1474 | 1475 | ; Function Gdip_GetDpiX 1476 | ; Description Gives the horizontal dots per inch of the graphics of a bitmap 1477 | ; 1478 | ; pBitmap Pointer to a bitmap 1479 | ; Width ByRef variable. This variable will be set to the width of the bitmap 1480 | ; Height ByRef variable. This variable will be set to the height of the bitmap 1481 | ; 1482 | ; return No return value 1483 | ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height 1484 | 1485 | Gdip_GetDpiX(pGraphics) 1486 | { 1487 | DllCall("gdiplus\GdipGetDpiX", "uint", pGraphics, "float*", dpix) 1488 | return Round(dpix) 1489 | } 1490 | 1491 | ;##################################################################################### 1492 | 1493 | Gdip_GetDpiY(pGraphics) 1494 | { 1495 | DllCall("gdiplus\GdipGetDpiY", "uint", pGraphics, "float*", dpiy) 1496 | return Round(dpiy) 1497 | } 1498 | 1499 | ;##################################################################################### 1500 | 1501 | Gdip_GetImageHorizontalResolution(pBitmap) 1502 | { 1503 | DllCall("gdiplus\GdipGetImageHorizontalResolution", "uint", pBitmap, "float*", dpix) 1504 | return Round(dpix) 1505 | } 1506 | 1507 | ;##################################################################################### 1508 | 1509 | Gdip_GetImageVerticalResolution(pBitmap) 1510 | { 1511 | DllCall("gdiplus\GdipGetImageVerticalResolution", "uint", pBitmap, "float*", dpiy) 1512 | return Round(dpiy) 1513 | } 1514 | 1515 | ;##################################################################################### 1516 | 1517 | Gdip_BitmapSetResolution(pBitmap, dpix, dpiy) 1518 | { 1519 | return DllCall("gdiplus\GdipBitmapSetResolution", "uint", pBitmap, "float", dpix, "float", dpiy) 1520 | } 1521 | 1522 | ;##################################################################################### 1523 | 1524 | Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="") 1525 | { 1526 | SplitPath, sFile,,, ext 1527 | if ext in exe,dll 1528 | { 1529 | Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16 1530 | VarSetCapacity(buf, 40) 1531 | Loop, Parse, Sizes, | 1532 | { 1533 | DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, "uint*", hIcon, "uint*", 0, "uint", 1, "uint", 0) 1534 | if !hIcon 1535 | continue 1536 | 1537 | if !DllCall("GetIconInfo", "uint", hIcon, "uint", &buf) 1538 | { 1539 | DestroyIcon(hIcon) 1540 | continue 1541 | } 1542 | hbmColor := NumGet(buf, 16) 1543 | hbmMask := NumGet(buf, 12) 1544 | 1545 | if !(hbmColor && DllCall("GetObject", "uint", hbmColor, "int", 24, "uint", &buf)) 1546 | { 1547 | DestroyIcon(hIcon) 1548 | continue 1549 | } 1550 | break 1551 | } 1552 | if !hIcon 1553 | return -1 1554 | 1555 | Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int") 1556 | hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) 1557 | 1558 | if !DllCall("DrawIconEx", "uint", hdc, "int", 0, "int", 0, "uint", hIcon, "uint", Width, "uint", Height, "uint", 0, "uint", 0, "uint", 3) 1559 | { 1560 | DestroyIcon(hIcon) 1561 | return -2 1562 | } 1563 | 1564 | VarSetCapacity(dib, 84) 1565 | DllCall("GetObject", "uint", hbm, "int", 84, "uint", &dib) 1566 | Stride := NumGet(dib, 12), Bits := NumGet(dib, 20) 1567 | 1568 | DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, "uint", Bits, "uint*", pBitmapOld) 1569 | pBitmap := Gdip_CreateBitmap(Width, Height), G := Gdip_GraphicsFromImage(pBitmap) 1570 | Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height) 1571 | SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) 1572 | Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld) 1573 | DestroyIcon(hIcon) 1574 | } 1575 | else 1576 | { 1577 | if !A_IsUnicode 1578 | { 1579 | VarSetCapacity(wFile, 1023) 1580 | DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sFile, "int", -1, "uint", &wFile, "int", 512) 1581 | DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &wFile, "uint*", pBitmap) 1582 | } 1583 | else 1584 | DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &sFile, "uint*", pBitmap) 1585 | } 1586 | return pBitmap 1587 | } 1588 | 1589 | ;##################################################################################### 1590 | 1591 | Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0) 1592 | { 1593 | DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "uint", hBitmap, "uint", Palette, "uint*", pBitmap) 1594 | return pBitmap 1595 | } 1596 | 1597 | ;##################################################################################### 1598 | 1599 | Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff) 1600 | { 1601 | DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "uint", pBitmap, "uint*", hbm, "int", Background) 1602 | return hbm 1603 | } 1604 | 1605 | ;##################################################################################### 1606 | 1607 | Gdip_CreateBitmapFromHICON(hIcon) 1608 | { 1609 | DllCall("gdiplus\GdipCreateBitmapFromHICON", "uint", hIcon, "uint*", pBitmap) 1610 | return pBitmap 1611 | } 1612 | 1613 | ;##################################################################################### 1614 | 1615 | Gdip_CreateHICONFromBitmap(pBitmap) 1616 | { 1617 | DllCall("gdiplus\GdipCreateHICONFromBitmap", "uint", pBitmap, "uint*", hIcon) 1618 | return hIcon 1619 | } 1620 | 1621 | ;##################################################################################### 1622 | 1623 | Gdip_CreateBitmap(Width, Height, Format=0x26200A) 1624 | { 1625 | DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, "uint", 0, "uint*", pBitmap) 1626 | Return pBitmap 1627 | } 1628 | 1629 | ;##################################################################################### 1630 | 1631 | Gdip_CreateBitmapFromClipboard() 1632 | { 1633 | if !DllCall("OpenClipboard", "uint", 0) 1634 | return -1 1635 | if !DllCall("IsClipboardFormatAvailable", "uint", 8) 1636 | return -2 1637 | if !hBitmap := DllCall("GetClipboardData", "uint", 2) 1638 | return -3 1639 | if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap) 1640 | return -4 1641 | if !DllCall("CloseClipboard") 1642 | return -5 1643 | DeleteObject(hBitmap) 1644 | return pBitmap 1645 | } 1646 | 1647 | ;##################################################################################### 1648 | 1649 | Gdip_SetBitmapToClipboard(pBitmap) 1650 | { 1651 | hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) 1652 | DllCall("GetObject", "uint", hBitmap, "int", VarSetCapacity(oi, 84, 0), "uint", &oi) 1653 | hdib := DllCall("GlobalAlloc", "uint", 2, "uint", 40+NumGet(oi, 44)) 1654 | pdib := DllCall("GlobalLock", "uint", hdib) 1655 | DllCall("RtlMoveMemory", "uint", pdib, "uint", &oi+24, "uint", 40) 1656 | DllCall("RtlMoveMemory", "Uint", pdib+40, "Uint", NumGet(oi, 20), "uint", NumGet(oi, 44)) 1657 | DllCall("GlobalUnlock", "uint", hdib) 1658 | DllCall("DeleteObject", "uint", hBitmap) 1659 | DllCall("OpenClipboard", "uint", 0) 1660 | DllCall("EmptyClipboard") 1661 | DllCall("SetClipboardData", "uint", 8, "uint", hdib) 1662 | DllCall("CloseClipboard") 1663 | } 1664 | 1665 | ;##################################################################################### 1666 | 1667 | Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A) 1668 | { 1669 | DllCall("gdiplus\GdipCloneBitmapArea", "float", x, "float", y, "float", w, "float", h 1670 | , "int", Format, "uint", pBitmap, "uint*", pBitmapDest) 1671 | return pBitmapDest 1672 | } 1673 | 1674 | ;##################################################################################### 1675 | ; Create resources 1676 | ;##################################################################################### 1677 | 1678 | Gdip_CreatePen(ARGB, w) 1679 | { 1680 | DllCall("gdiplus\GdipCreatePen1", "int", ARGB, "float", w, "int", 2, "uint*", pPen) 1681 | return pPen 1682 | } 1683 | 1684 | ;##################################################################################### 1685 | 1686 | Gdip_CreatePenFromBrush(pBrush, w) 1687 | { 1688 | DllCall("gdiplus\GdipCreatePen2", "uint", pBrush, "float", w, "int", 2, "uint*", pPen) 1689 | return pPen 1690 | } 1691 | 1692 | ;##################################################################################### 1693 | 1694 | Gdip_BrushCreateSolid(ARGB=0xff000000) 1695 | { 1696 | DllCall("gdiplus\GdipCreateSolidFill", "int", ARGB, "uint*", pBrush) 1697 | return pBrush 1698 | } 1699 | 1700 | ;##################################################################################### 1701 | 1702 | ; HatchStyleHorizontal = 0 1703 | ; HatchStyleVertical = 1 1704 | ; HatchStyleForwardDiagonal = 2 1705 | ; HatchStyleBackwardDiagonal = 3 1706 | ; HatchStyleCross = 4 1707 | ; HatchStyleDiagonalCross = 5 1708 | ; HatchStyle05Percent = 6 1709 | ; HatchStyle10Percent = 7 1710 | ; HatchStyle20Percent = 8 1711 | ; HatchStyle25Percent = 9 1712 | ; HatchStyle30Percent = 10 1713 | ; HatchStyle40Percent = 11 1714 | ; HatchStyle50Percent = 12 1715 | ; HatchStyle60Percent = 13 1716 | ; HatchStyle70Percent = 14 1717 | ; HatchStyle75Percent = 15 1718 | ; HatchStyle80Percent = 16 1719 | ; HatchStyle90Percent = 17 1720 | ; HatchStyleLightDownwardDiagonal = 18 1721 | ; HatchStyleLightUpwardDiagonal = 19 1722 | ; HatchStyleDarkDownwardDiagonal = 20 1723 | ; HatchStyleDarkUpwardDiagonal = 21 1724 | ; HatchStyleWideDownwardDiagonal = 22 1725 | ; HatchStyleWideUpwardDiagonal = 23 1726 | ; HatchStyleLightVertical = 24 1727 | ; HatchStyleLightHorizontal = 25 1728 | ; HatchStyleNarrowVertical = 26 1729 | ; HatchStyleNarrowHorizontal = 27 1730 | ; HatchStyleDarkVertical = 28 1731 | ; HatchStyleDarkHorizontal = 29 1732 | ; HatchStyleDashedDownwardDiagonal = 30 1733 | ; HatchStyleDashedUpwardDiagonal = 31 1734 | ; HatchStyleDashedHorizontal = 32 1735 | ; HatchStyleDashedVertical = 33 1736 | ; HatchStyleSmallConfetti = 34 1737 | ; HatchStyleLargeConfetti = 35 1738 | ; HatchStyleZigZag = 36 1739 | ; HatchStyleWave = 37 1740 | ; HatchStyleDiagonalBrick = 38 1741 | ; HatchStyleHorizontalBrick = 39 1742 | ; HatchStyleWeave = 40 1743 | ; HatchStylePlaid = 41 1744 | ; HatchStyleDivot = 42 1745 | ; HatchStyleDottedGrid = 43 1746 | ; HatchStyleDottedDiamond = 44 1747 | ; HatchStyleShingle = 45 1748 | ; HatchStyleTrellis = 46 1749 | ; HatchStyleSphere = 47 1750 | ; HatchStyleSmallGrid = 48 1751 | ; HatchStyleSmallCheckerBoard = 49 1752 | ; HatchStyleLargeCheckerBoard = 50 1753 | ; HatchStyleOutlinedDiamond = 51 1754 | ; HatchStyleSolidDiamond = 52 1755 | ; HatchStyleTotal = 53 1756 | Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0) 1757 | { 1758 | DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "int", ARGBfront, "int", ARGBback, "uint*", pBrush) 1759 | return pBrush 1760 | } 1761 | 1762 | ;##################################################################################### 1763 | 1764 | Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="") 1765 | { 1766 | if !(w && h) 1767 | DllCall("gdiplus\GdipCreateTexture", "uint", pBitmap, "int", WrapMode, "uint*", pBrush) 1768 | else 1769 | DllCall("gdiplus\GdipCreateTexture2", "uint", pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, "uint*", pBrush) 1770 | return pBrush 1771 | } 1772 | 1773 | ;##################################################################################### 1774 | 1775 | ; WrapModeTile = 0 1776 | ; WrapModeTileFlipX = 1 1777 | ; WrapModeTileFlipY = 2 1778 | ; WrapModeTileFlipXY = 3 1779 | ; WrapModeClamp = 4 1780 | Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1) 1781 | { 1782 | CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2) 1783 | DllCall("gdiplus\GdipCreateLineBrush", "uint", &PointF1, "uint", &PointF2, "int", ARGB1, "int", ARGB2, "int", WrapMode, "uint*", LGpBrush) 1784 | return LGpBrush 1785 | } 1786 | 1787 | ;##################################################################################### 1788 | 1789 | ; LinearGradientModeHorizontal = 0 1790 | ; LinearGradientModeVertical = 1 1791 | ; LinearGradientModeForwardDiagonal = 2 1792 | ; LinearGradientModeBackwardDiagonal = 3 1793 | Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1) 1794 | { 1795 | CreateRectF(RectF, x, y, w, h) 1796 | DllCall("gdiplus\GdipCreateLineBrushFromRect", "uint", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, "uint*", LGpBrush) 1797 | return LGpBrush 1798 | } 1799 | 1800 | ;##################################################################################### 1801 | 1802 | Gdip_CloneBrush(pBrush) 1803 | { 1804 | DllCall("gdiplus\GdipCloneBrush", "uint", pBrush, "uint*", pBrushClone) 1805 | return pBrushClone 1806 | } 1807 | 1808 | ;##################################################################################### 1809 | ; Delete resources 1810 | ;##################################################################################### 1811 | 1812 | Gdip_DeletePen(pPen) 1813 | { 1814 | return DllCall("gdiplus\GdipDeletePen", "uint", pPen) 1815 | } 1816 | 1817 | ;##################################################################################### 1818 | 1819 | Gdip_DeleteBrush(pBrush) 1820 | { 1821 | return DllCall("gdiplus\GdipDeleteBrush", "uint", pBrush) 1822 | } 1823 | 1824 | ;##################################################################################### 1825 | 1826 | Gdip_DisposeImage(pBitmap) 1827 | { 1828 | return DllCall("gdiplus\GdipDisposeImage", "uint", pBitmap) 1829 | } 1830 | 1831 | ;##################################################################################### 1832 | 1833 | Gdip_DeleteGraphics(pGraphics) 1834 | { 1835 | return DllCall("gdiplus\GdipDeleteGraphics", "uint", pGraphics) 1836 | } 1837 | 1838 | ;##################################################################################### 1839 | 1840 | Gdip_DisposeImageAttributes(ImageAttr) 1841 | { 1842 | return DllCall("gdiplus\GdipDisposeImageAttributes", "uint", ImageAttr) 1843 | } 1844 | 1845 | ;##################################################################################### 1846 | 1847 | Gdip_DeleteFont(hFont) 1848 | { 1849 | return DllCall("gdiplus\GdipDeleteFont", "uint", hFont) 1850 | } 1851 | 1852 | ;##################################################################################### 1853 | 1854 | Gdip_DeleteStringFormat(hFormat) 1855 | { 1856 | return DllCall("gdiplus\GdipDeleteStringFormat", "uint", hFormat) 1857 | } 1858 | 1859 | ;##################################################################################### 1860 | 1861 | Gdip_DeleteFontFamily(hFamily) 1862 | { 1863 | return DllCall("gdiplus\GdipDeleteFontFamily", "uint", hFamily) 1864 | } 1865 | 1866 | ;##################################################################################### 1867 | 1868 | Gdip_DeleteMatrix(Matrix) 1869 | { 1870 | return DllCall("gdiplus\GdipDeleteMatrix", "uint", Matrix) 1871 | } 1872 | 1873 | ;##################################################################################### 1874 | ; Text functions 1875 | ;##################################################################################### 1876 | 1877 | Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0) 1878 | { 1879 | IWidth := Width, IHeight:= Height 1880 | 1881 | RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos) 1882 | RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos) 1883 | RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width) 1884 | RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height) 1885 | RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour) 1886 | RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos) 1887 | RegExMatch(Options, "i)NoWrap", NoWrap) 1888 | RegExMatch(Options, "i)R(\d)", Rendering) 1889 | RegExMatch(Options, "i)S(\d+)(p*)", Size) 1890 | 1891 | if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2)) 1892 | PassBrush := 1, pBrush := Colour2 1893 | 1894 | if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2) 1895 | return -1 1896 | 1897 | Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout" 1898 | Loop, Parse, Styles, | 1899 | { 1900 | if RegExMatch(Options, "\b" A_loopField) 1901 | Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8 1902 | } 1903 | 1904 | Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right" 1905 | Loop, Parse, Alignments, | 1906 | { 1907 | if RegExMatch(Options, "\b" A_loopField) 1908 | Align |= A_Index//2.1 ; 0|0|1|1|2|2 1909 | } 1910 | 1911 | xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0 1912 | ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0 1913 | Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth 1914 | Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight 1915 | if !PassBrush 1916 | Colour := "0x" (Colour2 ? Colour2 : "ff000000") 1917 | Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4 1918 | Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12 1919 | 1920 | hFamily := Gdip_FontFamilyCreate(Font) 1921 | hFont := Gdip_FontCreate(hFamily, Size, Style) 1922 | FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000 1923 | hFormat := Gdip_StringFormatCreate(FormatStyle) 1924 | pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour) 1925 | if !(hFamily && hFont && hFormat && pBrush && pGraphics) 1926 | return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0 1927 | 1928 | CreateRectF(RC, xpos, ypos, Width, Height) 1929 | Gdip_SetStringFormatAlign(hFormat, Align) 1930 | Gdip_SetTextRenderingHint(pGraphics, Rendering) 1931 | ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) 1932 | 1933 | if vPos 1934 | { 1935 | StringSplit, ReturnRC, ReturnRC, | 1936 | 1937 | if (vPos = "vCentre") || (vPos = "vCenter") 1938 | ypos += (Height-ReturnRC4)//2 1939 | else if (vPos = "Top") || (vPos = "Up") 1940 | ypos := 0 1941 | else if (vPos = "Bottom") || (vPos = "Down") 1942 | ypos := Height-ReturnRC4 1943 | 1944 | CreateRectF(RC, xpos, ypos, Width, ReturnRC4) 1945 | ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) 1946 | } 1947 | 1948 | if !Measure 1949 | E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC) 1950 | 1951 | if !PassBrush 1952 | Gdip_DeleteBrush(pBrush) 1953 | Gdip_DeleteStringFormat(hFormat) 1954 | Gdip_DeleteFont(hFont) 1955 | Gdip_DeleteFontFamily(hFamily) 1956 | return E ? E : ReturnRC 1957 | } 1958 | 1959 | ;##################################################################################### 1960 | 1961 | Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF) 1962 | { 1963 | if !A_IsUnicode 1964 | { 1965 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0) 1966 | VarSetCapacity(wString, nSize*2) 1967 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize) 1968 | return DllCall("gdiplus\GdipDrawString", "uint", pGraphics 1969 | , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush) 1970 | } 1971 | else 1972 | { 1973 | return DllCall("gdiplus\GdipDrawString", "uint", pGraphics 1974 | , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush) 1975 | } 1976 | } 1977 | 1978 | ;##################################################################################### 1979 | 1980 | Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF) 1981 | { 1982 | VarSetCapacity(RC, 16) 1983 | if !A_IsUnicode 1984 | { 1985 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0) 1986 | VarSetCapacity(wString, nSize*2) 1987 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize) 1988 | DllCall("gdiplus\GdipMeasureString", "uint", pGraphics 1989 | , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines) 1990 | } 1991 | else 1992 | { 1993 | DllCall("gdiplus\GdipMeasureString", "uint", pGraphics 1994 | , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines) 1995 | } 1996 | return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0 1997 | } 1998 | 1999 | ; Near = 0 2000 | ; Center = 1 2001 | ; Far = 2 2002 | Gdip_SetStringFormatAlign(hFormat, Align) 2003 | { 2004 | return DllCall("gdiplus\GdipSetStringFormatAlign", "uint", hFormat, "int", Align) 2005 | } 2006 | 2007 | ; StringFormatFlagsDirectionRightToLeft = 0x00000001 2008 | ; StringFormatFlagsDirectionVertical = 0x00000002 2009 | ; StringFormatFlagsNoFitBlackBox = 0x00000004 2010 | ; StringFormatFlagsDisplayFormatControl = 0x00000020 2011 | ; StringFormatFlagsNoFontFallback = 0x00000400 2012 | ; StringFormatFlagsMeasureTrailingSpaces = 0x00000800 2013 | ; StringFormatFlagsNoWrap = 0x00001000 2014 | ; StringFormatFlagsLineLimit = 0x00002000 2015 | ; StringFormatFlagsNoClip = 0x00004000 2016 | Gdip_StringFormatCreate(Format=0, Lang=0) 2017 | { 2018 | DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, "uint*", hFormat) 2019 | return hFormat 2020 | } 2021 | 2022 | ; Regular = 0 2023 | ; Bold = 1 2024 | ; Italic = 2 2025 | ; BoldItalic = 3 2026 | ; Underline = 4 2027 | ; Strikeout = 8 2028 | Gdip_FontCreate(hFamily, Size, Style=0) 2029 | { 2030 | DllCall("gdiplus\GdipCreateFont", "uint", hFamily, "float", Size, "int", Style, "int", 0, "uint*", hFont) 2031 | return hFont 2032 | } 2033 | 2034 | Gdip_FontFamilyCreate(Font) 2035 | { 2036 | if !A_IsUnicode 2037 | { 2038 | nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", 0, "int", 0) 2039 | VarSetCapacity(wFont, nSize*2) 2040 | DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", &wFont, "int", nSize) 2041 | DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &wFont, "uint", 0, "uint*", hFamily) 2042 | } 2043 | else 2044 | DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &Font, "uint", 0, "uint*", hFamily) 2045 | return hFamily 2046 | } 2047 | 2048 | ;##################################################################################### 2049 | ; Matrix functions 2050 | ;##################################################################################### 2051 | 2052 | Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y) 2053 | { 2054 | DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, "uint*", Matrix) 2055 | return Matrix 2056 | } 2057 | 2058 | Gdip_CreateMatrix() 2059 | { 2060 | DllCall("gdiplus\GdipCreateMatrix", "uint*", Matrix) 2061 | return Matrix 2062 | } 2063 | 2064 | ;##################################################################################### 2065 | ; GraphicsPath functions 2066 | ;##################################################################################### 2067 | 2068 | ; Alternate = 0 2069 | ; Winding = 1 2070 | Gdip_CreatePath(BrushMode=0) 2071 | { 2072 | DllCall("gdiplus\GdipCreatePath", "int", BrushMode, "uint*", Path) 2073 | return Path 2074 | } 2075 | 2076 | Gdip_AddPathEllipse(Path, x, y, w, h) 2077 | { 2078 | return DllCall("gdiplus\GdipAddPathEllipse", "uint", Path, "float", x, "float", y, "float", w, "float", h) 2079 | } 2080 | 2081 | Gdip_AddPathPolygon(Path, Points) 2082 | { 2083 | StringSplit, Points, Points, | 2084 | VarSetCapacity(PointF, 8*Points0) 2085 | Loop, %Points0% 2086 | { 2087 | StringSplit, Coord, Points%A_Index%, `, 2088 | NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") 2089 | } 2090 | 2091 | return DllCall("gdiplus\GdipAddPathPolygon", "uint", Path, "uint", &PointF, "int", Points0) 2092 | } 2093 | 2094 | Gdip_DeletePath(Path) 2095 | { 2096 | return DllCall("gdiplus\GdipDeletePath", "uint", Path) 2097 | } 2098 | 2099 | ;##################################################################################### 2100 | ; Quality functions 2101 | ;##################################################################################### 2102 | 2103 | ; SystemDefault = 0 2104 | ; SingleBitPerPixelGridFit = 1 2105 | ; SingleBitPerPixel = 2 2106 | ; AntiAliasGridFit = 3 2107 | ; AntiAlias = 4 2108 | Gdip_SetTextRenderingHint(pGraphics, RenderingHint) 2109 | { 2110 | return DllCall("gdiplus\GdipSetTextRenderingHint", "uint", pGraphics, "int", RenderingHint) 2111 | } 2112 | 2113 | ; Default = 0 2114 | ; LowQuality = 1 2115 | ; HighQuality = 2 2116 | ; Bilinear = 3 2117 | ; Bicubic = 4 2118 | ; NearestNeighbor = 5 2119 | ; HighQualityBilinear = 6 2120 | ; HighQualityBicubic = 7 2121 | Gdip_SetInterpolationMode(pGraphics, InterpolationMode) 2122 | { 2123 | return DllCall("gdiplus\GdipSetInterpolationMode", "uint", pGraphics, "int", InterpolationMode) 2124 | } 2125 | 2126 | ; Default = 0 2127 | ; HighSpeed = 1 2128 | ; HighQuality = 2 2129 | ; None = 3 2130 | ; AntiAlias = 4 2131 | Gdip_SetSmoothingMode(pGraphics, SmoothingMode) 2132 | { 2133 | return DllCall("gdiplus\GdipSetSmoothingMode", "uint", pGraphics, "int", SmoothingMode) 2134 | } 2135 | 2136 | ; CompositingModeSourceOver = 0 (blended) 2137 | ; CompositingModeSourceCopy = 1 (overwrite) 2138 | Gdip_SetCompositingMode(pGraphics, CompositingMode=0) 2139 | { 2140 | return DllCall("gdiplus\GdipSetCompositingMode", "uint", pGraphics, "int", CompositingMode) 2141 | } 2142 | 2143 | ;##################################################################################### 2144 | ; Extra functions 2145 | ;##################################################################################### 2146 | 2147 | Gdip_Startup() 2148 | { 2149 | if !DllCall("GetModuleHandle", "str", "gdiplus") 2150 | DllCall("LoadLibrary", "str", "gdiplus") 2151 | VarSetCapacity(si, 16, 0), si := Chr(1) 2152 | DllCall("gdiplus\GdiplusStartup", "uint*", pToken, "uint", &si, "uint", 0) 2153 | return pToken 2154 | } 2155 | 2156 | Gdip_Shutdown(pToken) 2157 | { 2158 | DllCall("gdiplus\GdiplusShutdown", "uint", pToken) 2159 | if hModule := DllCall("GetModuleHandle", "str", "gdiplus") 2160 | DllCall("FreeLibrary", "uint", hModule) 2161 | return 0 2162 | } 2163 | 2164 | ; Prepend = 0; The new operation is applied before the old operation. 2165 | ; Append = 1; The new operation is applied after the old operation. 2166 | Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0) 2167 | { 2168 | return DllCall("gdiplus\GdipRotateWorldTransform", "uint", pGraphics, "float", Angle, "int", MatrixOrder) 2169 | } 2170 | 2171 | Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0) 2172 | { 2173 | return DllCall("gdiplus\GdipScaleWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder) 2174 | } 2175 | 2176 | Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0) 2177 | { 2178 | return DllCall("gdiplus\GdipTranslateWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder) 2179 | } 2180 | 2181 | Gdip_ResetWorldTransform(pGraphics) 2182 | { 2183 | return DllCall("gdiplus\GdipResetWorldTransform", "uint", pGraphics) 2184 | } 2185 | 2186 | Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation) 2187 | { 2188 | pi := 3.14159, TAngle := Angle*(pi/180) 2189 | 2190 | Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360) 2191 | if ((Bound >= 0) && (Bound <= 90)) 2192 | xTranslation := Height*Sin(TAngle), yTranslation := 0 2193 | else if ((Bound > 90) && (Bound <= 180)) 2194 | xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle) 2195 | else if ((Bound > 180) && (Bound <= 270)) 2196 | xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle)) 2197 | else if ((Bound > 270) && (Bound <= 360)) 2198 | xTranslation := 0, yTranslation := -Width*Sin(TAngle) 2199 | } 2200 | 2201 | Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight) 2202 | { 2203 | pi := 3.14159, TAngle := Angle*(pi/180) 2204 | if !(Width && Height) 2205 | return -1 2206 | RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle))) 2207 | RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle))) 2208 | } 2209 | 2210 | ; RotateNoneFlipNone = 0 2211 | ; Rotate90FlipNone = 1 2212 | ; Rotate180FlipNone = 2 2213 | ; Rotate270FlipNone = 3 2214 | ; RotateNoneFlipX = 4 2215 | ; Rotate90FlipX = 5 2216 | ; Rotate180FlipX = 6 2217 | ; Rotate270FlipX = 7 2218 | ; RotateNoneFlipY = Rotate180FlipX 2219 | ; Rotate90FlipY = Rotate270FlipX 2220 | ; Rotate180FlipY = RotateNoneFlipX 2221 | ; Rotate270FlipY = Rotate90FlipX 2222 | ; RotateNoneFlipXY = Rotate180FlipNone 2223 | ; Rotate90FlipXY = Rotate270FlipNone 2224 | ; Rotate180FlipXY = RotateNoneFlipNone 2225 | ; Rotate270FlipXY = Rotate90FlipNone 2226 | 2227 | Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1) 2228 | { 2229 | return DllCall("gdiplus\GdipImageRotateFlip", "uint", pBitmap, "int", RotateFlipType) 2230 | } 2231 | 2232 | ; Replace = 0 2233 | ; Intersect = 1 2234 | ; Union = 2 2235 | ; Xor = 3 2236 | ; Exclude = 4 2237 | ; Complement = 5 2238 | Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0) 2239 | { 2240 | return DllCall("gdiplus\GdipSetClipRect", "uint", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode) 2241 | } 2242 | 2243 | Gdip_SetClipPath(pGraphics, Path, CombineMode=0) 2244 | { 2245 | return DllCall("gdiplus\GdipSetClipPath", "uint", pGraphics, "uint", Path, "int", CombineMode) 2246 | } 2247 | 2248 | Gdip_ResetClip(pGraphics) 2249 | { 2250 | return DllCall("gdiplus\GdipResetClip", "uint", pGraphics) 2251 | } 2252 | 2253 | Gdip_GetClipRegion(pGraphics) 2254 | { 2255 | Region := Gdip_CreateRegion() 2256 | DllCall("gdiplus\GdipGetClip", "uint" pGraphics, "uint*", Region) 2257 | return Region 2258 | } 2259 | 2260 | Gdip_SetClipRegion(pGraphics, Region, CombineMode=0) 2261 | { 2262 | return DllCall("gdiplus\GdipSetClipRegion", "uint", pGraphics, "uint", Region, "int", CombineMode) 2263 | } 2264 | 2265 | Gdip_CreateRegion() 2266 | { 2267 | DllCall("gdiplus\GdipCreateRegion", "uint*", Region) 2268 | return Region 2269 | } 2270 | 2271 | Gdip_DeleteRegion(Region) 2272 | { 2273 | return DllCall("gdiplus\GdipDeleteRegion", "uint", Region) 2274 | } 2275 | 2276 | ;##################################################################################### 2277 | ; BitmapLockBits 2278 | ;##################################################################################### 2279 | 2280 | Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a) 2281 | { 2282 | CreateRect(Rect, x, y, w, h) 2283 | VarSetCapacity(BitmapData, 21, 0) 2284 | E := DllCall("Gdiplus\GdipBitmapLockBits", "uint", pBitmap, "uint", &Rect, "uint", LockMode, "int", PixelFormat, "uint", &BitmapData) 2285 | Stride := NumGet(BitmapData, 8) 2286 | Scan0 := NumGet(BitmapData, 16) 2287 | return E 2288 | } 2289 | 2290 | ;##################################################################################### 2291 | 2292 | Gdip_UnlockBits(pBitmap, ByRef BitmapData) 2293 | { 2294 | return DllCall("Gdiplus\GdipBitmapUnlockBits", "uint", pBitmap, "uint", &BitmapData) 2295 | } 2296 | 2297 | ;##################################################################################### 2298 | 2299 | Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride) 2300 | { 2301 | Numput(ARGB, Scan0+0, (x*4)+(y*Stride)) 2302 | } 2303 | 2304 | ;##################################################################################### 2305 | 2306 | Gdip_GetLockBitPixel(Scan0, x, y, Stride) 2307 | { 2308 | return NumGet(Scan0+0, (x*4)+(y*Stride)) 2309 | } 2310 | 2311 | ;##################################################################################### 2312 | 2313 | Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize) 2314 | { 2315 | static PixelateBitmap 2316 | if !PixelateBitmap 2317 | { 2318 | MCode_PixelateBitmap := "83EC388B4424485355568B74245C99F7FE8B5C244C8B6C2448578BF88BCA894C241C897C243485FF0F8E2E0300008B44245" 2319 | . "499F7FE897C24448944242833C089542418894424308944242CEB038D490033FF397C2428897C24380F8E750100008BCE0FAFCE894C24408DA4240000" 2320 | . "000033C03BF08944241089442460894424580F8E8A0000008B5C242C8D4D028BD52BD183C203895424208D3CBB0FAFFE8BD52BD142895424248BD52BD" 2321 | . "103F9897C24148974243C8BCF8BFE8DA424000000008B5C24200FB61C0B03C30FB619015C24588B5C24240FB61C0B015C24600FB61C11015C241083C1" 2322 | . "0483EF0175D38B7C2414037C245C836C243C01897C241475B58B7C24388B6C244C8B5C24508B4C244099F7F9894424148B44245899F7F9894424588B4" 2323 | . "4246099F7F9894424608B44241099F7F98944241085F60F8E820000008D4B028BC32BC18D68038B44242C8D04B80FAFC68BD32BD142895424248BD32B" 2324 | . "D103C18944243C89742420EB038D49008BC88BFE0FB64424148B5C24248804290FB644245888010FB644246088040B0FB644241088040A83C10483EF0" 2325 | . "175D58B44243C0344245C836C2420018944243C75BE8B4C24408B5C24508B6C244C8B7C2438473B7C2428897C24380F8C9FFEFFFF8B4C241C33D23954" 2326 | . "24180F846401000033C03BF2895424108954246089542458895424148944243C0F8E82000000EB0233D2395424187E6F8B4C243003C80FAF4C245C8B4" 2327 | . "424280FAFC68D550203CA8D0C818BC52BC283C003894424208BC52BC2408BFD2BFA8B54241889442424895424408B4424200FB614080FB60101542414" 2328 | . "8B542424014424580FB6040A0FB61439014424600154241083C104836C24400175CF8B44243C403BC68944243C7C808B4C24188B4424140FAFCE99F7F" 2329 | . "9894424148B44245899F7F9894424588B44246099F7F9894424608B44241099F7F98944241033C08944243C85F60F8E7F000000837C2418007E6F8B4C" 2330 | . "243003C80FAF4C245C8B4424280FAFC68D530203CA8D0C818BC32BC283C003894424208BC32BC2408BFB2BFA8B54241889442424895424400FB644241" 2331 | . "48B5424208804110FB64424580FB654246088018B4424248814010FB654241088143983C104836C24400175CF8B44243C403BC68944243C7C818B4C24" 2332 | . "1C8B44245C0144242C01742430836C2444010F85F4FCFFFF8B44245499F7FE895424188944242885C00F8E890100008BF90FAFFE33D2897C243C89542" 2333 | . "45489442438EB0233D233C03BCA89542410895424608954245889542414894424400F8E840000003BF27E738B4C24340FAFCE03C80FAF4C245C034C24" 2334 | . "548D55028BC52BC283C003894424208BC52BC2408BFD03CA894424242BFA89742444908B5424200FB6040A0FB611014424148B442424015424580FB61" 2335 | . "4080FB6040F015424600144241083C104836C24440175CF8B4424408B7C243C8B4C241C33D2403BC1894424400F8C7CFFFFFF8B44241499F7FF894424" 2336 | . "148B44245899F7FF894424588B44246099F7FF894424608B44241099F7FF8944241033C08944244085C90F8E8000000085F67E738B4C24340FAFCE03C" 2337 | . "80FAF4C245C034C24548D53028BC32BC283C003894424208BC32BC2408BFB03CA894424242BFA897424448D49000FB65424148B4424208814010FB654" 2338 | . "24580FB644246088118B5424248804110FB644241088043983C104836C24440175CF8B4424408B7C243C8B4C241C403BC1894424407C808D04B500000" 2339 | . "00001442454836C2438010F858CFEFFFF33D233C03BCA89542410895424608954245889542414894424440F8E9A000000EB048BFF33D2395424180F8E" 2340 | . "7D0000008B4C24340FAFCE03C80FAF4C245C8B4424280FAFC68D550203CA8D0C818BC52BC283C003894424208BC52BC240894424248BC52BC28B54241" 2341 | . "8895424548DA424000000008B5424200FB6140A015424140FB611015424588B5424240FB6140A015424600FB614010154241083C104836C24540175CF" 2342 | . "8B4424448B4C241C403BC1894424440F8C6AFFFFFF0FAF4C24188B44241499F7F9894424148B44245899F7F9894424588B44246099F7F9894424608B4" 2343 | . "4241099F7F98944241033C03944241C894424540F8E7B0000008B7C241885FF7E688B4C24340FAFCE03C80FAF4C245C8B4424280FAFC68D530203CA8D" 2344 | . "0C818BC32BC283C003894424208BC32BC2408BEB894424242BEA0FB65424148B4424208814010FB65424580FB644246088118B5424248804110FB6442" 2345 | . "41088042983C10483EF0175D18B442454403B44241C894424547C855F5E5D33C05B83C438C3" 2346 | VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2) 2347 | Loop % StrLen(MCode_PixelateBitmap)//2 ;% 2348 | NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "char") 2349 | } 2350 | 2351 | Gdip_GetImageDimensions(pBitmap, Width, Height) 2352 | if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut)) 2353 | return -1 2354 | if (BlockSize > Width || BlockSize > Height) 2355 | return -2 2356 | 2357 | E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1) 2358 | E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2) 2359 | if (E1 || E2) 2360 | return -3 2361 | 2362 | E := DllCall(&PixelateBitmap, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize) 2363 | Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2) 2364 | return 0 2365 | } 2366 | 2367 | ;##################################################################################### 2368 | 2369 | Gdip_ToARGB(A, R, G, B) 2370 | { 2371 | return (A << 24) | (R << 16) | (G << 8) | B 2372 | } 2373 | 2374 | ;##################################################################################### 2375 | 2376 | Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B) 2377 | { 2378 | A := (0xff000000 & ARGB) >> 24 2379 | R := (0x00ff0000 & ARGB) >> 16 2380 | G := (0x0000ff00 & ARGB) >> 8 2381 | B := 0x000000ff & ARGB 2382 | } 2383 | 2384 | ;##################################################################################### 2385 | 2386 | Gdip_AFromARGB(ARGB) 2387 | { 2388 | return (0xff000000 & ARGB) >> 24 2389 | } 2390 | 2391 | ;##################################################################################### 2392 | 2393 | Gdip_RFromARGB(ARGB) 2394 | { 2395 | return (0x00ff0000 & ARGB) >> 16 2396 | } 2397 | 2398 | ;##################################################################################### 2399 | 2400 | Gdip_GFromARGB(ARGB) 2401 | { 2402 | return (0x0000ff00 & ARGB) >> 8 2403 | } 2404 | 2405 | ;##################################################################################### 2406 | 2407 | Gdip_BFromARGB(ARGB) 2408 | { 2409 | return 0x000000ff & ARGB 2410 | } --------------------------------------------------------------------------------