mrx71 Posted April 22 Share Posted April 22 Hello. I'm new to the forum and not an experienced coder, but over the course of more than ten years I've already created a few little helpers with AutoIt. A big thank you to the developers of and the community around AutoIt, which I can no longer do without. The many posts here in the forum have always been a great help to me. Now I have a question for which I couldn't find anything in the forum. It relates to "Button Icons With _WinAPI_ExtractIconEx" from Bilgus: https://www.autoitscript.com/forum/topic/193150-button-icons-with-_winapi_extracticonex/ There, icons extracted via _WinAPI_ExtractIconEx are sent via GUICtrlSendMsg to buttons created with GUICtrlCreateButton. The method used can obviously not be transferred to icon controls (GUICtrlCreateIcon) without further ado. Can this work at all? Unfortunately, I don't understand it. I have reduced Bilgus' script to the bare essentials as an example to demonstrate both in comparison. Perhaps someone knows the solution to this, if it works at all as I imagine. Thanks again to everyone. expandcollapse popup#include <GuiButton.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPITheme.au3> #include <WindowsConstants.au3> $hMainGUI = GUICreate ("Example", 300, 300) GUISetBkColor (0xFFFFFF, $hMainGUI) GUISetState (@SW_SHOW, $hMainGUI) $iIconCount = _WinAPI_ExtractIconEx ("shell32.dll", -1, 0, 0, 0) $tResIcons = DllStructCreate ("HANDLE[" & $iIconCount & "]") $pResIcons = DllStructGetPtr ($tResIcons) $iIconCount = _WinAPI_ExtractIconEx ("shell32.dll", 0, $pResIcons, 0, $iIconCount) $idButton = GUICtrlCreateButton ("", 50, 50, 45, 45, $BS_ICON) GUICtrlSetImage (-1, "shell32.dll", 16781) $idIcon = GUICtrlCreateIcon ("shell32.dll", 2, 50, 170, 45, 45) GUICtrlSetImage (-1, "shell32.dll", 16780) Sleep (1000) ; This works. GUICtrlSendMsg ($idButton, $BM_SETIMAGE, $IMAGE_ICON, DllStructGetData ($tResIcons, 1, 297)) GUICtrlCreateLabel ("This works.", 50, 100) Sleep (1000) ; Does not work. GUICtrlSendMsg ($idIcon, $BM_SETIMAGE, $IMAGE_ICON, DllStructGetData ($tResIcons, 1, 297)) GUICtrlCreateLabel ("Does not work.", 50, 220) For $i = 1 To $iIconCount _WinAPI_DestroyIcon (DllStructGetData ($tResIcons, 1, $i)) Next While True $nMsg = GUIGetMsg () If $nMsg = $GUI_EVENT_CLOSE Then Exit WEnd Example.au3 Link to comment Share on other sites More sharing options...
Nine Posted April 22 Share Posted April 22 Maybe there is a better way, but this is working for me : GUICtrlDelete($idIcon) Sleep(20) $idIcon = GUICtrlCreateIcon ("", 2, 50, 170, 45, 45) Local $hDC = _WinAPI_GetDC(GUICtrlGetHandle($idIcon)) _WinAPI_DrawIcon($hDC, 0, 0, DllStructGetData ($tResIcons, 1, 297)) GUICtrlCreateLabel ("This now works.", 50, 220) mrx71 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Solution ioa747 Posted April 22 Solution Share Posted April 22 (edited) ; This works. -> because it's a button, and $BM_SETIMAGE = 0xF7 is ButtonConstants GUICtrlSendMsg ($idButton, $BM_SETIMAGE, $IMAGE_ICON, DllStructGetData ($tResIcons, 1, 297)) GUICtrlCreateLabel ("This works.", 50, 100) Sleep (1000) ; Does not work. -> because it's not a button, -> $STM_SETIMAGE = 0x0172 is StaticConstants -> Now works GUICtrlSendMsg ($idIcon, $STM_SETIMAGE, $IMAGE_ICON, DllStructGetData ($tResIcons, 1, 297)) GUICtrlCreateLabel ("Now works.", 50, 220) https://learn.microsoft.com/en-us/windows/win32/controls/individual-control-info #include <ButtonConstants.au3> ; C:\Program Files (x86)\AutoIt3\Include\ButtonConstants.au3 #include <StaticConstants.au3> ; C:\Program Files (x86)\AutoIt3\Include\StaticConstants.au3 Edited April 22 by ioa747 Nine and mrx71 1 1 I know that I know nothing Link to comment Share on other sites More sharing options...
mrx71 Posted April 22 Author Share Posted April 22 @ioa747 and @Nine Great, thank you both. Both solutions work perfectly. I'll keep them both in mind in case they produce different results under different circumstances. Link to comment Share on other sites More sharing options...
Nine Posted April 22 Share Posted April 22 This also works (for anyone interested) : GUICtrlSendMsg($idIcon, $STM_SETICON, DllStructGetData ($tResIcons, 1, 297), 0) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ioa747 Posted April 22 Share Posted April 22 (edited) I also tried this first, it doesn't work Edited April 22 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted April 22 Share Posted April 22 It does work for me....Win10 ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ioa747 Posted April 22 Share Posted April 22 (edited) in already existing scripts? me....Win10 too Edit: GUICtrlSendMsg($idIcon, $STM_SETICON, $IMAGE_ICON, DllStructGetData($tResIcons, 1, 297)) GUICtrlSendMsg($idIcon, $STM_SETICON, DllStructGetData($tResIcons, 1, 297), 0) yes, the second one works, I tried the first one Edited April 22 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
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