-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWindowSnipping.ahk
More file actions
2032 lines (1721 loc) · 71.1 KB
/
WindowSnipping.ahk
File metadata and controls
2032 lines (1721 loc) · 71.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#NoEnv
#SingleInstance Force
#Requires Autohotkey v1.1.36+ 32-bit Unicode
;--
;@Ahk2Exe-SetVersion 1.57.14
;@Ahk2Exe-SetProductName Window Snipping Tool
;@Ahk2Exe-SetDescription Allows to take quick screenshots and perform OCR with hotkeys
/**
* ============================================================================ *
* Want a clear path for learning AutoHotkey? *
* Take a look at our AutoHotkey courses. *
* They're structured in a way to make learning AHK EASY *
* Discover how easy AutoHotkey is here: https://the-Automator.com/Discover *
* ============================================================================ *
*/
#include <ScriptObj/ScriptObj>
DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")
if (A_OSVersion ~= "10\.")
appdata := A_AppData "\" RegexReplace(A_ScriptName, "\.\w+"), isWin10 := true
else
appdata := A_ScriptDir
global script := {base : script
,name : RegexReplace(A_ScriptName, "\.\w+")
,version : "1.57.14"
,author : "Joe Glines"
,email : "joe@the-automator.com"
,homepagetext : "www.the-automator.com/snip"
,homepagelink : "www.the-automator.com/snip?src=app"
,donateLink : "https://the-automator.com/PayPal"
,resfolder : appdata "\res"
,iconfile : appdata "\res\sct.ico"
,configfolder : appdata
,configfile : appdata "\settings.ini"}
/* ; Credits I borrowed heavily from ...
Screen clipping by Learning one https://autohotkey.com/boards/viewtopic.php?f=6&t=12088
OCR by malcev https://www.autohotkey.com/boards/viewtopic.php?f=6&t=72674
*/
if !fileExist(script.resfolder)
|| !FileExist(script.iconfile)
{
FileCreateDir, % script.resfolder
FileInstall, res\sct.ico, % script.iconfile
}
;@Ahk2Exe-SetMainIcon res\sct.ico
Menu, Tray, Icon, % script.iconfile
;~ Menu,Tray,Add,"Windows and left mouse click"
IniRead, ShowUsage, % script.configfile, Settings, ShowUsage, % true
IniRead, SWW, % script.configfile, Settings, StartWithWindows
Menu, Tray, Tip, Window Snipping Tool
Menu, Tray, NoStandard ;removes default options
Menu, Tray, Add ; to divide from standard menu, remove when above line is uncommented
Menu, Tray, Add, Hotkeys, HotkeysGUI
Menu, Tray, Add, Email Signature, SignatureGUI
Menu, Tray, Add
Menu, Tray, Add, Show Usage at Startup, ShowUsageSet
Menu, Tray, % ShowUsage ? "Check" : "Uncheck", Show Usage at Startup
Menu, Tray, Add
Menu, Tray, Add, Clear Settings, ClearSettings
Menu, Tray, Add, Check for Updates, Update
Menu, Tray, Add, About, AboutGUI
Menu, Tray, Add
Menu, Tray, Add,Reload,Reload
Menu, Tray, Add,Exit App,Exit
Menu, Tray, Default, Hotkeys
if (!FileExist(script.configfile))
{
FileCreateDir % RegexReplace(script.configfile, "^(.*)\\([^\\]*)$", "$1")
FileAppend,, % script.configfile, UTF-8-RAW
IniWrite, % true, % script.configfile, Settings, FirstRun
IniWrite, % true, % script.configfile, Settings, ShowUsage
IniWrite, % true, % script.configfile, Settings, StartWithWindows
Gosub HotkeysGUI
}
else
{
IniWrite, % false, % script.configfile, Settings, FirstRun
Gosub SetHotkeys
}
if (ShowUsage)
Gosub ShowUsageGUI
return
;===Functions==========================================================================
UriEncode(Uri, Enc = "UTF-8"){
StrPutVar(Uri, Var, Enc)
f := A_FormatInteger
SetFormat, IntegerFast, H
Loop
{
Code := NumGet(Var, A_Index - 1, "UChar")
If (!Code)
Break
If (Code >= 0x30 && Code <= 0x39 ; 0-9
|| Code >= 0x41 && Code <= 0x5A ; A-Z
|| Code >= 0x61 && Code <= 0x7A) ; a-z
Res .= Chr(Code)
Else
Res .= "%" . SubStr(Code + 0x100, -1)
}
SetFormat, IntegerFast, %f%
Return, Res
}
StrPutVar(Str, ByRef Var, Enc = ""){
Len := StrPut(Str, Enc) * (Enc = "UTF-16" || Enc = "CP1200" ? 2 : 1)
VarSetCapacity(Var, Len, 0)
Return, StrPut(Str, &Var, Enc)
}
SCW_DestroyAllClipWins() {
MaxGuis := SCW_Reg("MaxGuis"), StartAfter := SCW_Reg("StartAfter")
Loop, %MaxGuis% {
StartAfter++
Gui %StartAfter%: Destroy
}
}
SCW_SetUp(Options="") {
if !(Options = "") {
Loop, Parse, Options, %A_Space%
{
Field := A_LoopField
DotPos := InStr(Field, ".")
if (DotPos = 0)
Continue
var := SubStr(Field, 1, DotPos-1)
val := SubStr(Field, DotPos+1)
if var in StartAfter,MaxGuis,AutoMonitorWM_LBUTTONDOWN,DrawCloseButton,BorderAColor,BorderBColor,SelColor,SelTrans
%var% := val
}
}
SCW_Default(StartAfter,80), SCW_Default(MaxGuis,6) ;limit the # of snippets
SCW_Default(AutoMonitorWM_LBUTTONDOWN,1), SCW_Default(DrawCloseButton,0)
SCW_Default(BorderAColor,"ff6666ff"), SCW_Default(BorderBColor,"ffffffff")
SCW_Default(SelColor,"Yellow"), SCW_Default(SelTrans,80)
SCW_Reg("MaxGuis", MaxGuis), SCW_Reg("StartAfter", StartAfter), SCW_Reg("DrawCloseButton", DrawCloseButton)
SCW_Reg("BorderAColor", BorderAColor), SCW_Reg("BorderBColor", BorderBColor)
SCW_Reg("SelColor", SelColor), SCW_Reg("SelTrans",SelTrans)
SCW_Reg("WasSetUp", 1)
if AutoMonitorWM_LBUTTONDOWN
OnMessage(0x201, "SCW_LBUTTONDOWN")
}
SCW_ScreenClip2Win(clip=0,email=0,OCR=0) {
static c
static MONITOR_DEFAULTTOPRIMARY := 0x00000001
static MONITOR_DEFAULTTONEAREST := 0x00000002
global defaultSignature, origText
if !(SCW_Reg("WasSetUp"))
SCW_SetUp()
StartAfter := SCW_Reg("StartAfter"), MaxGuis := SCW_Reg("MaxGuis"), SelColor := SCW_Reg("SelColor"), SelTrans := SCW_Reg("SelTrans")
c++
if (c > MaxGuis)
c := 1
GuiNum := StartAfter + c
Area := SCW_SelectAreaMod("g" GuiNum " c" SelColor " t" SelTrans)
StringSplit, v, Area, |
DetectHiddenWindows, On
Gui %GuiNum%:+LastFound
$hWin := WinExist()
; WinGetPos X, Y, Width, Height, ahk_id %hWin%
; we cannot get the activewindow does not deactive previous window
; MouseGetPos, ,, $Hwnd1
; if !hMonPrimary := DllCall("MonitorFromWindow", "ptr", 0, "int", MONITOR_DEFAULTTOPRIMARY)
; Throw, Exception("couldnt get the monitor handle", A_ThisFunc)
; ; Get the scale factor for the primary monitor
; DllCall("Shcore.dll\GetScaleFactorForMonitor"
; , "ptr", hMonPrimary ; [in] HMONITOR hMon,
; , "ptr*", pScalePrimary) ; [out] DEVICE_SCALE_FACTOR *pScale
; pScalePrimary /= (A_ScreenDPI / 96) * 100.0
; if !hMon := DllCall("MonitorFromWindow", "ptr", $hwnd1, "int", MONITOR_DEFAULTTONEAREST)
; Throw, Exception("couldnt get the monitor handle", A_ThisFunc, $hwnd1)
; ; Get the scale factor for the screenshot monitor
; DllCall("Shcore.dll\GetScaleFactorForMonitor"
; , "ptr", hMon ; [in] HMONITOR hMon,
; , "ptr*", pScale) ; [out] DEVICE_SCALE_FACTOR *pScale
; pScale /= (A_ScreenDPI / 96) * 100.0
; ; ; Calculate the relative scale factor
; relativeScaleFactor := pScale / pScalePrimary
; Scale the coordinates using the relative scale factor
scaled_v1 := v1 ; * relativeScaleFactor
scaled_v2 := v2 ; * relativeScaleFactor
scaled_v3 := v3 ; * relativeScaleFactor
scaled_v4 := v4 ; * relativeScaleFactor
scaled_area := scaled_v1 "|" scaled_v2 "|" scaled_v3 "|" scaled_v4
; scaled_area := x "|" y "|" Width "|" Height
if (v3 < 10 and v4 < 10) ; too small area
return
pToken := Gdip_Startup()
if (! pToken ) {
MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.
return
}
Sleep, 100
if !pBitmap := Gdip_BitmapFromScreen(scaled_area){
MsgBox, 64, GDI+ error, GDI+ failed to create a Bitmap from screen.
return
}
if (OCR)
{
hBitmap:=Gdip_CreateHBITMAPFromBitmap(pBitmap) ;Convert an hBitmap from the pBitmap
pIRandomAccessStream := HBitmapToRandomAccessStream(hBitmap) ;OCR function needs a randome access stream (so it isn't "locked down")
DllCall("DeleteObject", "Ptr", hBitmap)
IniRead, currLang, % script.configfile, OCR, lang, en
Clipboard:=ocr(pIRandomAccessStream, currLang)
ObjRelease(pIRandomAccessStream)
if (!Clipboard)
MsgBox % 0x10, % "Error"
, % "No text was captured by the OCR engine.`nPlease Try again."
else if (Clipboard != "error")
{
ToolTip, % Clipboard
if (OCR == 2)
{
IniRead, currLang, % script.configfile, OCR, lang, en
IniRead, tgtlang, % script.configfile, OCR, tgtlang, en
Run % "https://translate.google.com/?sl=" currLang "&tl=" tgtlang "&text=" UriEncode(Clipboard) "&op=translate"
}
}
Gdip_Shutdown("pToken") ;clear selection
sleep 2000
ToolTip
return
}
if (email=1){
;**********************Added to automatically save to bmp*********************************
File1:=A_ScriptDir . "\example.BMP" ;path to file to save (make sure uppercase extenstion. see below for options
Gdip_SaveBitmapToFile(pBitmap, File1) ;Saves file as bmp
File2:=A_ScriptDir . "\example.JPG" ;path to file to save (make sure uppercase extenstion. see below for options
Gdip_SaveBitmapToFile(pBitmap, File2) ;Exports automatcially to file
Clipboard:=File2 ;Set the clipboard with path to jpg file by default
;**********************make sure outlook is running so email will be sent*********************************
Process, Exist, Outlook.exe ; check to see if Outlook is running.
Outlook_pid=%errorLevel% ; errorlevel equals the PID if active
If (Outlook_pid = 0) { ;
; run outlook.exe
; WinWait, Microsoft Outlook, ,3
MsgBox, % 0x40
, % "Outlook is not open"
, % "For this feature to work correctly you should open Outlook.`n`n"
. "After is open try using the hotkey again."
return
}
;**********************Write email*********************************
olMailItem := 0
try IsObject(MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem)) ; Get the Outlook application object if Outlook is open
catch
MailItem := ComObjCreate("Outlook.Application").CreateItem(olMailItem) ; Create if Outlook is not open
olFormatHTML := 2
MailItem.BodyFormat := olFormatHTML
;~ MailItem.TO := (MailTo)
;~ MailItem.CC :="glines@ti.com"
FormatTime, TodayDate , YYYYMMDDHH24MISS, dddd MMMM d, yyyy h:mm:ss tt
MailItem.Subject :="Screen shot taken : " (TodayDate) ;Subject line of email
if (FileExist(script.configfile))
IniRead, currSig, % script.configfile, Email, signature
if (!currSig || currSig == "ERROR")
currSig := defaultSignature
StringReplace, currSig, currSig, |, `n, All
StringReplace, currSig, currSig, `%date`%, %TodayDate%, All
StringReplace, currSig, currSig, </HTML>,
(LTrim
<br>
This email and screen clipping was created from WindowsSnipping Tool by <a href="https://www.the-automator.com/snip?src=app">the-Automator</a>.
</HTML>
), All
MailItem.HTMLBody := currSig
IniRead, currImg, % script.configfile, Email, images
if (!currImg || currImg == "ERROR")
currImg := 11
file := StrSplit(currImg)
if (file[1])
MailItem.Attachments.Add(File1)
if (file[2])
MailItem.Attachments.Add(File2)
MailItem.Display
; Reload
}
;*******************************************************
SCW_CreateLayeredWinMod(GuiNum,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
Gdip_Shutdown("pToken")
if (clip=1){
;********************** added to copy to clipboard by default*********************************
SCW_Win2Clipboard(0) ;copies to clipboard by default w/o border
;*******************************************************
}
}
SCW_SelectAreaMod(Options="") {
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
loop, parse, Options, %A_Space%
{
Field := A_LoopField
FirstChar := SubStr(Field,1,1)
if FirstChar contains c,t,g,m
{
StringTrimLeft, Field, Field, 1
%FirstChar% := Field
}
}
c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound -DPIScale ;provided from rommmcek 10/23/16
WinSet, Transparent, %t%
Gui %g%: Color, %c%
Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
While, (GetKeyState(Hotkey, "p")) {
Sleep, 10
MouseGetPos, MXend, MYend
w := abs(MX - MXend), h := abs(MY - MYend)
X := (MX < MXend) ? MX : MXend
Y := (MY < MYend) ? MY : MYend
Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
}
Gui %g%: Destroy
MouseGetPos, MXend, MYend
If ( MX > MXend )
temp := MX, MX := MXend, MXend := temp
If ( MY > MYend )
temp := MY, MY := MYend, MYend := temp
Return MX "|" MY "|" w "|" h
}
SCW_CreateLayeredWinMod(GuiNum,pBitmap,x,y,DrawCloseButton=0) {
static CloseButton := 16
BorderAColor := SCW_Reg("BorderAColor"), BorderBColor := SCW_Reg("BorderBColor")
; IniRead, ClipBorder, % script.configfile, Settings, ClipBorder, % false
Gui %GuiNum%: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs -DPIScale
Gui %GuiNum%: Show, Na, ScreenClippingWindow
WinWait, ScreenClippingWindow
hwnd := WinExist()
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
hbm := CreateDIBSection(Width+6, Height+6), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 3, 3, Width, Height)
Gdip_DisposeImage(pBitmap)
pPen1 := Gdip_CreatePen("0x" BorderAColor, 3), pPen2 := Gdip_CreatePen("0x" BorderBColor, 1)
if DrawCloseButton {
Gdip_DrawRectangle(G, pPen1, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
Gdip_DrawRectangle(G, pPen2, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
}
Gdip_DrawRectangle(G, pPen1, 1, 1, Width+3, Height+3)
Gdip_DrawRectangle(G, pPen2, 1, 1, Width+3, Height+3)
Gdip_DeletePen(pPen1), Gdip_DeletePen(pPen2)
UpdateLayeredWindow(hwnd, hdc, x-3, y-3, Width+6, Height+6)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
SCW_Reg("G" GuiNum "#HWND", hwnd)
SCW_Reg("G" GuiNum "#XClose", Width+6-CloseButton)
SCW_Reg("G" GuiNum "#YClose", CloseButton)
Return hwnd
}
SCW_LBUTTONDOWN() {
MouseGetPos,,, WinUMID
WinGetTitle, Title, ahk_id %WinUMID%
if (Title = "ScreenClippingWindow") {
PostMessage, 0xA1, 2,,, ahk_id %WinUMID%
KeyWait, Lbutton
CoordMode, mouse, Relative
MouseGetPos, x,y
XClose := SCW_Reg("G" A_Gui "#XClose"), YClose := SCW_Reg("G" A_Gui "#YClose")
if (x > XClose and y < YClose)
Gui %A_Gui%: Destroy
return 1 ; confirm that click was on module's screen clipping windows
}
}
SCW_Reg(variable, value="") {
static
if (value = "") {
yaqxswcdevfr := kxucfp%variable%pqzmdk
Return yaqxswcdevfr
} Else
kxucfp%variable%pqzmdk = %value%
}
SCW_Default(ByRef Variable,DefaultValue) {
if (Variable="")
Variable := DefaultValue
}
SCW_Win2Clipboard(KeepBorders=0) {
#WinActivateForce
WinActivate, ScreenClippingWindow ahk_class AutoHotkeyGUI ;activates last clipped window
Clipboard := ""
Send, !{PrintScreen} ; Active Win's client area to Clipboard
ClipWait, 0
if !KeepBorders {
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromClipboard()
Gdip_GetDimensions(pBitmap, w, h)
pBitmap2 := SCW_CropImage(pBitmap, 3, 3, w-6, h-6)
Gdip_SetBitmapToClipboard(pBitmap2)
Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap2)
Gdip_Shutdown("pToken")
}
}
SCW_CropImage(pBitmap, x, y, w, h) {
pBitmap2 := Gdip_CreateBitmap(w, h), G2 := Gdip_GraphicsFromImage(pBitmap2)
Gdip_DrawImage(G2, pBitmap, 0, 0, w, h, x, y, w, h)
Gdip_DeleteGraphics(G2)
return pBitmap2
}
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255){
if ((x != "") && (y != ""))
VarSetCapacity(pt, 8), NumPut(x, pt, 0), NumPut(y, pt, 4)
if (w = "") ||(h = "")
WinGetPos,,, w, h, ahk_id %hwnd%
return DllCall("UpdateLayeredWindow", "uint", hwnd, "uint", 0, "uint", ((x = "") && (y = "")) ? 0 : &pt, "int64*", w|h<<32, "uint", hdc, "int64*", 0, "uint", 0, "uint*", Alpha<<16|1<<24, "uint", 2)
}
BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster=""){
return DllCall("gdi32\BitBlt", "uint", dDC, "int", dx, "int", dy, "int", dw, "int", dh, "uint", sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020)
}
StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster=""){
return DllCall("gdi32\StretchBlt", "uint", ddc, "int", dx, "int", dy, "int", dw, "int", dh, "uint", sdc, "int", sx, "int", sy, "int", sw, "int", sh, "uint", Raster ? Raster : 0x00CC0020)
}
SetStretchBltMode(hdc, iStretchMode=4){
return DllCall("gdi32\SetStretchBltMode", "uint", hdc, "int", iStretchMode)
}
SetImage(hwnd, hBitmap){
SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
E := ErrorLevel
DeleteObject(E)
return E
}
SetSysColorToControl(hwnd, SysColor=15){
WinGetPos,,, w, h, ahk_id %hwnd%
bc := DllCall("GetSysColor", "Int", SysColor)
pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
SetImage(hwnd, hBitmap)
Gdip_DeleteBrush(pBrushClear)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
return 0
}
Gdip_BitmapFromScreen(Screen=0, Raster=""){
if (Screen = 0) {
Sysget, x, 76
Sysget, y, 77
Sysget, w, 78
Sysget, h, 79
} else if (Screen&1 != "") {
Sysget, M, Monitor, %Screen%
x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
} else {
StringSplit, S, Screen, |
x := S1, y := S2, w := S3, h := S4
}
if (x = "") || (y = "") || (w = "") || (h = "")
return -1
chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := GetDC()
BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
ReleaseDC(hhdc)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(hhdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
return pBitmap
}
Gdip_BitmapFromHWND(hwnd){
WinGetPos,,, Width, Height, ahk_id %hwnd%
hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
PrintWindow(hwnd, hdc)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
return pBitmap
}
CreateRectF(ByRef RectF, x, y, w, h){
VarSetCapacity(RectF, 16)
NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
}
CreateSizeF(ByRef SizeF, w, h){
VarSetCapacity(SizeF, 8)
NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")
}
CreatePointF(ByRef PointF, x, y){
VarSetCapacity(PointF, 8)
NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0){
hdc2 := hdc ? hdc : GetDC()
VarSetCapacity(bi, 40, 0)
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")
hbm := DllCall("CreateDIBSection", "uint" , hdc2, "uint" , &bi, "uint" , 0, "uint*", ppvBits, "uint" , 0, "uint" , 0)
If !hdc
ReleaseDC(hdc2)
return hbm
}
PrintWindow(hwnd, hdc, Flags=0){
return DllCall("PrintWindow", "uint", hwnd, "uint", hdc, "uint", Flags)
}
DestroyIcon(hIcon){
return DllCall("DestroyIcon", "uint", hIcon)
}
PaintDesktop(hdc){
return DllCall("PaintDesktop", "uint", hdc)
}
CreateCompatibleBitmap(hdc, w, h){
return DllCall("gdi32\CreateCompatibleBitmap", "uint", hdc, "int", w, "int", h)
}
CreateCompatibleDC(hdc=0){
return DllCall("CreateCompatibleDC", "uint", hdc)
}
SelectObject(hdc, hgdiobj){
return DllCall("SelectObject", "uint", hdc, "uint", hgdiobj)
}
DeleteObject(hObject){
return DllCall("DeleteObject", "uint", hObject)
}
GetDC(hwnd=0){
return DllCall("GetDC", "uint", hwnd)
}
ReleaseDC(hdc, hwnd=0){
return DllCall("ReleaseDC", "uint", hwnd, "uint", hdc)
}
DeleteDC(hdc){
return DllCall("DeleteDC", "uint", hdc)
}
Gdip_LibraryVersion(){
return 1.38
}
Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0){
if !BRAFromMemIn
return -1
Loop, Parse, BRAFromMemIn, `n
{
if (A_Index = 1) {
StringSplit, Header, A_LoopField, |
if (Header0 != 4 || Header2 != "BRA!")
return -2
}
else if (A_Index = 2) {
StringSplit, Info, A_LoopField, |
if (Info0 != 3)
return -3
} else
break
}
if !Alternate
StringReplace, File, File, \, \\, All
RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
if !FileInfo
return -4
hData := DllCall("GlobalAlloc", "uint", 2, "uint", FileInfo2)
pData := DllCall("GlobalLock", "uint", hData)
DllCall("RtlMoveMemory", "uint", pData, "uint", &BRAFromMemIn+Info2+FileInfo1, "uint", FileInfo2)
DllCall("GlobalUnlock", "uint", hData)
DllCall("ole32\CreateStreamOnHGlobal", "uint", hData, "int", 1, "uint*", pStream)
DllCall("gdiplus\GdipCreateBitmapFromStream", "uint", pStream, "uint*", pBitmap)
DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
return pBitmap
}
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h){
return DllCall("gdiplus\GdipDrawRectangle", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r){
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
Gdip_ResetClip(pGraphics)
Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
Gdip_ResetClip(pGraphics)
return E
}
Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h){
return DllCall("gdiplus\GdipDrawEllipse", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4){
return DllCall("gdiplus\GdipDrawBezier", "uint", pgraphics, "uint", pPen, "float", x1, "float", y1, "float", x2, "float", y2, "float", x3, "float", y3, "float", x4, "float", y4)
}
Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
return DllCall("gdiplus\GdipDrawArc", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
return DllCall("gdiplus\GdipDrawPie", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2){
return DllCall("gdiplus\GdipDrawLine", "uint", pGraphics, "uint", pPen, "float", x1, "float", y1, "float", x2, "float", y2)
}
Gdip_DrawLines(pGraphics, pPen, Points){
StringSplit, Points, Points, |
VarSetCapacity(PointF, 8*Points0)
Loop, %Points0% {
StringSplit, Coord, Points%A_Index%, `,
NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
}
return DllCall("gdiplus\GdipDrawLines", "uint", pGraphics, "uint", pPen, "uint", &PointF, "int", Points0)
}
Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h){
return DllCall("gdiplus\GdipFillRectangle", "uint", pGraphics, "int", pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r){
Region := Gdip_GetClipRegion(pGraphics)
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_DeleteRegion(Region)
return E
}
Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0){
StringSplit, Points, Points, |
VarSetCapacity(PointF, 8*Points0)
Loop, %Points0% {
StringSplit, Coord, Points%A_Index%, `,
NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
}
return DllCall("gdiplus\GdipFillPolygon", "uint", pGraphics, "uint", pBrush, "uint", &PointF, "int", Points0, "int", FillMode)
}
Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle){
return DllCall("gdiplus\GdipFillPie", "uint", pGraphics, "uint", pBrush, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h){
return DllCall("gdiplus\GdipFillEllipse", "uint", pGraphics, "uint", pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRegion(pGraphics, pBrush, Region){
return DllCall("gdiplus\GdipFillRegion", "uint", pGraphics, "uint", pBrush, "uint", Region)
}
Gdip_FillPath(pGraphics, pBrush, Path){
return DllCall("gdiplus\GdipFillPath", "uint", pGraphics, "uint", pBrush, "uint", Path)
}
Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1){
StringSplit, Points, Points, |
VarSetCapacity(PointF, 8*Points0)
Loop, %Points0%
{
StringSplit, Coord, Points%A_Index%, `,
NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
}
if (Matrix&1 = "")
ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
else if (Matrix != 1)
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")
if (sx = "" && sy = "" && sw = "" && sh = ""){
sx := 0, sy := 0,sw := Gdip_GetImageWidth(pBitmap),sh := Gdip_GetImageHeight(pBitmap)
}
E := DllCall("gdiplus\GdipDrawImagePointsRect","uint",pGraphics,"uint",pBitmap,"uint",&PointF,"int",Points0,"float",sx,"float",sy,"float",sw,"float",sh,"int",2,"uint", ImageAttr, "uint", 0, "uint", 0)
if ImageAttr
Gdip_DisposeImageAttributes(ImageAttr)
return E
}
Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1){
if (Matrix&1 = "")
ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
else if (Matrix != 1)
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")
if (sx = "" && sy = "" && sw = "" && sh = "") {
if (dx = "" && dy = "" && dw = "" && dh = "") {
sx := dx := 0, sy := dy := 0,sw :=dw:=Gdip_GetImageWidth(pBitmap),sh := dh := Gdip_GetImageHeight(pBitmap)
} else {
sx := sy := 0, sw := Gdip_GetImageWidth(pBitmap),sh := Gdip_GetImageHeight(pBitmap)
}
}
E := DllCall("gdiplus\GdipDrawImageRectRect","uint", pGraphics,"uint",pBitmap,"float",dx,"float",dy,"float",dw,"float", dh,"float",sx,"float",sy,"float", sw, "float",sh,"int", 2, "uint", ImageAttr, "uint", 0, "uint", 0)
if ImageAttr
Gdip_DisposeImageAttributes(ImageAttr)
return E
}
Gdip_SetImageAttributesColorMatrix(Matrix){
VarSetCapacity(ColourMatrix, 100, 0)
Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
StringSplit, Matrix, Matrix, |
Loop, 25 {
Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
}
DllCall("gdiplus\GdipCreateImageAttributes", "uint*", ImageAttr)
DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "uint", ImageAttr, "int", 1, "int", 1, "uint", &ColourMatrix, "int", 0, "int", 0)
return ImageAttr
}
Gdip_GraphicsFromImage(pBitmap){
DllCall("gdiplus\GdipGetImageGraphicsContext", "uint", pBitmap, "uint*", pGraphics)
return pGraphics
}
Gdip_GraphicsFromHDC(hdc){
DllCall("gdiplus\GdipCreateFromHDC", "uint", hdc, "uint*", pGraphics)
return pGraphics
}
Gdip_GetDC(pGraphics){
DllCall("gdiplus\GdipGetDC", "uint", pGraphics, "uint*", hdc)
return hdc
}
Gdip_ReleaseDC(pGraphics, hdc){
return DllCall("gdiplus\GdipReleaseDC", "uint", pGraphics, "uint", hdc)
}
Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff){
return DllCall("gdiplus\GdipGraphicsClear", "uint", pGraphics, "int", ARGB)
}
Gdip_BlurBitmap(pBitmap, Blur){
if (Blur > 100) || (Blur < 1)
return -1
sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
dWidth := sWidth//Blur, dHeight := sHeight//Blur
pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
G1 := Gdip_GraphicsFromImage(pBitmap1)
Gdip_SetInterpolationMode(G1, 7)
Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
Gdip_DeleteGraphics(G1)
pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
G2 := Gdip_GraphicsFromImage(pBitmap2)
Gdip_SetInterpolationMode(G2, 7)
Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
Gdip_DeleteGraphics(G2)
Gdip_DisposeImage(pBitmap1)
return pBitmap2
}
Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=100){
SplitPath, sOutput,,, Extension
if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
return -1
Extension := "." Extension
DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "uint", &ci)
if !(nCount && nSize)
return -2
Loop, %nCount% {
Location := NumGet(ci, 76*(A_Index-1)+44)
if !A_IsUnicode {
nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
if !InStr(sString, "*" Extension)
continue
}else{
nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
sString := ""
Loop, %nSize%
sString .= Chr(NumGet(Location+0, 2*(A_Index-1), "char"))
if !InStr(sString, "*" Extension)
continue
}
pCodec := &ci+76*(A_Index-1)
break
}
if !pCodec
return -3
if (Quality != 75)
{
Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
if Extension in .JPG,.JPEG,.JPE,.JFIF
{
DllCall("gdiplus\GdipGetEncoderParameterListSize", "uint", pBitmap, "uint", pCodec, "uint*", nSize)
VarSetCapacity(EncoderParameters, nSize, 0)
DllCall("gdiplus\GdipGetEncoderParameterList", "uint", pBitmap, "uint", pCodec, "uint", nSize, "uint", &EncoderParameters)
Loop, % NumGet(EncoderParameters) { ;%
if (NumGet(EncoderParameters, (28*(A_Index-1))+20) = 1) && (NumGet(EncoderParameters, (28*(A_Index-1))+24) = 6){
p := (28*(A_Index-1))+&EncoderParameters
NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20)))
break
}
}
}
}
if !A_IsUnicode {
nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", 0, "int", 0)
VarSetCapacity(wOutput, nSize*2)
DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", &wOutput, "int", nSize)
VarSetCapacity(wOutput, -1)
if !VarSetCapacity(wOutput)
return -4
E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &wOutput, "uint", pCodec, "uint", p ? p : 0)
} else
E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &sOutput, "uint", pCodec, "uint", p ? p : 0)
return E ? -5 : 0
}
Gdip_GetPixel(pBitmap, x, y){
DllCall("gdiplus\GdipBitmapGetPixel", "uint", pBitmap, "int", x, "int", y, "uint*", ARGB)
return ARGB
}
Gdip_SetPixel(pBitmap, x, y, ARGB){
return DllCall("gdiplus\GdipBitmapSetPixel", "uint", pBitmap, "int", x, "int", y, "int", ARGB)
}
Gdip_GetImageWidth(pBitmap){
DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width)
return Width
}
Gdip_GetImageHeight(pBitmap){
DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height)
return Height
}
Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height){
Width := Gdip_GetImageWidth(pBitmap)
Height := Gdip_GetImageHeight(pBitmap)
}
Gdip_GetImagePixelFormat(pBitmap){
DllCall("gdiplus\GdipGetImagePixelFormat", "uint", pBitmap, "uint*", Format)
return Format
}
Gdip_GetDpiX(pGraphics){
DllCall("gdiplus\GdipGetDpiX", "uint", pGraphics, "float*", dpix)
return Round(dpix)
}
Gdip_GetDpiY(pGraphics){
DllCall("gdiplus\GdipGetDpiY", "uint", pGraphics, "float*", dpiy)
return Round(dpiy)
}
Gdip_GetImageHorizontalResolution(pBitmap){
DllCall("gdiplus\GdipGetImageHorizontalResolution", "uint", pBitmap, "float*", dpix)
return Round(dpix)
}
Gdip_GetImageVerticalResolution(pBitmap){
DllCall("gdiplus\GdipGetImageVerticalResolution", "uint", pBitmap, "float*", dpiy)
return Round(dpiy)
}
Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize=""){
SplitPath, sFile,,, ext
if ext in exe,dll
{
Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
VarSetCapacity(buf, 40)
Loop, Parse, Sizes, |
{
DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, "uint*", hIcon, "uint*", 0, "uint", 1, "uint", 0)
if !hIcon
continue
if !DllCall("GetIconInfo", "uint", hIcon, "uint", &buf) {
DestroyIcon(hIcon)
continue
}
hbmColor := NumGet(buf, 16)
hbmMask := NumGet(buf, 12)
if !(hbmColor && DllCall("GetObject", "uint", hbmColor, "int", 24, "uint", &buf))
{
DestroyIcon(hIcon)
continue
}
break
}
if !hIcon
return -1
Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
if !DllCall("DrawIconEx", "uint", hdc, "int", 0, "int", 0, "uint", hIcon, "uint", Width, "uint", Height, "uint", 0, "uint", 0, "uint", 3) {