forked from rcmaehl/WhyNotWin11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourcesEx.au3
1348 lines (1208 loc) · 61.2 KB
/
ResourcesEx.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
; #Tidy_Parameters=/sort_funcs /reel
#include-once
#include <APIResConstants.au3>
#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <GUIMenu.au3>
#include <Memory.au3>
#include <StaticConstants.au3>
#include <WinAPIMisc.au3>
#include <WinAPIRes.au3>
#include <WindowsConstants.au3>
; Call once the script has ended to tidy up the used resources
OnAutoItExitRegister(_GDIPlus_Shutdown)
OnAutoItExitRegister(_Resource_DestroyAll)
_GDIPlus_Startup()
#Region ResourcesEx.au3 - Header
; #INDEX# =======================================================================================================================
; Title .........: ResourcesEx
; AutoIt Version : 3.3.12.0+
; Language ......: English
; Description ...:
; Author ........: Zedna (original)
; Modified ......: guinness (current). Thanks to Jos, Larry, Melba23, mLipok, ProgAndy, UEZ, ward and Yashied
; Dll ...........:
; ===============================================================================================================================
#cs
TODO:
Bug testing by the AutoIt community: http://www.autoitscript.com/forum/topic/162499-resourcesex-udf/
http://pastebin.com/5ru8H0cN
Code examples:
http://www.autoitscript.com/forum/topic/74565-extracticontofile-with-simple-gui-example/page-2#entry670142
Ref by AZJIO: http://www.autoitscript.com/forum/topic/51103-resources-udf/?p=1013300
Ref by Funkey: http://www.autoitscript.com/forum/topic/140449-createresourcedll/
Ref by ward: http://www.autoitscript.com/forum/topic/156041-resource-project-third-version/
Ref by Yashied: http://www.autoitscript.com/forum/topic/51103-resources-udf/?p=1147585
Resources:
Resources Ref: http://www.skynet.ie/~caolan/publink/winresdump/winresdump/doc/resfmt.txt
Resources Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa381043(v=vs.85).aspx
Icons Ref: http://msdn.microsoft.com/en-gb/library/windows/desktop/ms648050(v=vs.85).aspx#_win32_Icon_Sizes
Changelog:
2015/09/26
Changed: Comments throughout the UDF, removing trailing dot
Fixed: Various cosmetic changes
2015/01/12
Fixed: Example directive using double equals sign
Fixed: Delete functions not being cast as a bool value. (Thanks Synix)
Fixed: @error and @extended not be passed back in nested functions e.g. _Resource_GetAsRaw()
2014/07/19
Added: _Resource_SetBitmapToCtrlID() formerly known as _Resource_SetImageToCtrlID()
Added: Note about using #AutoIt3Wrapper_Res_Icon_Add to the example. (Thanks Zedna)
Added: Passing a blank string to _Resource_SetToCtrlID() through the $sResNameOrID parameter, will delete the image and previous handle
Changed: _Resource_SetImageToCtrlID() now accepts a hBitmap not a HBITMAP object
Fixed: _Resource_GetAsBitmap() now works the same way as _ResourceGetAsBitmap() did, by converting a jpg, png etc... to HBITMAP
Fixed: Memory management of some functions
2014/07/18
Fixed: Destroying a cursor
Fixed: Regression from loading the current of external module. (Thanks UEZ)
2014/07/17
Added: Additional checks to destroy cursors and icons
Added: Checking if the dll or exe filepath has a valid extension
Added: Example of using an icon and image on a button control
Fixed: Icons and cursors (finally) being re-sized to a control
Fixed: Using GUIGetStyle() on a non-AutoIt handle would cause issue with controls
Fixed: Variable naming of $sDLL to $sDllOrExePath for improved clarity
Removed: Workaround for setting icons to AutoIt controls
2014/07/17
Added: Commented workaround in the example for re-sizing an icon control
Added: ResourcesEx_PE.au3 created by PreExpand for all you constant variable haters out there!!!
Fixed: Changelog comments and source code comments
Fixed: Re-sizing icons when the control was different to the icon's size. (Thanks czardas for the MSDN link and Jon.)
Fixed: Re-sizing cursors and icons in general
2014/07/15
Added: Comments about using SOUND for wav files and RT_RCDATA for mp3 files. (Thanks Melba23)
Added: Option to relevant functions to re-size the image based on the control's dimensions. (Requested by kinch: http://www.autoitscript.com/forum/topic/51103-resources-udf/?p=1147525)
Added: Using _Resource_LoadFont() example. (Thanks UEZ)
Changed: Certain example resources to now use those found in %AUTOITDIR%\Examples\Helpfile\Extras
Changed: Constants and enums readability. (Thank mLipok)
Changed: Internal functions for destroying resources
Changed: Removed changes made from the previous version for loading resources multiple times. The design needs to be re-thought
Changed: Setting styles of controls using native AutoIt functions
Fixed: Destroying control resource images would fail to show if reinstated again
Fixed: Documentation comments
Fixed: Missing certain users who helped with creating this UDF
Fixed: Outdated SciTE files
2014/07/14:
Added: _Resource_GetAsCursor(), for the loading of animated cursors and standard cursors which can then be used with _WinAPI_SetCursor()
Added: _Resource_GetAsIcon(), for loading icon resource types
Added: _Resource_LoadFont(), which retrieves a font resource and adds to the current memory of the associated module
Added: _Resource_SetCursorToCtrlID() and _Resource_SetIconToCtrlID()
Added: Additional resource types to destroy on exit, including $RT_FONT, $RT_ICON and $RT_MENU
Added: Playing Mp3s to _Resource_LoadSound(). (Thanks to UEZ and Melba23 with changes made by me.)
Changed: _Resource_GetAsBitmap() returns a HTBITMAP handle without converting from hBitmap to HBITMAP
Changed: _Resource_PlaySound() to _Resource_LoadSound()
Changed: _Resource_SetBitmapToCtrlID() to _Resource_SetImageToCtrlID()
Changed: _SendMessage() to GUICtrlSendMsg()
Changed: Example files
Changed: Setting $iError in the internal get function
Changed: Signature of _Resource_Destroy()
Changed: Updated example to reflect major changes to the ResourcesEx UDF
Changed: Various UDF tweaks that I didn't document because I simply couldn't keep track of all the playing around I did in the last week
Fixed: _Resource_GetAsImage() not returning an error when a bitmap couldn't be found in the resource table
Fixed: Retrieving length of a string
Fixed: Using the current module instead of zero in _Resource_LoadSound()
Fixed: Various comment changes. (Thanks mLipok)
Fixed: Loading resources multiple times. This is fixed thanks to using the internal storage array
2014/07/07:
Added: _Resource_Destroy() and _Resource_DestroyAll() to destroy a particular resource name or all resources
Added: Checking if the resource name of id value is empty
Added: Descriptions, though could do with a little tweaking
Changed: _Resource_Get() to _Resource_GetAsRaw()
Changed: Internal workings of __Resource_Storage()
Changed: Re-size the storage array when destroyed or on shutdown
Fixed: _Resource_GetAsString() with default encoding of ANSI
Fixed: Calltips API referencing Resources.au3 and not ResourcesEx.au3
Removed: _Resource_Shutdown() due to the addition of _Resource_Destroy() and _Resource_DestroyAll()
2014/07/06:
Added: _Resource_Shutdown() to free up those resources which aren't loaded using _WinAPI_LockResource(). UnlockResource is obsolete
Added: Support for using $RT_STRING
Changed: _Resource_GetAsString() now works correctly for most encodings. (Thanks Jos)
Changed: _Resource_GetAsString() will now load as a string if the resource type requested is $RT_STRING
2014/07/04:
Added: #Regions. (Thanks mLipok)
Added: #Tidy_Parameters=/sort_funcs /reel (Thanks mLipok)
Added: All optional params now accept the default keyword
Added: Link to this thread. (Thanks mLipok)
Added: Main header. (Thanks mLipok)
Changed: $f.... >> $b..... (Thanks mLipok)
2014/07/03:
Initial release
#ce
#EndRegion ResourcesEx.au3 - Header
#Region ResourcesEx.au3 - #VARIABLES#
; #VARIABLES# ===================================================================================================================
; Error enumeration flags
Global Enum _
$RESOURCE_ERROR_NONE, _
$RESOURCE_ERROR_FINDRESOURCE, _
$RESOURCE_ERROR_INVALIDCONTROLID, _
$RESOURCE_ERROR_INVALIDCLASS, _
$RESOURCE_ERROR_INVALIDRESOURCENAME, _
$RESOURCE_ERROR_INVALIDRESOURCETYPE, _
$RESOURCE_ERROR_LOCKRESOURCE, _
$RESOURCE_ERROR_LOADBITMAP, _
$RESOURCE_ERROR_LOADCURSOR, _
$RESOURCE_ERROR_LOADICON, _
$RESOURCE_ERROR_LOADIMAGE, _
$RESOURCE_ERROR_LOADLIBRARY, _
$RESOURCE_ERROR_LOADSTRING, _
$RESOURCE_ERROR_SETIMAGE
Global Const _
$RESOURCE_SS_ENHMETAFILE = 0xF
Global Const _
$RESOURCE_SS_REALSIZECONTROL = 0x40
Global Const _
$RESOURCE_STM_SETICON = 0x0170
Global Const _
$RESOURCE_STM_GETIMAGE = 0x0173
Global Const _
$RESOURCE_STM_SETIMAGE = 0x0172
Global Const _
$RESOURCE_LANG_DEFAULT = 0
Global Enum _
$RESOURCE_RT_BITMAP = 1000, _
$RESOURCE_RT_ENHMETAFILE, _
$RESOURCE_RT_FONT
Global Enum _
$RESOURCE_POS_H, _
$RESOURCE_POS_W, _
$RESOURCE_POS_MAX
Global Const _
$RESOURCE_STORAGE_GUID = 'CA37F1E6-04D1-11E4-B340-4B0AE3E253B6'
Global Enum _
$RESOURCE_STORAGE, _
$RESOURCE_STORAGE_FIRSTINDEX
Global Enum _
$RESOURCE_STORAGE_ID, _
$RESOURCE_STORAGE_INDEX, _
$RESOURCE_STORAGE_RESETCOUNT, _
$RESOURCE_STORAGE_UBOUND
Global Enum _
$RESOURCE_STORAGE_DLL, _
$RESOURCE_STORAGE_CASTRESTYPE, _
$RESOURCE_STORAGE_LENGTH, _
$RESOURCE_STORAGE_PTR, _
$RESOURCE_STORAGE_RESLANG, _
$RESOURCE_STORAGE_RESNAMEORID, _
$RESOURCE_STORAGE_RESTYPE, _
$RESOURCE_STORAGE_MAX, _
$RESOURCE_STORAGE_ADD, _
$RESOURCE_STORAGE_DESTROY, _
$RESOURCE_STORAGE_DESTROYALL, _
$RESOURCE_STORAGE_GET
Global Enum _
$RESOURCE_WINGETPOS_XPOS, _
$RESOURCE_WINGETPOS_YPOS, _
$RESOURCE_WINGETPOS_WIDTH, _
$RESOURCE_WINGETPOS_HEIGHT
; ===============================================================================================================================
#EndRegion ResourcesEx.au3 - #VARIABLES#
#Region ResourcesEx.au3 - #FUNCTION#
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_Destroy
; Description ...: Destroy a resource name or id value
; Syntax ........: _Resource_Destroy($sResNameOrID[, $iResType = $RT_RCDATA])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $iResLang - [optional] A language identifier. Default value is 0
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - True
; Failure - False
; Author ........: guinness
; Modified ......:
; Remarks .......: Destroys the open $RT_BITMAP handles etc...of a resource name or id value
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_Destroy($sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $sDllOrExePath = Default)
If $iResLang = Default Then $iResLang = $RESOURCE_LANG_DEFAULT
If $iResType = Default Then $iResType = $RT_RCDATA
Return __Resource_Storage($RESOURCE_STORAGE_DESTROY, $sDllOrExePath, Null, $sResNameOrID, $iResType, $iResLang, $iResType, Null)
EndFunc ;==>_Resource_Destroy
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_DestroyAll
; Description ...: Destroy all resources
; Syntax ........: _Resource_DestroyAll()
; Parameters ....: None
; Return values .: Success - True
; Failure - False
; Author ........: guinness
; Modified ......:
; Remarks .......: Destroys all open $RT_BITMAP handles etc...of a resource name or id value
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_DestroyAll()
Return __Resource_Storage($RESOURCE_STORAGE_DESTROYALL, Null, Null, Null, Null, Null, Null, Null)
EndFunc ;==>_Resource_DestroyAll
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsBitmap
; Description ...: Get an image resource as a HBITMAP handle
; Syntax ........: _Resource_GetAsBitmap($sResNameOrID[, $iResType = $RT_RCDATA[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - HBITMAP handle
; Failure - Zero and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsBitmap($sResNameOrID, $iResType = $RT_RCDATA, $sDllOrExePath = Default)
Local $hHBITMAP = 0, $hBitmap = _Resource_GetAsImage($sResNameOrID, $iResType, $sDllOrExePath)
Local $iError = @error
Local $iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
$hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ; Convert to HBITMAP
If @error Then
$iError = $RESOURCE_ERROR_LOADBITMAP
Else
_GDIPlus_BitmapDispose($hBitmap)
$hBitmap = 0
EndIf
EndIf
If $iError <> $RESOURCE_ERROR_NONE Then $hHBITMAP = 0
Return SetError($iError, $iLength, $hHBITMAP)
EndFunc ;==>_Resource_GetAsBitmap
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsCursor
; Description ...: Get a resource as a cursor handle
; Syntax ........: _Resource_GetAsCursor($sResNameOrID[, $iResType = $RT_RCDATA[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - Cursor handle
; Failure - Zero and sets @error to non-zero
; Author ........: guinness
; Modified ......:
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsCursor($sResNameOrID, $iResType = $RT_RCDATA, $sDllOrExePath = Default)
Local $hCursor = __Resource_Get($sResNameOrID, $iResType, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_CURSOR)
Local $iError = @error
Local $iLength = @extended
If $iError <> $RESOURCE_ERROR_NONE Then $hCursor = 0
Return SetError($iError, $iLength, $hCursor)
EndFunc ;==>_Resource_GetAsCursor
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsBytes
; Description ...: Get a resources as bytes
; Syntax ........: _Resource_GetAsBytes($sResNameOrID[, $iResType = $RT_RCDATA[, $iResLang = Default[, $sDllOrExePath = Default]]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $iResLang - [optional] A language identifier. Default value is 0
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - String of bytes
; Failure - Empty byte string and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......: The size of the resource is stored in @extended. Doesn't work for RT_BITMAP type because _Resource_GetAsRaw() returns HBITMAP instead of memory pointer
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsBytes($sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $sDllOrExePath = Default)
Local $pResource = __Resource_Get($sResNameOrID, $iResType, $iResLang, $sDllOrExePath, $RT_RCDATA)
Local $iError = @error
Local $iLength = @extended
Local $dBytes = Binary(Null)
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
Local $tBuffer = DllStructCreate('byte array[' & $iLength & ']', $pResource)
$dBytes = DllStructGetData($tBuffer, 'array')
EndIf
Return SetError($iError, $iLength, $dBytes)
EndFunc ;==>_Resource_GetAsBytes
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsIcon
; Description ...: Get a resource as an icon handle
; Syntax ........: _Resource_GetAsIcon($sResNameOrID[, $iResType = $RT_RCDATA[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - Icon handle
; Failure - Zero and sets @error to non-zero
; Author ........: guinness
; Modified ......:
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsIcon($sResNameOrID, $iResType = $RT_RCDATA, $sDllOrExePath = Default)
Local $hIcon = __Resource_Get($sResNameOrID, $iResType, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_ICON)
Local $iError = @error
Local $iLength = @extended
If $iError <> $RESOURCE_ERROR_NONE Then $hIcon = 0
Return SetError($iError, $iLength, $hIcon)
EndFunc ;==>_Resource_GetAsIcon
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsImage
; Description ...: Get a resource as a hBitmap handle
; Syntax ........: _Resource_GetAsImage($sResNameOrID[, $iResType = $RT_RCDATA[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - hBitmap handle
; Failure - Zero and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness. Thanks to ProgAndy and UEZ
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsImage($sResNameOrID, $iResType = $RT_RCDATA, $sDllOrExePath = Default)
If $iResType = Default Then $iResType = $RT_RCDATA
Local $iError = $RESOURCE_ERROR_LOADIMAGE, $iLength = 0, _
$hBitmap = 0
Switch $iResType
Case $RT_BITMAP
Local $hHBITMAP = __Resource_Get($sResNameOrID, $RT_BITMAP, 0, $sDllOrExePath, $RT_BITMAP)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
If @error Then
$iError = $RESOURCE_ERROR_LOADIMAGE
Else
; _GDIPlus_BitmapDispose($hHBITMAP) ; Creates hard crash
; $hHBITMAP = 0
EndIf
EndIf
Case Else
Local $pResource = __Resource_Get($sResNameOrID, $iResType, 0, $sDllOrExePath, $RT_RCDATA)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
$hBitmap = __Resource_ConvertToBitmap($pResource, $iLength)
EndIf
EndSwitch
Return SetError($iError, $iLength, $hBitmap)
EndFunc ;==>_Resource_GetAsImage
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsRaw
; Description ...: Get a resource in a raw format
; Syntax ........: _Resource_GetAsRaw($sResNameOrID[, $iResType = $RT_RCDATA[, $iResLang = Default[, $sDllOrExePath = Default]]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $iResLang - [optional] A language identifier. Default value is 0
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - Resource pointer
; Failure - Null and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsRaw($sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $sDllOrExePath = Default)
Local $hResource = __Resource_Get($sResNameOrID, $iResType, $iResLang, $sDllOrExePath, $RT_RCDATA)
Return SetError(@error, @extended, $hResource)
EndFunc ;==>_Resource_GetAsRaw
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_GetAsString
; Description ...: Get a resource as a string
; Syntax ........: _Resource_GetAsString($sResNameOrID[, $iResType = $RT_RCDATA[, $iResLang = Default[, $sDllOrExePath = Default]]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $iResLang - [optional] A language identifier. Default value is 0
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - String
; Failure - Empty string and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness. Thanks to Jos
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_GetAsString($sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $sDllOrExePath = Default)
Local $iError = $RESOURCE_ERROR_LOADSTRING, _
$iLength = 0, _
$sString = ''
Switch $iResType
Case $RT_RCDATA
Local $dBytes = _Resource_GetAsBytes($sResNameOrID, $iResType, $iResLang, $sDllOrExePath)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then ; Parse the data by retrieving the correct encoding
Local Enum _
$BINARYTOSTRING_NONE, _
$BINARYTOSTRING_ANSI, _
$BINARYTOSTRING_UTF16LE, _
$BINARYTOSTRING_UTF16BE, _
$BINARYTOSTRING_UTF8
Local $iStart = $BINARYTOSTRING_NONE, $iUTFEncoding = $BINARYTOSTRING_ANSI
Local Const $sUTF8 = '0xEFBBBF', _
$sUTF16BE = '0xFEFF', _
$sUTF16LE = '0xFFFE', _
$sUTF32BE = '0x0000FEFF', _
$sUTF32LE = '0xFFFE0000'
Local $iUTF8 = BinaryLen($sUTF8), _
$iUTF16BE = BinaryLen($sUTF16BE), _
$iUTF16LE = BinaryLen($sUTF16LE), _
$iUTF32BE = BinaryLen($sUTF32BE), _
$iUTF32LE = BinaryLen($sUTF32LE)
Select
Case BinaryMid($dBytes, 1, $iUTF32BE) = $sUTF32BE
$iStart = $iUTF32BE
$iUTFEncoding = $BINARYTOSTRING_ANSI
Case BinaryMid($dBytes, 1, $iUTF32LE) = $sUTF32LE
$iStart = $iUTF32LE
$iUTFEncoding = $BINARYTOSTRING_ANSI
Case BinaryMid($dBytes, 1, $iUTF16BE) = $sUTF16BE
$iStart = $iUTF16BE
$iUTFEncoding = $BINARYTOSTRING_UTF16BE
Case BinaryMid($dBytes, 1, $iUTF16LE) = $sUTF16LE
$iStart = $iUTF16LE
$iUTFEncoding = $BINARYTOSTRING_UTF16LE
Case BinaryMid($dBytes, 1, $iUTF8) = $sUTF8
$iStart = $iUTF8
$iUTFEncoding = $BINARYTOSTRING_UTF8
EndSelect
$iStart += 1 ; Increase by 1 to strip the byte order mark
$iLength = $iLength + 1 - $iStart
$sString = BinaryToString(BinaryMid($dBytes, $iStart), $iUTFEncoding)
EndIf
$dBytes = 0
Case $RT_STRING
$sString = __Resource_Get($sResNameOrID, $iResType, $iResLang, $sDllOrExePath, $iResType)
$iError = @error
$iLength = @extended
EndSwitch
Return SetError($iError, $iLength, $sString)
EndFunc ;==>_Resource_GetAsString
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_LoadFont
; Description ...: Load a font resource into the memory of the specified module
; Syntax ........: _Resource_LoadFont($sResNameOrID[, $iResLang = Default[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iResLang - [optional] A language identifier. Default value is 0
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - Resource pointer
; Failure - Null and sets @error to non-zero
; Author ........: guinness
; Modified ......:
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_LoadFont($sResNameOrID, $iResLang = Default, $sDllOrExePath = Default)
Local $pResource = __Resource_Get($sResNameOrID, $RT_FONT, $iResLang, $sDllOrExePath, $RT_FONT)
Local $iError = @error
Local $iLength = @extended
If $iError = $RESOURCE_ERROR_NONE Then
Local $hFont = _WinAPI_AddFontMemResourceEx($pResource, $iLength) ; Load the font to memory and add to the internal storage array
__Resource_Storage($RESOURCE_STORAGE_ADD, $sDllOrExePath, $hFont, $sResNameOrID, $RESOURCE_RT_FONT, $iResLang, $RESOURCE_RT_FONT, $iLength)
$hFont = 0
EndIf
Return SetError($iError, $iLength, $pResource)
EndFunc ;==>_Resource_LoadFont
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_LoadSound
; Description ...: Load (play) a sound resource. This is limited to mp3 and wav only
; Syntax ........: _Resource_LoadSound($sResNameOrID[, $iFlags = $SND_SYNC[, $sDllOrExePath = Default]])
; Parameters ....: $sResNameOrID - A resource name or id value
; $iFlags - [optional] See $iFlags for the $SND_* constants in _WinAPI_PlaySound(). Default value is $SND_SYNC
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness. Thanks to Larry, ProgAndy, UEZ, Melba23
; Remarks .......: Use the resource type RT_RCDATA for mp3 files and SOUND for wav files
; Related .......:
; Link ..........: http://msdn2.microsoft.com/en-us/library/ms712879.aspx
; ===============================================================================================================================
Func _Resource_LoadSound($sResNameOrID, $iFlags = $SND_SYNC, $sDllOrExePath = Default) ; Returns no @error, just True or False
Local $bIsInternal = False, $bReturn = False
Local $hInstance = __Resource_LoadModule($sDllOrExePath, $bIsInternal)
If Not $hInstance Then Return SetError($RESOURCE_ERROR_LOADLIBRARY, 0, $bReturn) ; Return an error as an issue occurred and there is no point in continuing
Local $dSound = _Resource_GetAsBytes($sResNameOrID) ; Assume mp3 so look in RT_RCDATA
Local $iLength = @extended
If Not $iLength Then
; Assume a wav file
$bReturn = _WinAPI_PlaySound($sResNameOrID, BitOR($SND_RESOURCE, $iFlags), $hInstance)
Else
; Convert mp3 to a hybrid wav
Local $sAlign_Buffer = '00', _
$sHeader_1 = '0x52494646', _
$sHeader_2 = '57415645666D74201E0000005500020044AC0000581B0000010000000C00010002000000B600010071056661637404000000640E060064617461'
Local $sMp3 = StringTrimLeft(Binary($dSound), StringLen('00'))
Local Const $iByte = 8
; Convert to required format
Local $iMp3Size = StringRegExpReplace(Hex($iLength, $iByte), '(..)(..)(..)(..)', '$4$3$2$1')
Local $iWavSize = StringRegExpReplace(Hex($iLength + 63, $iByte), '(..)(..)(..)(..)', '$4$3$2$1')
; Construct hybrid wav file
Local $sHybridWav = $sHeader_1 & $iWavSize & $sHeader_2 & $iMp3Size & $sMp3
If Mod($iMp3Size, 2) Then
$sHybridWav &= $sAlign_Buffer
EndIf
; Create struct
Local $tWAV = DllStructCreate('byte array[' & BinaryLen($sHybridWav) & ']')
DllStructSetData($tWAV, 'array', $sHybridWav)
$iFlags = BitOR($SND_MEMORY, $SND_NODEFAULT, $iFlags) ; Set the appropriate flags
$bReturn = _WinAPI_PlaySound(DllStructGetPtr($tWAV), $iFlags, $hInstance)
EndIf
__Resource_UnloadModule($hInstance, $bIsInternal)
Return $bReturn
EndFunc ;==>_Resource_LoadSound
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SaveToFile
; Description ...: Save a resource to a file
; Syntax ........: _Resource_SaveToFile($sFilePath, $sResNameOrID[, $iResType = $RT_RCDATA[, $iResLang = Default[, $bCreatePath = Default[,
; $sDllOrExePath = Default]]]])
; Parameters ....: $sFilePath - The filepath to save the resource to
; $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $iResLang - [optional] A language identifier. Default value is 0
; $bCreatePath - [optional] Create the path if it doesn't exist. Default value is False
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SaveToFile($sFilePath, $sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $bCreatePath = Default, $sDllOrExePath = Default)
Local $bReturn = False, _
$iCreatePath = (IsBool($bCreatePath) And $bCreatePath ? $FO_CREATEPATH : 0), $iError = $RESOURCE_ERROR_NONE, $iLength = 0
If $iResType = Default Then $iResType = $RT_RCDATA
If $iResType = $RT_BITMAP Then
; Workaround: for RT_BITMAP _Resource_GetAsBytes() doesn't work so use _Resource_GetAsImage() instead
Local $hImage = _Resource_GetAsImage($sResNameOrID, $iResType)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
FileClose(FileOpen($sFilePath, BitOR($FO_OVERWRITE, $FO_BINARY, $iCreatePath))) ; Create the filepath
$bReturn = _GDIPlus_ImageSaveToFile($hImage, $sFilePath)
_GDIPlus_ImageDispose($hImage)
EndIf
Else
Local $dBytes = _Resource_GetAsBytes($sResNameOrID, $iResType, $iResLang, $sDllOrExePath)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
Local $hFileOpen = FileOpen($sFilePath, BitOR($FO_OVERWRITE, $FO_BINARY, $iCreatePath))
If $hFileOpen > -1 Then
$bReturn = True
FileWrite($hFileOpen, $dBytes)
FileClose($hFileOpen)
EndIf
EndIf
EndIf
Return SetError($iError, $iLength, $bReturn)
EndFunc ;==>_Resource_SaveToFile
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SetBitmapToCtrlID
; Description ...: Set a HBITMAP handle to controlid
; Syntax ........: _Resource_SetBitmapToCtrlID($iCtrlID, $hHBITMAP)
; Parameters ....: $iCtrlID - A valid controlid
; $hHBITMAP - A HBITMAP handle
; $bResize - [optional] Resize the image based on the controlid's dimensions. Default is False
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SetBitmapToCtrlID($iCtrlID, $hHBITMAP, $bResize = Default)
Local $bReturn = __Resource_SetToCtrlID($iCtrlID, $hHBITMAP, $RT_BITMAP, False, $bResize)
Return SetError(@error, @extended, $bReturn)
EndFunc ;==>_Resource_SetBitmapToCtrlID
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SetCursorToCtrlID
; Description ...: Set a cursor handle to controlid
; Syntax ........: _Resource_SetCursorToCtrlID($iCtrlID, $hCursor)
; Parameters ....: $iCtrlID - A valid controlid
; $hCursor - A cursor handle
; $bResize - [optional] Resize the image based on the controlid's dimensions. Default is False
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: guinness
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SetCursorToCtrlID($iCtrlID, $hCursor, $bResize = Default)
Local $bReturn = __Resource_SetToCtrlID($iCtrlID, $hCursor, $RT_CURSOR, False, $bResize)
Return SetError(@error, @extended, $bReturn)
EndFunc ;==>_Resource_SetCursorToCtrlID
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SetIconToCtrlID
; Description ...: Set a icon handle to controlid
; Syntax ........: _Resource_SetIconToCtrlID($iCtrlID, $hIcon)
; Parameters ....: $iCtrlID - A valid controlid
; $hIcon - An icon handle
; $bResize - [optional] Resize the image based on the controlid's dimensions. Default is False
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: guinness
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SetIconToCtrlID($iCtrlID, $hIcon, $bResize = Default)
Local $bReturn = __Resource_SetToCtrlID($iCtrlID, $hIcon, $RT_ICON, False, $bResize)
Return SetError(@error, @extended, $bReturn)
EndFunc ;==>_Resource_SetIconToCtrlID
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SetImageToCtrlID
; Description ...: Set a hBitmap handle to controlid
; Syntax ........: _Resource_SetImageToCtrlID($iCtrlID, $hBitmap)
; Parameters ....: $iCtrlID - A valid controlid
; $hBitmap - A hBitmap handle
; $bResize - [optional] Resize the image based on the controlid's dimensions. Default is False
; Return values .: Success - True
; Failure - False and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SetImageToCtrlID($iCtrlID, $hBitmap, $bResize = Default)
Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ; Convert to HBITMAP
If @error Then
$hHBITMAP = 0
Else
_GDIPlus_BitmapDispose($hBitmap)
EndIf
$hBitmap = 0
Local $bReturn = __Resource_SetToCtrlID($iCtrlID, $hHBITMAP, $RT_BITMAP, False, $bResize)
Return SetError(@error, @extended, $bReturn)
EndFunc ;==>_Resource_SetImageToCtrlID
; #FUNCTION# ====================================================================================================================
; Name ..........: _Resource_SetToCtrlID
; Description ...: Set am image from resources to controlid
; Syntax ........: _Resource_SetToCtrlID($iCtrlID, $sResNameOrID[, $iResType = $RT_RCDATA[, $sDllOrExePath = Default]])
; Parameters ....: $iCtrlID - A valid controlid
; $sResNameOrID - A resource name or id value
; $iResType - [optional] Resource type. $RT_* constants located in APIResConstants.au3 Default value is $RT_RCDATA
; $sDllOrExePath - [optional] A filepath to an external Dll or executable. Default value is the current module
; $bResize - [optional] Resize the image based on the controlid's dimensions. Default is False
; Return values .: Success - True (if an image and on XP then it returns a HBITMAP handle which can then be destroyed by _WinAPI_DeleteObject() when no longer required.)
; Failure - False and sets @error to non-zero
; Author ........: Zedna
; Modified ......: guinness. Thanks to ProgAndy and UEZ
; Remarks .......: The size of the resource is stored in @extended
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _Resource_SetToCtrlID($iCtrlID, $sResNameOrID, $iResType = $RT_RCDATA, $sDllOrExePath = Default, $bResize = Default)
If $iResType = Default Then $iResType = $RT_RCDATA
Local $aWinGetPos = 0, _
$bDestroy = True, $bReturn = False, _
$iError = $RESOURCE_ERROR_INVALIDRESOURCETYPE, $iLength = 0, _
$vReturn = False
Local $hWnd = 0
__Resource_GetCtrlId($hWnd, $iCtrlID)
Switch $iResType
Case $RT_BITMAP, $RT_RCDATA
If StringStripWS($sResNameOrID, $STR_STRIPALL) = '' Or String($sResNameOrID) = '0' Then
$bReturn = __Resource_SetToCtrlID($iCtrlID, 0, $RT_BITMAP, True, False)
$iError = @error
Else
Local $hHBITMAP = _Resource_GetAsBitmap($sResNameOrID, $iResType, $sDllOrExePath) ; hBitmap
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE And $iLength > 0 Then
; $bDestroy = False
$bReturn = __Resource_SetToCtrlID($iCtrlID, $hHBITMAP, $RT_BITMAP, $bDestroy, $bResize)
$iError = @error
If $bReturn Then
If _WinAPI_GetVersion() >= 0x0600 Then
$bReturn = _WinAPI_DeleteObject($hHBITMAP) > 0 ; Delete if Vista or above
$vReturn = $bReturn
Else
__Resource_Storage($RESOURCE_STORAGE_ADD, $sDllOrExePath, $hHBITMAP, $sResNameOrID, $iResType, Null, $iResType, $iLength)
$vReturn = $hHBITMAP
EndIf
EndIf
EndIf
EndIf
Case $RT_CURSOR
If StringStripWS($sResNameOrID, $STR_STRIPALL) = '' Or String($sResNameOrID) = '0' Then
$bReturn = __Resource_SetToCtrlID($iCtrlID, 0, $RT_CURSOR, True, False)
$iError = @error
Else
$bDestroy = False
Local $hCursor = 0
If $bResize Then
$aWinGetPos = WinGetPos($hWnd)
If Not @error Then
Local $aPos[$RESOURCE_POS_MAX]
$aPos[$RESOURCE_POS_H] = $aWinGetPos[$RESOURCE_WINGETPOS_HEIGHT]
$aPos[$RESOURCE_POS_W] = $aWinGetPos[$RESOURCE_WINGETPOS_WIDTH]
If $aPos[$RESOURCE_POS_H] = 0 And $aPos[$RESOURCE_POS_W] = 0 Then
GUICtrlSetImage($iCtrlID, @AutoItExe, 0)
$aWinGetPos = WinGetPos($hWnd)
If Not @error Then
$aPos[$RESOURCE_POS_H] = $aWinGetPos[$RESOURCE_WINGETPOS_HEIGHT]
$aPos[$RESOURCE_POS_W] = $aWinGetPos[$RESOURCE_WINGETPOS_WIDTH]
EndIf
EndIf
$hCursor = __Resource_Get($sResNameOrID, $RT_CURSOR, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_CURSOR, $aPos)
$iError = @error
$iLength = @extended
EndIf
Else
$hCursor = _Resource_GetAsCursor($sResNameOrID, $iResType, $sDllOrExePath)
$iError = @error
$iLength = @extended
EndIf
If $iError = $RESOURCE_ERROR_NONE Then
$bReturn = __Resource_SetToCtrlID($iCtrlID, $hCursor, $RT_CURSOR, $bDestroy, $bResize)
EndIf
$hCursor = 0
$vReturn = $bReturn
EndIf
Case $RT_ICON
If StringStripWS($sResNameOrID, $STR_STRIPALL) = '' Or String($sResNameOrID) = '0' Then
$bReturn = __Resource_SetToCtrlID($iCtrlID, 0, $RT_ICON, True, False)
$iError = @error
Else
$bDestroy = False
Local $hIcon = 0
If $bResize Then
__Resource_GetCtrlId($hWnd, $iCtrlID)
$aWinGetPos = WinGetPos($hWnd)
If Not @error Then
Local $aPos[$RESOURCE_POS_MAX]
$aPos[$RESOURCE_POS_H] = $aWinGetPos[$RESOURCE_WINGETPOS_HEIGHT]
$aPos[$RESOURCE_POS_W] = $aWinGetPos[$RESOURCE_WINGETPOS_WIDTH]
If $aPos[$RESOURCE_POS_H] = 0 And $aPos[$RESOURCE_POS_W] = 0 Then
GUICtrlSetImage($iCtrlID, @AutoItExe, 0)
$aWinGetPos = WinGetPos($hWnd)
If Not @error Then
$aPos[$RESOURCE_POS_H] = $aWinGetPos[$RESOURCE_WINGETPOS_HEIGHT]
$aPos[$RESOURCE_POS_W] = $aWinGetPos[$RESOURCE_WINGETPOS_WIDTH]
EndIf
EndIf
$hIcon = __Resource_Get($sResNameOrID, $RT_ICON, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_ICON, $aPos)
$iError = @error
$iLength = @extended
#cs
If $iError = $RESOURCE_ERROR_NONE Then
Local $pData = __Resource_Get($sResNameOrID, $RT_ICON, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_ICON)
Local $iIconName = _WinAPI_LookupIconIdFromDirectoryEx($pData, True, $aWinGetPos[2], $aWinGetPos[3])
$pData = __Resource_Get($iIconName, $RT_ICON, $RESOURCE_LANG_DEFAULT, $sDllOrExePath, $RT_RCDATA)
$iError = @error
$iLength = @extended
If $iError = $RESOURCE_ERROR_NONE Then
$hIcon = _WinAPI_CreateIconFromResourceEx($pData, $iLength)
EndIf
EndIf
#ce
EndIf
Else
$hIcon = _Resource_GetAsIcon($sResNameOrID, $iResType, $sDllOrExePath)
$iError = @error
$iLength = @extended
EndIf
If $iError = $RESOURCE_ERROR_NONE Then
$bReturn = __Resource_SetToCtrlID($iCtrlID, $hIcon, $RT_ICON, $bDestroy, $bResize)
EndIf
$hIcon = 0
$vReturn = $bReturn
EndIf
EndSwitch
Return SetError($iError, $iLength, $vReturn)
EndFunc ;==>_Resource_SetToCtrlID
; INTERNAL FUNCTIONS
Func __Resource_ConvertToBitmap($pResource, $iLength) ; hBitmap
; Local $tByte = DllStructCreate('byte[' & $iLength & ']')
; _MemMoveMemory($pResource, DllStructGetPtr($tByte), $iLength)
Local $hData = _MemGlobalAlloc($iLength, $GMEM_MOVEABLE)
Local $pData = _MemGlobalLock($hData)
_MemMoveMemory($pResource, $pData, $iLength)
; _MemMoveMemory(DllStructGetPtr($tByte), $pData, $iLength)
_MemGlobalUnlock($hData)
Local $pStream = _WinAPI_CreateStreamOnHGlobal($hData)
Local $hBitmap = _GDIPlus_BitmapCreateFromStream($pStream) ; hBitmap
; _MemGlobalFree($hData) ; Uncomment and gifs don't work
_WinAPI_ReleaseStream($pStream)
Return $hBitmap ; To destroy use _GDIPlus_BitmapDispose()
EndFunc ;==>__Resource_ConvertToBitmap
Func __Resource_Destroy($pResource, $iResType)
Local $bReturn = False
Switch $iResType
Case $RT_ANICURSOR, $RT_CURSOR
$bReturn = _WinAPI_DeleteObject($pResource) > 0
If Not $bReturn Then
$bReturn = _WinAPI_DestroyCursor($pResource) > 0
EndIf
Case $RT_BITMAP
$bReturn = _WinAPI_DeleteObject($pResource) > 0
Case $RT_FONT
$bReturn = True ; No action required
Case $RT_ICON
$bReturn = _WinAPI_DeleteObject($pResource) > 0
If Not $bReturn Then
$bReturn = _WinAPI_DestroyIcon($pResource) > 0
EndIf
Case $RT_MENU
$bReturn = _GUICtrlMenu_DestroyMenu($pResource) > 0
Case $RT_STRING
$bReturn = True ; No action required
Case $RESOURCE_RT_BITMAP
$bReturn = _GDIPlus_BitmapDispose($pResource) > 0
Case $RESOURCE_RT_ENHMETAFILE
$bReturn = _WinAPI_DeleteEnhMetaFile($pResource) > 0
Case $RESOURCE_RT_FONT
$bReturn = _WinAPI_RemoveFontMemResourceEx($pResource) > 0
Case Else
$bReturn = True ; No action required
EndSwitch
If Not IsBool($bReturn) Then $bReturn = $bReturn > 0
Return $bReturn
EndFunc ;==>__Resource_Destroy
Func __Resource_Get($sResNameOrID, $iResType = $RT_RCDATA, $iResLang = Default, $sDllOrExePath = Default, $iCastResType = Default, $aPos = Null)
If $iResType = $RT_RCDATA And StringStripWS($sResNameOrID, $STR_STRIPALL) = '' Then Return SetError($RESOURCE_ERROR_INVALIDRESOURCENAME, 0, Null) ; If the resource name or id value is empty
If $iCastResType = Default Then $iCastResType = $iResType
If $iResLang = Default Then $iResLang = $RESOURCE_LANG_DEFAULT
If $iResType = Default Then $iResType = $RT_RCDATA
Local $iError = $RESOURCE_ERROR_NONE, $iLength = 0, _
$vResource = __Resource_Storage($RESOURCE_STORAGE_GET, $sDllOrExePath, Null, $sResNameOrID, $iResType, $iResLang, $iCastResType, Null)
$iLength = @extended
If $vResource Then
Return SetError($iError, $iLength, $vResource)
EndIf
Local $bIsInternal = False
Local $hInstance = __Resource_LoadModule($sDllOrExePath, $bIsInternal)
If Not $hInstance Then Return SetError($RESOURCE_ERROR_LOADLIBRARY, 0, 0) ; Return an error as an issue occurred and there is no point in continuing
Local $hResource = (($iResLang <> $RESOURCE_LANG_DEFAULT) ? _WinAPI_FindResourceEx($hInstance, $iResType, $sResNameOrID, $iResLang) : _WinAPI_FindResource($hInstance, $iResType, $sResNameOrID))
If @error <> $RESOURCE_ERROR_NONE Then $iError = $RESOURCE_ERROR_FINDRESOURCE
If $iError = $RESOURCE_ERROR_NONE Then
If $aPos = Null Then
Local $aTemp[$RESOURCE_POS_MAX] = [0, 0]
$aPos = $aTemp
$aTemp = 0
$aPos[$RESOURCE_POS_H] = 0
$aPos[$RESOURCE_POS_W] = 0
EndIf
$iLength = _WinAPI_SizeOfResource($hInstance, $hResource)
Switch $iCastResType
Case $RT_ANICURSOR, $RT_CURSOR
$vResource = _WinAPI_LoadImage($hInstance, $sResNameOrID, $IMAGE_CURSOR, $aPos[$RESOURCE_POS_W], $aPos[$RESOURCE_POS_H], $LR_DEFAULTCOLOR)
If @error <> $RESOURCE_ERROR_NONE Or Not $vResource Then $iError = $RESOURCE_ERROR_LOADCURSOR
Case $RT_BITMAP
$vResource = _WinAPI_LoadImage($hInstance, $sResNameOrID, $IMAGE_BITMAP, $aPos[$RESOURCE_POS_W], $aPos[$RESOURCE_POS_H], $LR_DEFAULTCOLOR)
If @error <> $RESOURCE_ERROR_NONE Or Not $vResource Then $iError = $RESOURCE_ERROR_LOADBITMAP
Case $RT_ICON
$vResource = _WinAPI_LoadImage($hInstance, $sResNameOrID, $IMAGE_ICON, $aPos[$RESOURCE_POS_W], $aPos[$RESOURCE_POS_H], $LR_DEFAULTCOLOR)
If @error <> $RESOURCE_ERROR_NONE Or Not $vResource Then $iError = $RESOURCE_ERROR_LOADICON
Case $RT_STRING
$vResource = _WinAPI_LoadString($hInstance, $sResNameOrID)
$iLength = @extended
If @error <> $RESOURCE_ERROR_NONE Then $iError = $RESOURCE_ERROR_LOADSTRING
Case Else ; $RT_RCDATA
Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
$vResource = _WinAPI_LockResource($hData)
$hData = 0
If Not $vResource Then $iError = $RESOURCE_ERROR_LOCKRESOURCE