fs1234 Posted April 4, 2019 Posted April 4, 2019 Hi All, I would like to use images on the buttons, but not working.I tried the code below: expandcollapse popup#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!
abberration Posted April 4, 2019 Posted April 4, 2019 (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 April 4, 2019 by abberration Easy MP3 | Software Installer | Password Manager
fs1234 Posted April 4, 2019 Author Posted April 4, 2019 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
abberration Posted April 4, 2019 Posted April 4, 2019 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: Easy MP3 | Software Installer | Password Manager
Zedna Posted April 5, 2019 Posted April 5, 2019 Look at sources and examples of Resources & ResourcesEx UDF. Link is in my signature ... Resources UDF ResourcesEx UDF AutoIt Forum Search
fs1234 Posted April 5, 2019 Author Posted April 5, 2019 Thanks abberation and Zedna, With the help of ResourcesEx I managed to solve the problem.
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