Who Posted July 5, 2010 Posted July 5, 2010 (edited) This should work fine, no need to use my UDF for this #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIT\mainprog.ico ; replace 3 by your desired icon index ; remember there are some standard Autoit's icons in compiled EXE ; so your first added icon is not first in EXE _GUIImageList_AddIcon($GUI_ImageList, @AutoItExe, 3, True) Thanks, I will try that but it seems not to be an easy task. I complied the script and run PE Explorer to view the index of the icon, it's 50, but after editing the source _GUIImageList_AddIcon($GUI_ImageList, @AutoItExe, 50) Then the toolbar button is lost. If I try _GUIImageList_AddIcon($GUI_ImageList, @AutoItExe, 0) It's shown as the AutoIT icon. Edited July 5, 2010 by Who
Zedna Posted July 5, 2010 Author Posted July 5, 2010 Thanks, I will try that but it seems not to be an easy task. I complied the script and run PE Explorer to view the index of the icon, it's 50, but after editing the sourceIndex 50 is totally wrong.Use ResHacker to see right icon index.There are 3,4 or 5 standard icons in compiled Autoit's EXE I don't know the exact number.Also don't forget in ImageList functions you use zero based index. Resources UDF ResourcesEx UDF AutoIt Forum Search
Who Posted July 5, 2010 Posted July 5, 2010 (edited) Index 50 is totally wrong. Use ResHacker to see right icon index. There are 3,4 or 5 standard icons in compiled Autoit's EXE I don't know the exact number. Also don't forget in ImageList functions you use zero based index. After googling, I found out that the index for customs icon begin from -5. However, if I use this index with GUICtrlCreateIcon then everything's just fine. But if I use it with _GUIImageList_AddIcon then nothing's shown up. So am I misunderstand something or maybe it's a bug? #AutoIt3Wrapper_Res_Icon_Add=C:\Program Files\AutoIt3\Icons\filetype-blank.ico #include <GuiToolbar.au3> #include <GuiImageList.au3> #include <WinAPI.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hToolbar, $hNormal $hGUI = GUICreate("Toolbar", 400, 300) $hToolbar = _GUICtrlToolbar_Create($hGUI) GUICtrlCreateIcon(@AutoItExe, -5, 40, 40, 16, 16) ;~ This works $hNormal = _GUIImageList_Create(16, 16) ;~ _GUIImageList_AddIcon($hNormal, @AutoItExe, -5) ;~ This doesn't work _GUIImageList_AddIcon($hNormal, "C:\Program Files\AutoIt3\Icons\filetype-blank.ico", 0) ;~ This works _GUICtrlToolbar_SetImageList($hToolbar, $hNormal) _GUICtrlToolbar_AddButton($hToolbar, 0, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc Edited July 5, 2010 by Who
matrixnz Posted August 8, 2010 Posted August 8, 2010 Hi Zedna In Windows 7(64bit) the following two functions no longer appear to work for displaying JPG and Gifs: _ResourceGetAsImage _ResourceSetImageToCtrl _SetBitmapToCtrl works fine _ResourceGet as you mentioned in your first post seems to have a memory leak and crashes the script I can confirm that the resources are being embedded correctly. Cheers
Zedna Posted August 9, 2010 Author Posted August 9, 2010 Hi Zedna In Windows 7(64bit) the following two functions no longer appear to work for displaying JPG and Gifs: _ResourceGetAsImage _ResourceSetImageToCtrl _SetBitmapToCtrl works fine _ResourceGet as you mentioned in your first post seems to have a memory leak and crashes the script I can confirm that the resources are being embedded correctly. Cheers Thanks for the report. I think (but I'm not sure) it's because I use old ANSI API calls instead of newer Unicode (widechar) ones. So try to replace all DllCall() functions which end with "A" by their "W" alternatives and if there is any "char/str" structure then replace it by "wchar/wstr". This is quick test if it's source of these problems. Now looking at sources there seems to be only one place containing ANSI: FindResourceA,FindResourceExA in _ResourceGet() original ANSI: If $ResLang <> 0 Then $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceExA", "int", $hInstance, "long", $ResType, "str", $ResName, "short", $ResLang) Else $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hInstance, "str", $ResName, "long", $ResType) EndIf new Unicode/Widechar: If $ResLang <> 0 Then $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceExW", "int", $hInstance, "long", $ResType, "wstr", $ResName, "short", $ResLang) Else $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceW", "int", $hInstance, "wstr", $ResName, "long", $ResType) EndIf Try to replace it and tell me the result ... Resources UDF ResourcesEx UDF AutoIt Forum Search
Yashied Posted August 9, 2010 Posted August 9, 2010 Use "ptr" instead "int". If $ResLang <> 0 Then $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceExW", "ptr", $hInstance, "long", $ResType, "wstr", $ResName, "ushort", $ResLang) Else $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceW", "ptr", $hInstance, "wstr", $ResName, "long", $ResType) EndIf My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
matrixnz Posted August 9, 2010 Posted August 9, 2010 Hi Zedna, Yashied Tried both methods unfortunately still no change, no errors are reported. Also I should have said previously that _ResourceGet inconjunction with _SetBitmapToCtrl does work fine, it only crashed the script when attempting to use in conjunction with an icon. To set a Bitmap directly to a control _ResourceSetImageToCtrl($Control, "Resource", $RT_BITMAP) still works fine. Cheers
Zedna Posted August 9, 2010 Author Posted August 9, 2010 (edited) Also I should have said previously that _ResourceGet inconjunction with _SetBitmapToCtrl does work fine, it only crashed the script when attempting to use in conjunction with an icon.For icons you don't need my Resources UDF, just use GUICtrlSetImage(@ScriptFullPath, ...).Look at my post #442 at top of this page for detailed example ... Edited August 9, 2010 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
matrixnz Posted September 1, 2010 Posted September 1, 2010 (edited) Update: Using Trancexx _ResourceGetAsRaw function appears to work in Windows 7 x64...._ResourceGetAsRaw(@AutoItExe, 10, "TEST_JPG_3")...Also works with PNG with transparency which is really great.hereCheers Edited September 2, 2010 by matrixnz
playlet Posted September 25, 2010 Posted September 25, 2010 (edited) --- Edited August 18, 2016 by playlet
ekeem Posted September 28, 2010 Posted September 28, 2010 Hi Zedna, Thank you for this awesome UDF, love it. Hope you can help with this issue I come across? I can't figure it out. Is there anyway to resize an image as use below? I have tried guictrlsetpos with no luck. I have also tried a combination of GDI+ commands, but not experience with it, so failed there also. Does bmp or png make a difference? Please help, thank you in advance. No matter what size I set initially or after guisetstate, it only display the original size of the picture. #AutoIt3Wrapper_Res_File_Add=BlackBackGround.bmp, rt_bitmap, gr_BlackBackGround $BlackBkGrnd = GUICtrlCreatePic("", 0, 0, $gui_w, $gui_h, $WS_CLIPSIBLINGS) _ResourceSetImageToCtrl($BlackBkGrnd, "gr_BlackBackGround", $RT_BITMAP)
Zedna Posted October 1, 2010 Author Posted October 1, 2010 I'm still the most of time offline because of my bad accident so be patient as about your questions ... Resources UDF ResourcesEx UDF AutoIt Forum Search
FaceOff Posted October 5, 2010 Posted October 5, 2010 (edited) Hey guys! I'm a bit new to AutoIt and I started a project a few days ago. Now the best solution to solve my problem is your resources.au3! But I have a problem with this class Only the image load functions work, the GetAsString and GetAsBytes and also the SaveToFile functions doesn't work, even in your example script I really need to load some simple text / binary data from resource, so I would be pleased if someone could help me! My O/S is Windows 7 Ultimate x64 if this does matter. Cheers FaceOff Edit: It always returns just an empty string or a zero! Edited October 5, 2010 by FaceOff
Moderators Melba23 Posted October 6, 2010 Moderators Posted October 6, 2010 FaceOff,Welcome to the AutoIt forum. Zedna is not around that much at the moment, so I will try and help if I can. I too had this problem a while ago and made the following changes to the functions you mention to get them to work:expandcollapse popupFunc _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResPointer, $ResSize $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) If @error Then Return SetError(1, 0, 0) $ResSize = @extended $struct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer) Return DllStructGetData($struct, 1) ; returns bytes <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Melba23's fix EndFunc Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResStruct, $ResSize, $FileHandle If $CreatePath Then $CreatePath = 8 ; mode 8 = Create directory structure if it doesn't exist in FileOpen() If $ResType = $RT_BITMAP Then ; workaround: for RT_BITMAP _ResourceGetAsBytes() doesn't work so use _ResourceGetAsImage() $hImage = _ResourceGetAsImage($ResName, $ResType) If @error Then Return SetError(10, 0, 0) ; create filepath if doesn't exist $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If @error Then Return SetError(11, 0, 0) FileClose($FileHandle) If @error Then Return SetError(12, 0, 0) _GDIPlus_ImageSaveToFile($hImage, $FileName) _GDIPlus_ImageDispose($hImage) $ResSize = FileGetSize($FileName) Else ; standard way $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) ; - <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Melba23's fix If @error Then Return SetError(1, 0, 0) $ResSize = @extended $ResStruct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer) ; - <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< to here If @error Then Return SetError(1, 0, 0) $ResSize = DllStructGetSize($ResStruct) $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If @error Then Return SetError(2, 0, 0) FileWrite($FileHandle, DllStructGetData($ResStruct, 1)) If @error Then Return SetError(3, 0, 0) FileClose($FileHandle) If @error Then Return SetError(4, 0, 0) EndIf Return $ResSize EndFuncBasically the original _ResourceGetAsBytes was returning a structure, not the bytes themselves. Zedna and I had a long discussion about it much earlier in the thread and the end result was that he did not want to change it because it would be script breaking. So I just patch each new release as shown above so the functions do what they say on the label. The first patch extracts the actual bytes from the struct and returns them. The second patch removes the _ResourceGetAsBytes call from the _ResourceSaveToFile function and replaces it with code that gives the structure needed for the rest of the function and which is no longer provided after the first patch. I hope that makes sense. The above code works fine for me on Vista - give it a try in Win7 and let me know if it works there too. 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
BullGates Posted November 16, 2010 Posted November 16, 2010 (edited) In Windows 7 x64 I also had the same problem as you describe, after reading all posts and putting the ideas together, this finally seems to work great on both x64, x86 Windows 7 and Windows XP: resources.au3: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <WinAPI.au3> #include <GDIPlus.au3> #include <Memory.au3> _GDIPlus_Startup() Global Const $RT_CURSOR = 1 Global Const $RT_BITMAP = 2 Global Const $RT_ICON = 3 Global Const $RT_MENU = 4 Global Const $RT_DIALOG = 5 Global Const $RT_STRING = 6 Global Const $RT_FONTDIR = 7 Global Const $RT_FONT = 8 Global Const $RT_ACCELERATOR = 9 Global Const $RT_RCDATA = 10 Global Const $RT_MESSAGETABLE = 11 Global Const $RT_GROUP_CURSOR = 12 Global Const $RT_GROUP_ICON = 14 Global Const $RT_VERSION = 16 Global Const $RT_DLGINCLUDE = 17 Global Const $RT_PLUGPLAY = 19 Global Const $RT_VXD = 20 Global Const $RT_ANICURSOR = 21 Global Const $RT_ANIICON = 22 Global Const $RT_HTML = 23 Global Const $RT_MANIFEST = 24 Global Const $SND_RESOURCE = 0x00040004 Global Const $SND_SYNC = 0x0 Global Const $SND_ASYNC = 0x1 Global Const $SND_MEMORY = 0x4 Global Const $SND_LOOP = 0x8 Global Const $SND_NOSTOP = 0x10 Global Const $SND_NOWAIT = 0x2000 Global Const $SND_PURGE = 0x40 Func _ResourceGet($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10 Local Const $IMAGE_BITMAP = 0 Local $hInstance, $hBitmap, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize If $DLL = -1 Then $hInstance = _WinAPI_GetModuleHandle("") Else $hInstance = _WinAPI_LoadLibrary($DLL) EndIf If $hInstance = 0 Then Return SetError(1, 0, 0) If $ResType = $RT_BITMAP Then $hBitmap = _WinAPI_LoadImage($hInstance, $ResName, $IMAGE_BITMAP, 0, 0, 0) If @error Then Return SetError(2, 0, 0) Return $hBitmap ; returns handle to Bitmap EndIf If $ResLang <> 0 Then $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceExW", "ptr", $hInstance, "long", $ResType, "wstr", $ResName, "ushort", $ResLang) Else $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceW", "ptr", $hInstance, "wstr", $ResName, "long", $ResType) EndIf If @error Then Return SetError(3, 0, 0) $InfoBlock = $InfoBlock[0] If $InfoBlock = 0 Then Return SetError(4, 0, 0) $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "ptr", $hInstance, "ptr", $InfoBlock) If @error Then Return SetError(5, 0, 0) $ResSize = $ResSize[0] If $ResSize = 0 Then Return SetError(6, 0, 0) $GlobalMemoryBlock = DllCall("kernel32.dll", "ptr", "LoadResource", "ptr", $hInstance, "ptr", $InfoBlock) If @error Then Return SetError(7, 0, 0) $GlobalMemoryBlock = $GlobalMemoryBlock[0] If $GlobalMemoryBlock = 0 Then Return SetError(8, 0, 0) $MemoryPointer = DllCall("kernel32.dll", "ptr", "LockResource", "ptr", $GlobalMemoryBlock) If @error Then Return SetError(9, 0, 0) $MemoryPointer = $MemoryPointer[0] If $MemoryPointer = 0 Then Return SetError(10, 0, 0) If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance) If @error Then Return SetError(11, 0, 0) SetExtended($ResSize) Return $MemoryPointer EndFunc ; for ANSI strings Func _ResourceGetAsString($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResPointer, $ResSize, $struct $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) If @error Then SetError(1, 0, 0) Return '' EndIf $ResSize = @extended $struct = DllStructCreate("char[" & $ResSize & "]", $ResPointer) Return DllStructGetData($struct, 1) ; returns string EndFunc ; for Unicode strings (Widechar) Func _ResourceGetAsStringW($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResPointer, $ResSize, $struct $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) If @error Then SetError(1, 0, 0) Return '' EndIf $ResSize = @extended $struct = DllStructCreate("wchar[" & $ResSize & "]", $ResPointer) Return DllStructGetData($struct, 1) ; returns string EndFunc ; _ResourceGetAsBytes() doesn't work for RT_BITMAP type ; because _ResourceGet() returns hBitmap instead of memory pointer in this case Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResPointer, $ResSize $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) If @error Then Return SetError(1, 0, 0) $ResSize = @extended $struct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer) Return DllStructGetData($struct, 1) ; returns bytes <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Melba23's fix EndFunc ; returned hImage can be used in many GDI+ functions: ; $width = _GDIPlus_ImageGetWidth ($hImage) ; $height = _GDIPlus_ImageGetHeight($hImage) Func _ResourceGetAsImage($ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10 Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap $ResData = _ResourceGet($ResName, $ResType, 0, $DLL) If @error Then Return SetError(1, 0, 0) $nSize = @extended If $ResType = $RT_BITMAP Then ; $ResData is hBitmap type $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ResData) Else ; $ResData is memory pointer ; thanks ProgAndy $hData = _MemGlobalAlloc($nSize,2) $pData = _MemGlobalLock($hData) _MemMoveMemory($ResData,$pData,$nSize) _MemGlobalUnlock($hData) $pStream = DllCall( "ole32.dll","ptr","CreateStreamOnHGlobal", "ptr",$hData, "long",1, "Int*",0) $pStream = $pStream[3] $hImage = DllCall($ghGDIPDll,"ptr","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0) $hImage = $hImage[2] _WinAPI_DeleteObject($pStream) ; next line must be commented otherwise animated GIFs will not work ;~ _MemGlobalFree($hData) EndIf Return $hImage ; hImage type EndFunc Func _ResourceGetAsBitmap($ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10 $hImage = _ResourceGetAsImage($ResName, $ResType, $DLL) If @error Then Return SetError(1, 0, 0) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) Return $hBitmap ; hBitmap type EndFunc Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1) ; $RT_RCDATA = 10 Local $ResStruct, $ResSize, $FileHandle If $CreatePath Then $CreatePath = 8 ; mode 8 = Create directory structure if it doesn't exist in FileOpen() If $ResType = $RT_BITMAP Then ; workaround: for RT_BITMAP _ResourceGetAsBytes() doesn't work so use _ResourceGetAsImage() $hImage = _ResourceGetAsImage($ResName, $ResType) If @error Then Return SetError(10, 0, 0) ; create filepath if doesn't exist $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If @error Then Return SetError(11, 0, 0) FileClose($FileHandle) If @error Then Return SetError(12, 0, 0) _GDIPlus_ImageSaveToFile($hImage, $FileName) _GDIPlus_ImageDispose($hImage) $ResSize = FileGetSize($FileName) Else ; standard way $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL) ; - <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Melba23's fix If @error Then Return SetError(1, 0, 0) $ResSize = @extended $ResStruct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer) ; - <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< to here If @error Then Return SetError(1, 0, 0) $ResSize = DllStructGetSize($ResStruct) $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If @error Then Return SetError(2, 0, 0) FileWrite($FileHandle, DllStructGetData($ResStruct, 1)) If @error Then Return SetError(3, 0, 0) FileClose($FileHandle) If @error Then Return SetError(4, 0, 0) EndIf Return $ResSize EndFunc Func _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10 Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap $ResData = _ResourceGet($ResName, $ResType, 0, $DLL) If @error Then Return SetError(1, 0, 0) $nSize = @extended If $ResType = $RT_BITMAP Then _SetBitmapToCtrl($CtrlId, $ResData) If @error Then Return SetError(2, 0, 0) Else ; thanks ProgAndy ; for other types than BITMAP use GDI+ for converting to bitmap first $hData = _MemGlobalAlloc($nSize,2) $pData = _MemGlobalLock($hData) _MemMoveMemory($ResData,$pData,$nSize) _MemGlobalUnlock($hData) $pStream = DllCall( "ole32.dll","ptr","CreateStreamOnHGlobal", "ptr",$hData, "long",1, "Int*",0) $pStream = $pStream[3] $pBitmap = DllCall($ghGDIPDll,"ptr","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0) $pBitmap = $pBitmap[2] $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap) _SetBitmapToCtrl($CtrlId, $hBitmap) If @error Then SetError(3, 0, 0) _GDIPlus_BitmapDispose($pBitmap) _WinAPI_DeleteObject($pStream) _MemGlobalFree($hData) EndIf Return 1 EndFunc ; internal helper function ; thanks for improvements Melba Func _SetBitmapToCtrl($CtrlId, $hBitmap) Local Const $STM_SETIMAGE = 0x0172 Local Const $STM_GETIMAGE = 0x0173 Local Const $BM_SETIMAGE = 0xF7 Local Const $BM_GETIMAGE = 0xF6 Local Const $IMAGE_BITMAP = 0 Local Const $SS_BITMAP = 0x0E Local Const $BS_BITMAP = 0x0080 Local Const $GWL_STYLE = -16 Local $hWnd, $hPrev, $Style, $iCtrl_SETIMAGE, $iCtrl_GETIMAGE, $iCtrl_BITMAP ; determine control class and adjust constants accordingly Switch _WinAPI_GetClassName($CtrlId) Case "Button" ; button,checkbox,radiobutton,groupbox $iCtrl_SETIMAGE = $BM_SETIMAGE $iCtrl_GETIMAGE = $BM_GETIMAGE $iCtrl_BITMAP = $BS_BITMAP Case "Static" ; picture,icon,label $iCtrl_SETIMAGE = $STM_SETIMAGE $iCtrl_GETIMAGE = $STM_GETIMAGE $iCtrl_BITMAP = $SS_BITMAP Case Else Return SetError(1, 0, 0) EndSwitch $hWnd = GUICtrlGetHandle($CtrlId) If $hWnd = 0 Then Return SetError(2, 0, 0) ; set SS_BITMAP/BS_BITMAP style to the control $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) If @error Then Return SetError(3, 0, 0) _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $iCtrl_BITMAP)) If @error Then Return SetError(4, 0, 0) ; set image to the control $hPrev = _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, $hBitmap) If @error Then Return SetError(5, 0, 0) If $hPrev Then _WinAPI_DeleteObject($hPrev) Return 1 EndFunc ; thanks Larry,ProgAndy ; MSDN: http://msdn2.microsoft.com/en-us/library/ms712879.aspx ; default flag is $SND_SYNC = 0 Func _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1) If $DLL = -1 Then $hInstance = 0 Else $hInstance = _WinAPI_LoadLibrary($DLL) EndIf Local $ret = DllCall("winmm.dll", "ptr", "PlaySound", "str", $ResName, "hwnd", $hInstance, "ptr", BitOr($SND_RESOURCE,$Flag)) If @error Then Return SetError(1, 0, 0) If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance) If @error Then Return SetError(2, 0, 0) Return $ret[0] EndFunc Hope this helps! Edited November 16, 2010 by BullGates [topic="51913"]Restrict USB Storage usage to group membership[/topic] * [topic="48699"]Using nircmd library[/topic] * Some admin notes
supersonic Posted November 16, 2010 Posted November 16, 2010 BullGates, thank you for your work! Which version did you modified? Your version is without Melba23's fixes (= relase from 2010-02-12)... Aren't they no longer needed? Greets, -supersonic.
BullGates Posted November 16, 2010 Posted November 16, 2010 Melba fixes are present also, the comments are included as you can see. I did nothing special, I've just put all the hints together and it solved my problems under Windows 7 x64, I've also tested in Windows XP and it seems to work fine. resources.udf in my opinion should be included in autoit, it's quite useful. [topic="51913"]Restrict USB Storage usage to group membership[/topic] * [topic="48699"]Using nircmd library[/topic] * Some admin notes
trancexx Posted November 16, 2010 Posted November 16, 2010 Melba fixes are present also, the comments are included as you can see. I did nothing special, I've just put all the hints together and it solved my problems under Windows 7 x64, I've also tested in Windows XP and it seems to work fine. resources.udf in my opinion should be included in autoit, it's quite useful.Out of the question.It may be useful but in current form it should't even be used. ♡♡♡ . eMyvnE
longworthbob Posted November 26, 2010 Posted November 26, 2010 (edited) I was wondering if I missed something. When I download the resource_au3.zip file, it won't unzip. The program says it's invalid? This is from a Vista box; maybe I should try another system... Ok, I got it, you had zip in a zip... Edited November 26, 2010 by longworthbob
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now