Jump to content
fs1234

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)

GUISetState()

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

While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            Exit
        Case $MSG = $B_Button1
            $Store = "Number"
            $StoreName = "Name"
            _Display()
    EndSelect
WEnd

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

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)
    _WinAPI_FreeLibrary($hLib)
    _WinAPI_DeleteObject($hBmp)
EndFunc

Could someone help me?

Thank you!

Share this post


Link to post
Share on other sites
Posted (edited)

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)
GUISetState(@SW_SHOW)
GUICtrlSetImage($Button1, $sFileName, 10)

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

    EndSwitch
WEnd

 

Edited by abberration

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Thanks, abberration,

Your code works great with shell32.dll (icon?), but I would need it with bitmap. I didn't test with my own dll, but with the windows cards.dll.

I attached the file.

 

Thanks again

cards.dll

Share this post


Link to post
Share on other sites

I have been researching for over an hour trying to figure out how to access data in a dll (I have very little experience with dlls). I learned a good bit today, but haven't figured it out yet. In the mean time, I just ran across something that may solve your problem:

 


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Thanks abberation and Zedna,

With the help of ResourcesEx I managed to solve the problem.

Share this post


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

×
×
  • Create New...