Jump to content

Recommended Posts

Posted (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 by Who
Posted

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

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.

Posted (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 by Who
  • 1 month later...
Posted

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

Posted

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 ...

Posted

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
Posted

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

post-16922-12813631170351_thumb.jpg

Posted (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 by Zedna
  • 4 weeks later...
Posted (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.

here

Cheers

Edited by matrixnz
  • 4 weeks later...
Posted

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)
Posted (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 by FaceOff
  • Moderators
Posted

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:

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

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

Basically 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. :shocked:

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • 1 month later...
Posted (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:

#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 by BullGates

[topic="51913"]Restrict USB Storage usage to group membership[/topic] * [topic="48699"]Using nircmd library[/topic] * Some admin notes

Posted

BullGates,

thank you for your work! :graduated:

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.

Posted

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

Posted

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

  • 2 weeks later...
Posted (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 by longworthbob

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...