Recommended Posts

So if you haven't noticed Zedna's Resources UDF has been a very popular UDF over the last 7 years and was last updated in 2011, but now is the time to bring the UDF up to date with the current AutoIt language syntax (v3.3.14.2). So with the blessing of Zedna may I present to you ResourcesEx. It's built using the UDF standards I have tried to enforce around here, with improved documentation and an overall UDF structure.

I please ask that you try and break the UDF, criticise, educate, whatever, just play around with the functions and example. I do ask that you just don't say "you've missed the point" and leave at that. Provide an alternative or constructive reason as to why I have "missed the point".

Thanks.

IMPORTANT: You must be using SciTE4AutoIt3, as this comes included with AutoItWrapper

_ResourceSetImageToCtrl() works with "static/button" type of controls (picture,label,icon,button,checkbox,radiobutton,groupbox) [NO_ISSUE]

_ResourcePlaySound() plays only WAV files (not MP3 files) [FIXED]

_ResourceGetAsBytes() doesn't work for RT_BITMAP type because _ResourceGet() returns hBitmap instead of memory pointer in this case there could be used _ResourceGetAsImage() as workaround

_ResourceGet() has potential memory leak releasing of resources UnlockResource, FreeResource (opposite of LoadResource, LockResource) is not done because it must be done after using of resources at the end and not inside UDF [FIXED]

_GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is called [FIXED]

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() formely 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: Additonal 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_Shudown() due to the addition of _Resource_Destroy() and _Resource_DestroyAll()
2014/07/06:
Added: _Resource_Shudown() 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

Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Share this post

Link to post

Share on other sites

With all due respect please leave your opinion out of this discussion, as you are undermining my hard work of many hours. You clearly lack a basic understanding in programming and what the ternary operator is, because it's not just AutoIt where you can find it.

All,

For those who actually have an interest in programming, please test the UDF and leave unnecessary comments about the direction of AutoIt out of it.

Note: If the ternary issue is stopping people using it then I can switch to using __Iif() which is part of WinAPIInternals.au3 (aka WinAPIEx.au3) and is either a wrapper for the ternary operator or the old if statment, depending on what version of WinAPIEx you're using. So...up to you people.

Share this post

Link to post

Share on other sites

Stick with the ternary syntax - if people do not like it (or do not want to update to support it) then they can modify the code themselves.

_ResourceGet() has potential memory leak

[...]

because it must be done after using of resources at the end and not inside UDF

Perhaps store called resources in an array which is then used by an "Internal Use Only" UDF function called on exit via OnAutoItExitRegister. I do something similar in my NoFocusLines UDF.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area