-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_GUIResourcePic.au3
1670 lines (1502 loc) · 84.9 KB
/
_GUIResourcePic.au3
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
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; Uncomment this line to Au3Check!
#include-once
; #INDEX# =======================================================================================================================
; Title .........: _GUIResourcePic
; Version .......: 1.8.2012.2600b
; AutoIt Version.: 3.3.8.1
; Language.......: English
; Description ...: Load image (.bmp, .jpg, .png, .gif {animated} and other formats.) resources from .exe, .dll, .ocx, .cpl...
; Author ........: João Carlos (jscript)
; Remarks .......: Based on http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=1776 and Prog@ndy work concept!
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _GUICtrlPic_Create
; _GUICtrlPic_Delete
; _GUICtrlPic_Release
; _GUICtrlPic_SetImage
; _GUICtrlPic_SetState
; _GUICtrlPic_GetInfo
; ===============================================================================================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
; __GRP_GetGifInfo
; __GRP_BuildList
; __GRP_DrawFrame
; __GRP_hImgToCtrl
; __GRP_DeleteObj
; __GRP_CreateTimer
; __GRP_KillTimer
; __GRP_SetTimer
; __GRP_ReleaseGIF
; __GRP_WM_DESTROY
; __GRP_ShutDown
; __GRP_GetCtrlIndex
; __GRP_GetGifFrameDelays
; __GRP_GetGifLoopCount
; __GRP_GetFileNameType
; __GRP_FreeMem
; __GRP_LoadResource
; ===== From other authors. =====
; __GDIPCreateBitmapFromScan0 ;
; _GDIPlus_ImageLoadFromHGlobal ;
; _MemGlobalAllocFromBinary ;
; _MemGlobalAllocFromMem ;
; ===============================================================================================================================
; Thanks to asdf8 for add this! =================================================================================================
;~ #Obfuscator_Ignore_Funcs= __GRP_BuildList, __GRP_DrawFrame, __GRP_SetTimer, __GDIPCreateBitmapFromScan0, _MemGlobalAllocFromMem
;~ #Obfuscator_Ignore_Variables= $vGRP_TEMP, $avGRP_CTRLIDS, $iGRP_MSG
; ===============================================================================================================================
; #INCLUDES# ====================================================================================================================
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <Memory.au3>
#include <WinApi.au3>
#include <Array.au3>
; ===============================================================================================================================
; #VARIABLES# ===================================================================================================================
; State
Global Const $GUI_GIFSTART = 64 ; If image is GIF animated, start/resume animation!
Global Const $GUI_GIFSTOP = 128 ; If image is GIF animated, stop/pause animation!
; Style (GIS = Gif Image Styles)
Global Const $GIS_ASPECTRATIOFIX = 0x2000 ; Fix the image size based on aspect ratio.
Global Const $GIS_HALFTRANSPARENCY = 0x4014 ; The images are rendered with the window background color. This Style is default.
Global Const $GIS_FULLTRANSPARENCY = 0x40015 ; The frames are rendered in full transparency independent of the background color of the window!
; Note: This Style consumes more CPU because the exstyle $WS_EX_TRANSPARENT is added to each frame in real time!
; Not valid if the image does not have transparency!
; Default Style to _GUICtrlPic_Create()!
Global Const $GIS_SS_DEFAULT_PIC = BitOR($GIS_HALFTRANSPARENCY, $SS_NOTIFY)
; ExStyle (GIS_EX = Gif Image Extended Styles)
Global $GIS_EX_DEFAULTRENDER = 0x21 ; To use _GUIImageList_Draw in rendering of images, use less CPU. This ExStyle is default!
Global $GIS_EX_CTRLSNDRENDER = 0x22 ; The frames is render using GUICtrlSendMsg, but consumes much more CPU!!!
; Note: If you use this ExStyle, only $GRP_FULLTRANSPARENCY is used for rendering images!
; Control and GIF variables
Global $avGRP_CTRLIDS[1][20]
Global $vGRP_TEMP, $iGRP_MSG = 0
Global $pGRP_tGUID = DllStructCreate($tagGUID)
; GDIP image property types constants
Global Const $iGRP_ptTypeByte = 1
Global Const $iGRP_ptTypeShort = 3
Global Const $iGRP_ptTypeLong = 4
Global Const $iGRP_ptLoopCount = 0x5101
Global Const $iGRP_ptFrameDelay = 0x5100
Global Const $tGRP_PropTagItem = "long id; long length; int Type; ptr value"
; Open DLLs to acelerate execution!
Global Const $hGRP_GDI32 = DllOpen("gdi32.dll")
Global Const $hGRP_USER32 = DllOpen("user32.dll")
Global Const $hGRP_COMCTL32 = DllOpen("comctl32.dll")
; ===============================================================================================================================
; #EXIT_REGISTER# ===============================================================================================================
OnAutoItExitRegister("__GRP_ShutDown")
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Create
; Description ...: Creates a Picture control for the GUI.
; Syntax ........: _GUICtrlPic_Create( sFileName, iLeft, iTop [, iWidth [, iHeight [, iStyle [, sExStyle ]]]]]] )
; Parameters ....: FileName - Filename of the picture, binary or resource to be loaded.
; Supported types: BMP, JPG, PNG, GIF(animated). Can be an URL path too.
; For a resource file, use the parameter in this format:
; "MyFile.ext|RessourceName|ResourceType".
; Left - The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
; Top - The top of the control. If -1 is used then top will be computed according to GUICoordMode.
; Width - [optional] The width of the control (default is the previously used width).
; Height - [optional] The height of the control (default is the previously used height).
; $iStyle - [optional] Defines the style of the control. Default is -1.
; $sExStyle - [optional] Defines the extended style of the control. Default is -1.
; Return values .: Success - Returns the identifier (controlID) of the new control.
; Failure - Returns 0 if picture cannot be created.
; Author ........: JScript (João Carlos - FROM Brazil)
; Modified.......:
; Remarks .......: 1 - To update the picture after the dialog box is displayed just use _GUICtrlPic_SetImage().
; 2 - If you want to have a picture having the same size as the file content just use Width=Height=0.
; 3 - To set or change information in the control see _GUICtrlPic_Set...() functions.
; 4 - Default resizing is $GUI_DOCKSIZE.
; 5 - If a picture is set as a background picture, as the other controls will overlap, it's important to disable
; the pic control and create it after the others controls: GUICtrlSetState( controlID, $GUI_DISABLE ).
; 6 - The extended style $GUI_WS_EX_PARENTDRAG can be used to allow the dragging of the parent window for windows
; that don't have a titlebar. Just use: GUICtrlSetStyle( controlID, -1, $GUI_WS_EX_PARENTDRAG ).
; 7 - The background is set to transparent. GUICtrlSetBkColor() has effect on this pic control.
; 8 - The resource type: $RT_ICON is not supported.
; 9 - For a resource file, use the "FileName" parameter in this format: "MyFile.ext|RessourceName|ResourceType".
; 10 - The INTERNALID parameter should only be used by the _GUICtrlPic_SetImage()!
; 11 - Styles and ExStyles info:
; If you define Widht and Heigth of image, to fix the size based on aspect ratio, use $GIS_ASPECTRATIOFIX Style.
; $GIS_HALFTRANSPARENCY = The images are rendered with the window background color. This Style is default.
; $GIS_FULLTRANSPARENCY = Frames are rendered in full transparency independent of the background color of the window!
; Note: This Style consumes more CPU because the exstyle $WS_EX_TRANSPARENT is added to each frame in real time!
; Not valid if the image does not have transparency!
; To combine styles with the default style use BitOr($GIS_SS_DEFAULT_PIC, newstyle,...).
; $GIS_EX_DEFAULTRENDER = To use _GUIImageList_Draw in rendering of images, use less CPU. This ExStyle is default!
; $GIS_EX_CTRLSNDRENDER = The frames is render using GUICtrlSendMsg, but consumes much more CPU!!!
; Note: If you use this ExStyle, only $GRP_FULLTRANSPARENCY is used for rendering images!
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_Create("..\GUI\mslogo.jpg", 50, 50, 200, 50)
; ===============================================================================================================================
Func _GUICtrlPic_Create($sFileName, $iLeft = 0, $iTop = 0, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1, $INTERNALID = 0)
Local $iCtrlID, $hCtrlID, $aCtrlStyle, $aCtrlExStyle, $iCtrlSize = 0x40 ; SS_REALSIZECONTROL = 0x40
Local $hOImage, $pDimensionIDs, $iTransparency = 1, $iFrameCount, $aiFrameDelays, $iLoopCount, $hWndForm = 0
Local $iIndex, $iOWidth, $iOHeight, $iReSize = 1, $asImgType, $tCtrlInfo, $iResizeMode
Local $t_Style, $t_ExStyle, $iDefaultRender = 1, $iTransMode = 0, $hHGMem
; If set image into native control!
If $INTERNALID Then
; If not a valid controlID return 0.
If Not GUICtrlGetHandle($INTERNALID) Then Return SetError(0, 0, 0)
$iCtrlID = $INTERNALID
EndIf
;----> Initialize GDI+ library only if not alread started!
If $__g_hGDIPDll = 0 Then _GDIPlus_Startup()
;<----
; Processing the [FileName] parameter.
If Not __GRP_GetFileNameType($sFileName, $hOImage, $hHGMem) Then Return SetError(0, 0, 0)
; Returns file format GUID and image format name of an image.
$asImgType = _GDIPlus_ImageGetRawFormat($hOImage)
$asImgType = $asImgType[1]
If $asImgType = "GIF" Then
; __GRP_GetGifInfo( Byref param )
If Not __GRP_GetGifInfo($pDimensionIDs, $hOImage, $iFrameCount, $iLoopCount, $aiFrameDelays, $iTransparency) Then
__GRP_FreeMem($hOImage, $hHGMem)
Return SetError(0, 0, 0)
EndIf
EndIf
; Processing the Styles.
If $iStyle = -1 Then $iStyle = $GIS_SS_DEFAULT_PIC
If $iExStyle = -1 Then $iExStyle = $WS_EX_TRANSPARENT
; $GIS_FULLTRANSPARENCY is used, frames are rendered in full transparency independent of the background color of the window!
If BitAND($iStyle, $GIS_FULLTRANSPARENCY) = $GIS_FULLTRANSPARENCY Then
If $iTransparency Then $iTransMode = 1
$t_Style = BitOR($iStyle, $GIS_FULLTRANSPARENCY)
; Remove Style.
$iStyle = BitXOR($iStyle, $GIS_FULLTRANSPARENCY)
EndIf
; Check if $GIS_EX_CTRLSNDRENDER is used, the frames is render using GUICtrlSendMsg, but consumes much more CPU!!!
; Note: If you use this ExStyle, only $GRP_FULLTRANSPARENCY is used for rendering images!
If BitAND($iExStyle, $GIS_EX_CTRLSNDRENDER) = $GIS_EX_CTRLSNDRENDER Then
$iDefaultRender = 0
If $iTransparency Then $iTransMode = 1
$t_ExStyle = BitOR($iExStyle, $GIS_EX_CTRLSNDRENDER)
; Remove Style.
$iExStyle = BitXOR($iExStyle, $GIS_EX_CTRLSNDRENDER)
EndIf
; Get image file dimensions.
$iOWidth = _GDIPlus_ImageGetWidth($hOImage)
$iOHeight = _GDIPlus_ImageGetHeight($hOImage)
; Processing the image dimensions...
Select
; If you want to have a picture control having the same size as the file content just use width=height=0.
Case ($iWidth = 0 And $iHeight = 0) Or ($iWidth = -1 And $iHeight = -1) Or ($iWidth = $iOWidth And $iHeight = $iOHeight)
$iReSize = 0
$iCtrlSize = 0x800 ; SS_REALSIZEIMAGE = 0x800
$iWidth = $iOWidth
$iHeight = $iOHeight
If BitAND($iStyle, $GIS_ASPECTRATIOFIX) = $GIS_ASPECTRATIOFIX Then
$t_Style = BitOR($iStyle, $GIS_ASPECTRATIOFIX)
; Remove Style.
$iStyle = BitXOR($iStyle, $GIS_ASPECTRATIOFIX)
EndIf
; Fix Aspect Ratio if Style $GIS_ASPECTRATIOFIX is used.
Case BitAND($iStyle, $GIS_ASPECTRATIOFIX) = $GIS_ASPECTRATIOFIX
Local $iAspectW = Int($iOWidth * $iHeight / $iOHeight)
Local $iAspectH = Int($iOHeight * $iWidth / $iOWidth)
Switch ($iAspectW > $iWidth)
Case True
$iHeight = $iAspectH
Case False
$iWidth = $iAspectW
EndSwitch
$t_Style = BitOR($iStyle, $GIS_ASPECTRATIOFIX)
; Remove Style.
$iStyle = BitXOR($iStyle, $GIS_ASPECTRATIOFIX)
EndSelect
;----> Remove some $GIS_XXX Styles!
If BitAND($iStyle, $GIS_HALFTRANSPARENCY) = $GIS_HALFTRANSPARENCY Then $iStyle = BitXOR($iStyle, $GIS_HALFTRANSPARENCY)
If BitAND($iExStyle, $GIS_EX_DEFAULTRENDER) = $GIS_EX_DEFAULTRENDER Then $iExStyle = BitXOR($iExStyle, $GIS_EX_DEFAULTRENDER)
;<----
;----> Control ID to show GIF image and interact with other functions.
Switch $INTERNALID
Case 0
$iCtrlID = GUICtrlCreateLabel("", $iLeft, $iTop, $iWidth, $iHeight, BitOR($iStyle, $iCtrlSize, $SS_BITMAP), $iExStyle)
; The automatic resizing event can be disabled if GUIEventOptions(Option) is set to 1.
$iResizeMode = Opt("GUIResizeMode")
Select
Case Opt("GUIEventOptions") = 0 And $iResizeMode = 0
GUICtrlSetResizing(-1, 768) ; Default resizing is $GUI_DOCSIZE = 768
Case $iResizeMode > 0
GUICtrlSetResizing(-1, $iResizeMode)
EndSelect
Case Else
GUICtrlSetPos($iCtrlID, Default, Default, $iWidth, $iHeight)
GUICtrlSetStyle($iCtrlID, BitOR($iStyle, $iCtrlSize, $SS_BITMAP), $iExStyle)
EndSwitch
; To GIF transparency work!
GUICtrlSetBkColor($iCtrlID, $GUI_BKCOLOR_TRANSPARENT)
; Get styles of control!
$hCtrlID = GUICtrlGetHandle($iCtrlID)
$aCtrlStyle = DllCall($hGRP_USER32, "long", "GetWindowLong", "hwnd", $hCtrlID, "int", -16) ; -16 = $GWL_STYLE
$aCtrlExStyle = DllCall($hGRP_USER32, "long", "GetWindowLong", "hwnd", $hCtrlID, "int", -20) ; -20 = $GWL_EXSTYLE
;<----
; Get window handle for use with __GRP_CreateTimer function.
$hWndForm = _WinAPI_GetParent($hCtrlID)
;----> Fills ctrl info structure.
If IsBinary($sFileName) Then $sFileName = "Binary"
$tCtrlInfo = DllStructCreate("hwnd CtrlHandle;int Style;int ExStyle;wchar FileName[" & StringLen($sFileName) & "];" & _
"long Left;long Top;long Width;long Height;long OWidht;long OHeight;int tStyle;int tExStyle;wchar Function[15];long HGMEM")
DllStructSetData($tCtrlInfo, "CtrlHandle", $hCtrlID)
DllStructSetData($tCtrlInfo, "Style", $aCtrlStyle[0])
DllStructSetData($tCtrlInfo, "ExStyle", $aCtrlExStyle[0])
DllStructSetData($tCtrlInfo, "FileName", $sFileName)
DllStructSetData($tCtrlInfo, "Left", $iLeft)
DllStructSetData($tCtrlInfo, "Top", $iTop)
; Control size.
DllStructSetData($tCtrlInfo, "Width", $iWidth)
DllStructSetData($tCtrlInfo, "Height", $iHeight)
; Original image size.
DllStructSetData($tCtrlInfo, "OWidht", $iOWidth)
DllStructSetData($tCtrlInfo, "OHeight", $iOHeight)
; Save internal Styles!
DllStructSetData($tCtrlInfo, "tStyle", $t_Style)
DllStructSetData($tCtrlInfo, "tExStyle", $t_ExStyle)
; Save build/draw function name, initial is __GRP_BuildList!
DllStructSetData($tCtrlInfo, "Function", "__GRP_BuildList")
; Save HGlobal MEM to release after.
DllStructSetData($tCtrlInfo, "HGMEM", $hHGMem)
;<----
;----> Fills array with the control data!
$iIndex = $avGRP_CTRLIDS[0][0] + 1
ReDim $avGRP_CTRLIDS[$iIndex + 1][20]
$avGRP_CTRLIDS[0][0] = $iIndex
$avGRP_CTRLIDS[$iIndex][0] = $iCtrlID ; control ID
$avGRP_CTRLIDS[$iIndex][1] = $tCtrlInfo ; control info structure.
$avGRP_CTRLIDS[$iIndex][2] = $hOImage
$avGRP_CTRLIDS[$iIndex][3] = $pDimensionIDs
$avGRP_CTRLIDS[$iIndex][4] = $iFrameCount
$avGRP_CTRLIDS[$iIndex][5] = $aiFrameDelays
$avGRP_CTRLIDS[$iIndex][6] = $iLoopCount * $iFrameCount ; Repeat count
$avGRP_CTRLIDS[$iIndex][7] = 0 ; First frame
$avGRP_CTRLIDS[$iIndex][8] = $iDefaultRender ; Render to use.
$avGRP_CTRLIDS[$iIndex][9] = $iReSize ; Resize=1 true, 0 false
$avGRP_CTRLIDS[$iIndex][10] = $iTransMode ; Mode to render transparency!
$avGRP_CTRLIDS[$iIndex][11] = 0 ; Flag to fill ImageList first! 0=empty
$avGRP_CTRLIDS[$iIndex][12] = $hWndForm
$avGRP_CTRLIDS[$iIndex][13] = 0 ; _WinAPI_GetDC($hCtrlID)
$avGRP_CTRLIDS[$iIndex][14] = 0 ; _GUIImageList_Create() or DllStructCreate()
$avGRP_CTRLIDS[$iIndex][15] = 0 ; Callback identifier, need this for the Kill Timer.
$avGRP_CTRLIDS[$iIndex][16] = 0 ; Pointer to a callback identifier, need this for the __GRP_SetTimer.
$avGRP_CTRLIDS[$iIndex][17] = 0 ; Flag to checks if the timer needs to be set to avoid unnecessary use of CPU!
$avGRP_CTRLIDS[$iIndex][18] = $iTransparency ; Transparency flag.
$avGRP_CTRLIDS[$iIndex][19] = 0 ; GUI background color, used by _GUIImageList_Create.
; Check if gif is animated...
Switch $iFrameCount
Case 0
; Resize the picture with quality, thanks to the asdf8!
; http://www.autoitscript.com/forum/topic/100167-guiresourcepicau3-udf-supports-gif-animation-using-gdi/page__st__20#entry1004411
If $iReSize Then
Local $hOBitmap = __GDIPCreateBitmapFromScan0($iWidth, $iHeight, 0, $GDIP_PXF32ARGB, 0)
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hOBitmap)
DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphic, "int", 7) ; high-quality, bicubic interpolation.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hOImage, 0, 0, $iWidth, $iHeight)
_GDIPlus_ImageDispose($hOImage)
_GDIPlus_GraphicsDispose($hGraphic)
$hOImage = $hOBitmap
$avGRP_CTRLIDS[$iIndex][2] = $hOImage
EndIf
; Shows the single frame in the control.
__GRP_hImgToCtrl($iCtrlID, $hOImage, $pDimensionIDs, 0)
Case Else
; Get the min and max value of Frame Delays.
Local $iLowTime = _ArrayMin($aiFrameDelays, 1, 0), $iHiTime = _ArrayMax($aiFrameDelays, 1, 0)
; If they are different, set flag to change timer in real time!
If $iLowTime <> $iHiTime Then $avGRP_CTRLIDS[$iIndex][17] = 1
Switch $iDefaultRender
Case 1
$avGRP_CTRLIDS[$iIndex][13] = _WinAPI_GetDC($hCtrlID)
$avGRP_CTRLIDS[$iIndex][14] = _GUIImageList_Create($iWidth, $iHeight, 5, 0, $iFrameCount, 0)
Case 0
Local $HBITMAP[$iFrameCount]
$avGRP_CTRLIDS[$iIndex][14] = $HBITMAP
EndSwitch
; First build a list / array of image frames to speed up drawing!
__GRP_CreateTimer($hWndForm, $iLowTime, "__GRP_BuildList", $iIndex)
EndSwitch
; If the window is closed, ensures that the memory is released if the control has not been deleted by _GUICtrlPic_Delete function!
If Not $iGRP_MSG Then
GUIRegisterMsg($WM_DESTROY, "__GRP_WM_DESTROY")
$iGRP_MSG = 1
;BOOL WINAPI SetProcessWorkingSetSize(
; _In_ HANDLE hProcess,
; _In_ SIZE_T dwMinimumWorkingSetSize,
; _In_ SIZE_T dwMaximumWorkingSetSize
;);
Local $hHandle = _WinAPI_GetCurrentProcess()
DllCall("kernel32.dll", "int", "SetProcessWorkingSetSize", "hwnd", $hHandle, "int", -1, "int", -1)
_WinAPI_CloseHandle($hHandle)
EndIf
; Free the memory allocated for the control struct!
$tCtrlInfo = 0
;<----
Return SetError(0, 0, $iCtrlID)
EndFunc ;==>_GUICtrlPic_Create
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Delete
; Description ...: Deletes a control returned by _GUICtrlPic_Create.
; Syntax.........: _GUICtrlPic_Delete( controlID )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; Return values .: Success - Returns 1.
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_Delete($iCtrlID)
; ===============================================================================================================================
Func _GUICtrlPic_Delete($iCtrlID)
Local $iIndex
$iIndex = __GRP_GetCtrlIndex($iCtrlID)
If Not $iIndex Then Return 0
; If image is GIF animated...
__GRP_ReleaseGIF($iIndex)
#cs
For $i = $iIndex To UBound($avGRP_CTRLIDS) - 2
For $j = 0 To 19
$avGRP_CTRLIDS[$i][$j] = $avGRP_CTRLIDS[$i + 1][$j]
Next
Next
ReDim $avGRP_CTRLIDS[$avGRP_CTRLIDS[0][0]][20]
$avGRP_CTRLIDS[0][0] -= 1
#ce
Return GUICtrlDelete($iCtrlID)
EndFunc ;==>_GUICtrlPic_Delete
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Release
; Description ...: Frees memory used by the control without deleting it!
; Syntax.........: _GUICtrlPic_Release( controlID )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; Return values .: Success - Returns 1.
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_Release($iCtrlID)
; ===============================================================================================================================
Func _GUICtrlPic_Release($iCtrlID)
Local $iIndex
$iIndex = __GRP_GetCtrlIndex($iCtrlID)
If Not $iIndex Then Return 0
; If image is GIF animated...
__GRP_ReleaseGIF($iIndex)
Return 1
EndFunc ;==>_GUICtrlPic_Release
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetImage
; Description ...: Sets the picture or resource to use for a control.
; Syntax.........: _GUICtrlPic_SetImage( controlID, FileName [, FixSize ]])
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; FileName - Filename of the picture, binary or resource to be loaded.
; Supported types: BMP, JPG, PNG, GIF(animated). Can be an URL path too.
; For a resource file, use the parameter in this format:
; "MyFile.ext|RessourceName|ResourceType".
; FixSize - [optional] fix the original size of image.
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: 1 - You can use this function in the following static controls: GUICtrlCreatePic() or GUICtrlCreateLabel()
; 2 - If you want to have a picture control having the same size as the file content just use FixSize=True.
; 3 - The resource type: $RT_ICON is not supported.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetImage($iCtrlID, $sFileName)
; ===============================================================================================================================
Func _GUICtrlPic_SetImage($iCtrlID, $sFileName, $lFixSize = False)
Local $hOImage, $pDimensionIDs, $iTransparency = 1, $iTransMode = 0
Local $iFrameCount, $aiFrameDelays, $iLoopCount, $asImgType
Local $iWidth = -1, $iHeight = -1, $iOWidth, $iOHeight, $iReSize = 1, $tCtrlInfo
Local $iIndex, $iStyle, $iExStyle, $hHGMem
If $iCtrlID = -1 Then $iCtrlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
$iIndex = __GRP_GetCtrlIndex($iCtrlID)
If Not $iIndex Then ; Was passed a native control to set image!
Local $aCtrlPos, $hCtrlID
$hCtrlID = GUICtrlGetHandle($iCtrlID)
If Not $hCtrlID Then Return SetError(0, 0, 0)
$aCtrlPos = WinGetPos($hCtrlID)
If @error Then Return SetError(0, 0, 0)
; If you want to have a picture control having the same size as the file content just use FixSize=True.
If $lFixSize Then
$aCtrlPos[2] = 0
$aCtrlPos[3] = 0
EndIf
; Get styles of control!
$iStyle = DllCall($hGRP_USER32, "long", "GetWindowLong", "hwnd", $hCtrlID, "int", -16) ; -16 = $GWL_STYLE
$iExStyle = DllCall($hGRP_USER32, "long", "GetWindowLong", "hwnd", $hCtrlID, "int", -20) ; -20 = $GWL_EXSTYLE
Return SetError(0, _GUICtrlPic_Create($sFileName, $aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2], $aCtrlPos[3], $iStyle[0], $iExStyle[0], $iCtrlID), 1)
EndIf
; Processing the [FileName] parameter.
If Not __GRP_GetFileNameType($sFileName, $hOImage, $hHGMem) Then Return SetError(0, 0, 0)
; If image is GIF animated...
__GRP_ReleaseGIF($iIndex)
; Returns file format GUID and image format name of an image.
$asImgType = _GDIPlus_ImageGetRawFormat($hOImage)
$asImgType = $asImgType[1]
If $asImgType = "GIF" Then
; __GRP_GetGifInfo( Byref param )
If Not __GRP_GetGifInfo($pDimensionIDs, $hOImage, $iFrameCount, $iLoopCount, $aiFrameDelays, $iTransparency) Then
_GDIPlus_ImageDispose($hOImage)
Return SetError(0, 0, 0)
EndIf
EndIf
; ctrl info structure.
$tCtrlInfo = $avGRP_CTRLIDS[$iIndex][1]
; Processing the Styles.
$iStyle = DllStructGetData($tCtrlInfo, "tStyle")
$iExStyle = DllStructGetData($tCtrlInfo, "tExStyle")
; If $GIS_FULLTRANSPARENCY is used, frames are rendered in full transparency independent of the background color of the window!
; Check if $GIS_EX_CTRLSNDRENDER is used, the frames is render using GUICtrlSendMsg, but consumes much more CPU!!!
; Note: If you use this ExStyle, only $GRP_FULLTRANSPARENCY is used for rendering images!
If BitAND($iStyle, $GIS_FULLTRANSPARENCY) = $GIS_FULLTRANSPARENCY Or _
BitAND($iExStyle, $GIS_EX_CTRLSNDRENDER) = $GIS_EX_CTRLSNDRENDER Then
If $iTransparency Then $iTransMode = 1
EndIf
; Get image file dimensions.
$iOWidth = _GDIPlus_ImageGetWidth($hOImage)
$iOHeight = _GDIPlus_ImageGetHeight($hOImage)
; Get control dimensions.
$iWidth = DllStructGetData($tCtrlInfo, "Width")
$iHeight = DllStructGetData($tCtrlInfo, "Height")
; Processing the image dimensions...
Select
; If you want to have a picture control having the same size as the file content just use FixSize=True.
Case $lFixSize
$iReSize = 0
$iWidth = $iOWidth
$iHeight = $iOHeight
GUICtrlSetPos($iCtrlID, Default, Default, $iWidth, $iHeight)
; Fix Aspect Ratio if Style $GIS_ASPECTRATIOFIX is used.
Case BitAND($iStyle, $GIS_ASPECTRATIOFIX) = $GIS_ASPECTRATIOFIX
Local $iAspectW = Int($iOWidth * $iHeight / $iOHeight)
Local $iAspectH = Int($iOHeight * $iWidth / $iOWidth)
Switch ($iAspectW > $iWidth)
Case True
$iHeight = $iAspectH
Case False
$iWidth = $iAspectW
EndSwitch
EndSelect
;----> Fills ctrl info structure.
;DllStructSetData($tCtrlInfo, "CtrlHandle", $hCtrlID)
If Not IsBinary($sFileName) Then DllStructSetData($tCtrlInfo, "FileName", $sFileName)
;DllStructSetData($tCtrlInfo, "Style", $aCtrlStyle[0])
;DllStructSetData($tCtrlInfo, "ExStyle", $aCtrlExStyle[0])
;DllStructSetData($tCtrlInfo, "Left", $iLeft)
;DllStructSetData($tCtrlInfo, "Top", $iTop)
; Control size.
DllStructSetData($tCtrlInfo, "Width", $iWidth)
DllStructSetData($tCtrlInfo, "Height", $iHeight)
; Original image size.
DllStructSetData($tCtrlInfo, "OWidht", $iOWidth)
DllStructSetData($tCtrlInfo, "OHeight", $iOHeight)
; Save build/draw function name, initial is __GRP_BuildList!
DllStructSetData($tCtrlInfo, "Function", "__GRP_BuildList")
; Save HGlobal MEM to release after.
DllStructSetData($tCtrlInfo, "HGMEM", $hHGMem)
;<----
;----> Fills array with the control data!
;$avGRP_CTRLIDS[$iIndex][0] = $iCtrlID ; control ID
;$avGRP_CTRLIDS[$iIndex][1] = $tCtrlInfo ; control info structure.
$avGRP_CTRLIDS[$iIndex][2] = $hOImage
$avGRP_CTRLIDS[$iIndex][3] = $pDimensionIDs
$avGRP_CTRLIDS[$iIndex][4] = $iFrameCount
$avGRP_CTRLIDS[$iIndex][5] = $aiFrameDelays
$avGRP_CTRLIDS[$iIndex][6] = $iLoopCount * $iFrameCount ; Repeat count
$avGRP_CTRLIDS[$iIndex][7] = 0 ; First frame
;$avGRP_CTRLIDS[$iIndex][8] = $iDefaultRender ; Render to use.
$avGRP_CTRLIDS[$iIndex][9] = $iReSize ; Resize=1 true, 0 false
$avGRP_CTRLIDS[$iIndex][10] = $iTransMode
$avGRP_CTRLIDS[$iIndex][11] = 0 ; Flag to fill ImageList first! 0=empty
;$avGRP_CTRLIDS[$iIndex][12] = $hWndForm
$avGRP_CTRLIDS[$iIndex][13] = 0 ; _WinAPI_GetDC($hCtrlID) only if $iDefaultRender = 1.
$avGRP_CTRLIDS[$iIndex][14] = 0 ; _GUIImageList_Create
;$avGRP_CTRLIDS[$iIndex][15] = 0 ; Callback identifier, need this for the Kill Timer.
;$avGRP_CTRLIDS[$iIndex][16] = 0 ; Pointer to a callback identifier, need this for the __GRP_SetTimer.
$avGRP_CTRLIDS[$iIndex][17] = 0 ; Flag to checks if the timer needs to be set to avoid unnecessary use of CPU!
$avGRP_CTRLIDS[$iIndex][18] = $iTransparency ; Transparency flag.
$avGRP_CTRLIDS[$iIndex][19] = 0 ; GUI background color, used by _GUIImageList_Create.
Local $iState = GUICtrlGetState($iCtrlID)
GUICtrlSetState($iCtrlID, $GUI_HIDE)
; Check if gif is animated...
Switch $iFrameCount
Case 0
; Resize the picture with quality, thanks to the asdf8!
; http://www.autoitscript.com/forum/topic/100167-guiresourcepicau3-udf-supports-gif-animation-using-gdi/page__st__20#entry1004411
If $iReSize Then
Local $hOBitmap = __GDIPCreateBitmapFromScan0($iWidth, $iHeight, 0, $GDIP_PXF32ARGB, 0)
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hOBitmap)
DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphic, "int", 7) ; high-quality, bicubic interpolation.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hOImage, 0, 0, $iWidth, $iHeight)
_GDIPlus_ImageDispose($hOImage)
_GDIPlus_GraphicsDispose($hGraphic)
$hOImage = $hOBitmap
$avGRP_CTRLIDS[$iIndex][2] = $hOImage
EndIf
; Shows the single frame in the control.
__GRP_hImgToCtrl($iCtrlID, $hOImage, $pDimensionIDs, 0)
Case Else
; Get the min and max value of Frame Delays.
Local $iLowTime = _ArrayMin($aiFrameDelays, 1, 0), $iHiTime = _ArrayMax($aiFrameDelays, 1, 0)
; If they are different, set flag to change timer in real time!
If $iLowTime <> $iHiTime Then $avGRP_CTRLIDS[$iIndex][17] = 1
Switch $avGRP_CTRLIDS[$iIndex][8] ; $iDefaultRender
Case 1
$avGRP_CTRLIDS[$iIndex][13] = _WinAPI_GetDC(DllStructGetData($tCtrlInfo, "CtrlHandle"))
$avGRP_CTRLIDS[$iIndex][14] = _GUIImageList_Create(DllStructGetData($tCtrlInfo, "Width"), DllStructGetData($tCtrlInfo, "Height"), 5, 0, $iFrameCount, 0)
Case 0
Local $HBITMAP[$iFrameCount]
$avGRP_CTRLIDS[$iIndex][14] = $HBITMAP
EndSwitch
; First build a list / array of image frames to speed up drawing!
__GRP_CreateTimer($avGRP_CTRLIDS[$iIndex][12], $iLowTime, "__GRP_BuildList", $iIndex)
EndSwitch
GUICtrlSetState($iCtrlID, $iState)
; Free the memory allocated for the control struct!
$tCtrlInfo = 0
;<----
Return SetError(0, 0, 1)
EndFunc ;==>_GUICtrlPic_SetImage
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetState
; Description ...: Changes the state of a control returned by a _GUICtrlPic_Create.
; Syntax.........: _GUICtrlPic_SetState( controlID, state )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; state - See the State values below.
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: Suported state values:
; ___________________________________________________________________________________________________
; $GUI_SHOW -> Control will be visible.
; $GUI_HIDE -> Control will not be visible.
; $GUI_ENABLE -> Control will be enabled. If image is GIF animated, start animation!
; $GUI_DISABLE -> Control will be disable. If image is GIF animated, stop animation!
; $GUI_GIFSTART -> If image is GIF animated, start/resume animation!
; $GUI_GIFSTOP -> If image is GIF animated, stop/pause animation!
; ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; State values can be summed up as: $GUI_DISABLE + $GUI_HIDE sets the control in an disabled and hidden state.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetState($iCtrlID, $GUI_HIDE)
; ===============================================================================================================================
Func _GUICtrlPic_SetState($iCtrlID, $iState)
Local $iIndex, $iCtrlState, $aiDelay
If $iCtrlID = -1 Then $iCtrlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
$iIndex = __GRP_GetCtrlIndex($iCtrlID)
If Not $iIndex Then Return 0
$iCtrlState = GUICtrlGetState($iCtrlID)
If (BitAND($iState, $GUI_SHOW) = $GUI_SHOW And BitAND($iCtrlState, $GUI_HIDE) = $GUI_HIDE) Or _
(BitAND($iState, $GUI_ENABLE) = $GUI_ENABLE And BitAND($iCtrlState, $GUI_DISABLE) = $GUI_DISABLE) Then
; If image is GIF animated, creates a new timer based on Frame Delay.
If $avGRP_CTRLIDS[$iIndex][4] Then
$aiDelay = $avGRP_CTRLIDS[$iIndex][5]
__GRP_CreateTimer($avGRP_CTRLIDS[$iIndex][12], $aiDelay[$avGRP_CTRLIDS[$iIndex][7]], DllStructGetData($avGRP_CTRLIDS[$iIndex][1], "Function"), $iIndex)
$aiDelay = 0
Else
; Show the last frame in the control.
__GRP_hImgToCtrl($iCtrlID, $avGRP_CTRLIDS[$iIndex][2], $avGRP_CTRLIDS[$iIndex][3], $avGRP_CTRLIDS[$iIndex][7])
EndIf
EndIf
If BitAND($iState, $GUI_HIDE) = $GUI_HIDE And BitAND($iCtrlState, $GUI_SHOW) = $GUI_SHOW Then
; If image is GIF animated, kill timer...
If $avGRP_CTRLIDS[$iIndex][4] Then __GRP_KillTimer($avGRP_CTRLIDS[$iIndex][12], $iIndex)
EndIf
If BitAND($iState, $GUI_DISABLE) = $GUI_DISABLE And BitAND($iCtrlState, $GUI_ENABLE) = $GUI_ENABLE Then
; If image is GIF animated, kill timer...
If $avGRP_CTRLIDS[$iIndex][4] Then __GRP_KillTimer($avGRP_CTRLIDS[$iIndex][12], $iIndex)
; Show the last frame in the control.
__GRP_hImgToCtrl($iCtrlID, $avGRP_CTRLIDS[$iIndex][2], $avGRP_CTRLIDS[$iIndex][3], $avGRP_CTRLIDS[$iIndex][7])
EndIf
Return GUICtrlSetState($iCtrlID, $iState)
EndFunc ;==>_GUICtrlPic_SetState
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlPic_GetInfo
; Description ...: Get image info!
; Syntax ........: _GUICtrlPic_GetInfo( sFileName )
; Parameters ....: FileName - Filename of the picture, binary, resource or control ID returned by _GUICtrlPic_Create()
; Supported types: BMP, JPG, PNG, GIF(animated). Can be an URL path too.
; For a resource file, use the parameter in this format:
; "MyFile.ext|RessourceName|ResourceType".
; Return values .: Returns an array with image info. The array returned is one-dimensional and is made up as follows:
; $avArray[0] = Original Width
; $avArray[1] = Original Height
; $avArray[2] = Handle to an image object
; $avArray[3] = Frame Count
; $avArray[4] = Loop Count
; $avArray[5] = Transparency
; Author ........: João Carlos (jscript)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: _GUICtrlPic_GetInfo($sFileName)
; ===============================================================================================================================
Func _GUICtrlPic_GetInfo($sFileName)
Local $hOImage, $pDimensionIDs = 0, $iFrameCount = 0, $iLoopCount = 0, $aiFrameDelays
Local $iIndex, $iOWidth, $iOHeight, $asImgType, $tCtrlInfo, $iTransparency = 1
Local $avArray[6], $hHGMem
If $sFileName = -1 Then $sFileName = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
$iIndex = __GRP_GetCtrlIndex($sFileName)
If $iIndex Then
$tCtrlInfo = $avGRP_CTRLIDS[$iIndex][1]
$avArray[0] = DllStructGetData($tCtrlInfo, "OWidht")
$avArray[1] = DllStructGetData($tCtrlInfo, "OHeight")
$avArray[2] = $avGRP_CTRLIDS[$iIndex][2] ; hOImage
$avArray[3] = $avGRP_CTRLIDS[$iIndex][4] ; FrameCount
$avArray[4] = $avGRP_CTRLIDS[$iIndex][6] ; Repeat count
$avArray[5] = $avGRP_CTRLIDS[$iIndex][18] ; Transparency
$tCtrlInfo = 0
Return $avArray
EndIf
;----> Initialize GDI+ library only if not alread started!
If $__g_hGDIPDll = 0 Then _GDIPlus_Startup()
;<----
; Processing the [FileName] parameter.
If Not __GRP_GetFileNameType($sFileName, $hOImage, $hHGMem) Then Return SetError(0, 0, 0)
; Returns file format GUID and image format name of an image.
$asImgType = _GDIPlus_ImageGetRawFormat($hOImage)
$asImgType = $asImgType[1]
If $asImgType = "GIF" Then
; __GRP_GetGifInfo( Byref param )
If Not __GRP_GetGifInfo($pDimensionIDs, $hOImage, $iFrameCount, $iLoopCount, $aiFrameDelays, $iTransparency) Then
_GDIPlus_ImageDispose($hOImage)
Return SetError(0, 0, 0)
EndIf
EndIf
; Get image file dimensions.
$iOWidth = _GDIPlus_ImageGetWidth($hOImage)
$iOHeight = _GDIPlus_ImageGetHeight($hOImage)
_GDIPlus_ImageDispose($hOImage)
$avArray[0] = $iOWidth
$avArray[1] = $iOHeight
$avArray[2] = $hOImage
$avArray[3] = $iFrameCount
$avArray[4] = $iLoopCount
$avArray[5] = $iTransparency
Return $avArray
EndFunc ;==>_GUICtrlPic_GetInfo
; ===================================================== #INTERNAL_USE_ONLY# =====================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __GRP_GetGifInfo
; Description ...: Get GIF general informations.
; Syntax ........: __GRP_GetGifInfo(Byref $pDimensionIDs, Byref $hOImage, Byref $iFrameCount, _Byref $iLoopCount, Byref $aiFrameDelays,
; Byref $iTransparency)
; Parameters ....: $pDimensionIDs - [in/out] A pointer value.
; $hOImage - [in/out] A handle value.
; $iFrameCount - [in/out] An integer value.
; $iLoopCount - [in/out] An integer value.
; $aiFrameDelays - [in/out] An array of integers.
; $iTransparency - [in/out] An integer value.
; Return values .: 0 if error!
; Author ........: JScript
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __GRP_GetGifInfo(ByRef $pDimensionIDs, ByRef $hOImage, ByRef $iFrameCount, ByRef $iLoopCount, ByRef $aiFrameDelays, ByRef $iTransparency)
Local $aiDimensionsCount, $aiFrameCount, $aGetPixel
;----> Processing the gif image
; Get a pointer to the GUID struct.
$pDimensionIDs = DllStructGetPtr($pGRP_tGUID)
; Gets the number of frame dimensions in an Image object.
$aiDimensionsCount = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hOImage, "int*", 0)
If @error Or Not $aiDimensionsCount[2] Then Return 0
; Gets the identifiers for the frame dimensions of an Image object
DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hOImage, "ptr", $pDimensionIDs, "int", $aiDimensionsCount[2])
If @error Then Return 0
; Gets the number of frames in a specified dimension of an Image object
$aiFrameCount = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameCount", "int", $hOImage, "ptr", $pDimensionIDs, "int*", 0)
If @error Or Not $aiFrameCount[3] Then Return 0
$iFrameCount = $aiFrameCount[3]
If $iFrameCount Then
$aiFrameDelays = __GRP_GetGifFrameDelays($hOImage, $iFrameCount)
$iLoopCount = __GRP_GetGifLoopCount($hOImage)
Else
$iFrameCount = 0 ; Not animation!
EndIf
; Check if gif image is transparent.
$aGetPixel = DllCall($__g_hGDIPDll, "dword", "GdipBitmapGetPixel", "ptr", $hOImage, "int", 0, "int", 0, "dword*", 0)
If Not @error Or $aGetPixel[0] = 0 Then
If BitShift($aGetPixel[4], 24) Then $iTransparency = 0 ; No transparent
EndIf
;<----
Return 1
EndFunc ;==>__GRP_GetGifInfo
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __GRP_BuildList
; Description ...: First build a list / array of image frames to speed up drawing!
; Syntax ........: __GRP_BuildList($hWnd, $Msg, $iIndex, $dwTime)
; Parameters ....: $hWnd, $Msg, $iIDTimer, $dwTime
; Return values .: None
; Author ........: JScript
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __GRP_BuildList($hWnd, $Msg, $iIndex, $dwTime)
#forceref $hWnd, $Msg, $iIndex, $dwTime
;------------------------------
; Note: $iIndex = $iIDTimer !!!
;------------------------------
;If Not _WinAPI_IsWindowVisible($avGRP_CTRLIDS[$iIndex][12]) Then Return 0
$dwTime = DllCall($hGRP_USER32, "bool", "IsWindowVisible", "hwnd", $hWnd)
If Not $dwTime[0] Then Return 0
; Flag to fill ImageList first! 0=empty
Switch $avGRP_CTRLIDS[$iIndex][11]
Case 0 To $avGRP_CTRLIDS[$iIndex][4]
Local $hOBitmap, $hGraphic, $hHBitmap, $tCtrlInfo
; Select ActiveFrame in this hImage object specified by a dimension and an index.
DllCall($__g_hGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $avGRP_CTRLIDS[$iIndex][2], "ptr", $avGRP_CTRLIDS[$iIndex][3], "int", $avGRP_CTRLIDS[$iIndex][7])
; Check if resize flag is true
Switch $avGRP_CTRLIDS[$iIndex][9] ; Resize flag: 1 true, 0 false
Case 1
$tCtrlInfo = $avGRP_CTRLIDS[$iIndex][1]
; Creates a Bitmap object based on size and format information.
$hOBitmap = __GDIPCreateBitmapFromScan0(DllStructGetData($tCtrlInfo, "Width"), DllStructGetData($tCtrlInfo, "Height"), 0, $GDIP_PXF32ARGB, 0)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hOBitmap)
DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphic, "int", 7)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $avGRP_CTRLIDS[$iIndex][2], 0, 0, DllStructGetData($tCtrlInfo, "Width"), DllStructGetData($tCtrlInfo, "Height"))
_GDIPlus_GraphicsDispose($hGraphic)
; Create a handle to a bitmap from a bitmap object used to render frames!
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hOBitmap)
_GDIPlus_ImageDispose($hOBitmap)
$tCtrlInfo = 0
Case 0
; Create a handle to a bitmap from a bitmap object used to render frames!
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($avGRP_CTRLIDS[$iIndex][2])
EndSwitch
; Fills the structure with the Image data!
Switch $avGRP_CTRLIDS[$iIndex][8]
Case 1
If $avGRP_CTRLIDS[$iIndex][18] And Not $avGRP_CTRLIDS[$iIndex][19] Then
Local $hDC = _WinAPI_GetDC($avGRP_CTRLIDS[$iIndex][12])
Local $aCall = DllCall($hGRP_GDI32, "dword", "GetBkColor", "handle", $hDC)
_GUIImageList_SetBkColor($avGRP_CTRLIDS[$iIndex][14], $aCall[0])
_WinAPI_ReleaseDC($avGRP_CTRLIDS[$iIndex][12], $hDC)
$avGRP_CTRLIDS[$iIndex][19] = $aCall[0]
EndIf
;_GUIImageList_Add($avGRP_CTRLIDS[$iIndex][14], $hHBitmap)
DllCall($hGRP_COMCTL32, "int", "ImageList_Add", _
"handle", $avGRP_CTRLIDS[$iIndex][14], _ ; Handle to the control
"handle", $hHBitmap, _ ; Handle to the bitmap that contains the image or images.
"handle", 0) ; Mask = 0
__GRP_DeleteObj($hHBitmap);_WinAPI_DeleteObject($hHBitmap)
Case 0
$vGRP_TEMP = $avGRP_CTRLIDS[$iIndex][14]
If IsArray($vGRP_TEMP) Then
$vGRP_TEMP[$avGRP_CTRLIDS[$iIndex][7]] = $hHBitmap
$avGRP_CTRLIDS[$iIndex][14] = $vGRP_TEMP
Else
__GRP_DeleteObj($hHBitmap);_WinAPI_DeleteObject($hHBitmap)
EndIf
$hHBitmap = 0
EndSwitch
; Increment flag...
$avGRP_CTRLIDS[$iIndex][11] += 1
Case Else
__GRP_KillTimer($hWnd, $iIndex)
$vGRP_TEMP = $avGRP_CTRLIDS[$iIndex][5]
DllStructSetData($avGRP_CTRLIDS[$iIndex][1], "Function", "__GRP_DrawFrame")
Return __GRP_CreateTimer($hWnd, $vGRP_TEMP[$avGRP_CTRLIDS[$iIndex][7]], "__GRP_DrawFrame", $iIndex)
EndSwitch
__GRP_DrawFrame($hWnd, $Msg, $iIndex, $dwTime)
EndFunc ;==>__GRP_BuildList
; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __GRP_DrawFrame
; Description ...: To provides Animation Timer functionality.
; Syntax.........: __GRP_DrawFrame()
; Parameters ....: $hWnd, $Msg, $iIDTimer, $dwTime
; Return values .:
; Author ........: JScript
; Modified.......:
; Remarks .......: Based on Prog@ndy work concept!
; Related .......:
; Link ..........:
; Example .......; __GRP_DrawFrame($hWnd, $Msg, $iIndex, $dwTime)
; ===============================================================================================================================
Func __GRP_DrawFrame($hWnd, $Msg, $iIndex, $dwTime)
#forceref $hWnd, $Msg, $iIndex, $dwTime
;------------------------------
; Note: $iIndex = $iIDTimer !!!
;------------------------------
;----> ControlID array sample.
#cs
$avGRP_CTRLIDS[$iIndex][0] = $iCtrlID ; control ID
$avGRP_CTRLIDS[$iIndex][1] = $tCtrlInfo ; control info structure.
$avGRP_CTRLIDS[$iIndex][2] = $hOImage
$avGRP_CTRLIDS[$iIndex][3] = $pDimensionIDs
$avGRP_CTRLIDS[$iIndex][4] = $iFrameCount
$avGRP_CTRLIDS[$iIndex][5] = $aiFrameDelays
$avGRP_CTRLIDS[$iIndex][6] = $iLoopCount * $iFrameCount ; Repeat count
$avGRP_CTRLIDS[$iIndex][7] = 0 ; First frame
$avGRP_CTRLIDS[$iIndex][8] = $iDefaultRender ; Render to use.
$avGRP_CTRLIDS[$iIndex][9] = $iReSize ; Resize=1 true, 0 false
$avGRP_CTRLIDS[$iIndex][10] = $iTransMode ; Mode to render transparency!
$avGRP_CTRLIDS[$iIndex][11] = 0 ; Flag to fill ImageList first! 0=empty
$avGRP_CTRLIDS[$iIndex][12] = $hWndForm
$avGRP_CTRLIDS[$iIndex][13] = 0 ; _WinAPI_GetDC($hCtrlID)
$avGRP_CTRLIDS[$iIndex][14] = 0 ; _GUIImageList_Create
$avGRP_CTRLIDS[$iIndex][15] = 0 ; Callback identifier, need this for the Kill Timer.
$avGRP_CTRLIDS[$iIndex][16] = 0 ; Pointer to a callback identifier, need this for the __GRP_SetTimer.
$avGRP_CTRLIDS[$iIndex][17] = 0 ; Flag to checks if the timer needs to be set to avoid unnecessary use of CPU!
$avGRP_CTRLIDS[$iIndex][18] = $iTransparency ; Transparency flag.
$avGRP_CTRLIDS[$iIndex][19] = 0 ; GUI background color.
#ce
;<----
; Mode to render transparency: set $WS_EX_TRANSPARENT in control!!!
If $avGRP_CTRLIDS[$iIndex][10] Then
GUICtrlSetStyle($avGRP_CTRLIDS[$iIndex][0], -1, BitOR(DllStructGetData($avGRP_CTRLIDS[$iIndex][1], "ExStyle"), $WS_EX_TRANSPARENT))
EndIf
; Send GIF frame to control ID returned by _GUICtrlPic_Create() function.
Switch $avGRP_CTRLIDS[$iIndex][8]
Case 1
;_GUIImageList_Draw($avGRP_CTRLIDS[$iIndex][14], $avGRP_CTRLIDS[$iIndex][7], $avGRP_CTRLIDS[$iIndex][13], 0, 0, 1)
DllCall($hGRP_COMCTL32, "bool", "ImageList_Draw", _
"handle", $avGRP_CTRLIDS[$iIndex][14], _ ; $hWnd
"int", $avGRP_CTRLIDS[$iIndex][7], _ ; $iIndex
"handle", $avGRP_CTRLIDS[$iIndex][13], _ ; $hDC
"int", 0, "int", 0, "uint", 0) ; X, Y
Case 0
$vGRP_TEMP = $avGRP_CTRLIDS[$iIndex][14]
If IsArray($vGRP_TEMP) Then
__GRP_DeleteObj(GUICtrlSendMsg($avGRP_CTRLIDS[$iIndex][0], 0x0172, 0, $vGRP_TEMP[$avGRP_CTRLIDS[$iIndex][7]])) ; $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
EndIf
EndSwitch
; Checks if the timer needs to be set to avoid unnecessary use of CPU!
If $avGRP_CTRLIDS[$iIndex][17] Then
$vGRP_TEMP = $avGRP_CTRLIDS[$iIndex][5]
; Adjust Frame Timer based on Frame Delay.
__GRP_SetTimer($hWnd, $vGRP_TEMP[$avGRP_CTRLIDS[$iIndex][7]], $iIndex) ; __GRP_SetTimer($hWnd, DllStructGetData($avGRP_CTRLIDS[$iIndex][5], 1, $avGRP_CTRLIDS[$iIndex][7]), $iIndex)
EndIf
; Increment frame number.
$avGRP_CTRLIDS[$iIndex][7] += 1
; If FrameNumber = FrameCounter, reset FrameNumber to 0.
If $avGRP_CTRLIDS[$iIndex][7] > ($avGRP_CTRLIDS[$iIndex][4] - 1) Then
$avGRP_CTRLIDS[$iIndex][7] = 0
EndIf
; Loop count.
If $avGRP_CTRLIDS[$iIndex][6] Then
$avGRP_CTRLIDS[$iIndex][6] -= 1
If Not $avGRP_CTRLIDS[$iIndex][6] Then
__GRP_KillTimer($hWnd, $iIndex)
__GRP_hImgToCtrl($avGRP_CTRLIDS[$iIndex][0], $avGRP_CTRLIDS[$iIndex][2], $avGRP_CTRLIDS[$iIndex][3], $avGRP_CTRLIDS[$iIndex][7])
EndIf
EndIf