Jump to content

Is it possible: image for buttons from dll?

Recommended Posts

Hi All,

I would like to use images on the buttons, but not working.I tried the code below:

#include <GUIConstants.au3>
#include <WinAPI.au3>

$Form1 = GUICreate("", 400, 400)
$pic = GUICtrlCreatePic("",  20, 40, 80, 80)


$B_Button1 = GUICtrlCreateButton("Button1", 20, 40, 80, 80, $BS_BITMAP)
GUICtrlSetImage(-1, GUICtrlSetImageFromDLL($pic, 'stores.dll', 1))

While 1
    $MSG = GUIGetMsg()
        Case $MSG = $GUI_EVENT_CLOSE
        Case $MSG = $B_Button1
            $Store = "Number"
            $StoreName = "Name"

Func _Display()
    MsgBox(0, $Store, $StoreName)

Func GUICtrlSetImageFromDLL($controlID, $filename, $imageIndex)
    Local Const $STM_SETIMAGE = 0x0172

    $hLib = _WinAPI_LoadLibrary($filename)
    $hBmp = _WinAPI_LoadImage($hLib, $imageIndex, $IMAGE_BITMAP, 0, 0, $LR_DEFAULTCOLOR)
    GUICtrlSendMsg($controlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)

Could someone help me?

Thank you!

Link to post
Share on other sites

I don't have the dll that you have, so I worked up some code. It was real quick and I have to go, so it's rough but it kind of works.


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Show the Windows PickIconDlg.
;Local $sFileName = @SystemDir & '\shell32.dll'

; Create a structure to store the icon index
Local $tIconIndex = DllStructCreate("int")
Local $tString = DllStructCreate("wchar[260]")
Local $iStructsize = DllStructGetSize($tString) / 2

DllCall("shell32.dll", "none", 62, _
        "hwnd", 0, _
        "struct*", $tString, _
        "int", $iStructsize, _
        "struct*", $tIconIndex)

$sFileName = DllStructGetData($tString, 1)
DllStructSetData($tString, 1, $sFileName)

$Form1 = GUICreate("Form1", 295, 120, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 128, 56, 75, 25, $WS_GROUP)
GUICtrlSetImage($Button1, $sFileName, 10)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE



Edited by abberration
Link to post
Share on other sites

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