Diana (Cda) Posted November 20, 2014 Share Posted November 20, 2014 (edited) Good evening! I have a very similar question to here, the only actual thread I found that was asking pretty much the same thing as I need to figure out: . In my case, got things to work out just fine when I used the code straight up in each line where it should go (i.e., when not trying to do this via variables at all): GUICtrlSetImage(-1, @SystemDir & "shell32.dll", 240, 0) GUISetIcon(@SystemDir & "shell32.dll", 133) [icons used above from the shell32.dll: #240 and #133] Here's where I run into trouble, though: since I like to re-use/recycle code a lot rather typing everything new all the time, I really love to use variables, and putting variables at the top in an easily identifiable, editable format. So I replaced the pertinent parts of GUICtrlSetImage and GUISetIcon as seen here below (showing here with incomplete, imperfectly-working @SystemDir and shell32.dll references with no icon numbers listed): ;================================================================== ; VARIABLES - without icon references as they don't work yet if I put icon numbers: $icon_for_GUI = @SystemDir & "\shell32.dll" $icon_for_CLEAR_button = @SystemDir & "\shell32.dll" ;================================================================== (This _doesn't_ work, and for obvious reasons. the ', 240' and ', 133' parts are by their lonesome!: $icon_for_GUI = @SystemDir & "shell32.dll", 240 $icon_for_CLEAR_button = @SystemDir & "shell32.dll", 133) and the rest of the code in the body, like this: GUICtrlSetImage(-1, $icon_for_CLEAR_button, 0) ... GUISetIcon($icon_for_GUI) The problem happens when I try to reference the 240 and 133 icons. I have to leave them out as the codes stands now as seen in the variables section above, otherwise I get errors. There must be a way to do something similar to the above but getting the icons we want to be displayed from the shell32.dll. Unfortunately, I tried everything I could think of - extra brackets, extra quotation marks, replacing quotes with apostrophes, all the usual things I tried but that didn't work this time to fix the parsing errors. When I put the @SystemDir & "shell32.dll" reference right in the body of the code with its ", 240" and ", 133" afterwards, no problem. But when I extract and put as a variable, I'm missing the key to encasing the actual icon reference within the variable so that it works. Right now, I have the GUI showing with the $icon_for_GUI and $icon_for_CLEAR_button variables without the icon numbers b/c at least it works that way. I get a generic icon, and I suspect that the code above makes the GUI just latch onto the first icon in shell32.dll. See, I've always made my GUIs referencing icons within the same folder and a @scriptdir path, but I'd like to make things cleaner, and especially for GUI scripts, would like to start referencing shell32.dll icons, instead of having icon files all over the place wherever there's a GUI au3 in a folder. If someone can help with the bit that I'm missing, that would be grand. (These were no help, either: https://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm, https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlButton_GetImage.htm, as the same problem persists. How to have right syntax in variables so one's icon choice is used at any given moment in a GUI script.) Thank you! Edited November 25, 2014 by Diana (Cda) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 21, 2014 Moderators Share Posted November 21, 2014 You cannot do something like this? #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $sDLL = @SystemDir & "\shell32.dll" GUICreate("Test", 140, 150) $button1 = GUICtrlCreateButton("My Button #1", 10, 10, 120, 50) GUICtrlSetImage(-1,$sDLL, 133) $button2 = GUICtrlCreateButton("My Button #1", 10, 80, 120, 50) GUICtrlSetImage(-1,$sDLL, 240) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Diana (Cda) Posted November 21, 2014 Author Share Posted November 21, 2014 (edited) Hi, there and thank you for your response. What's great is that I actually don't need to re-do the script in a different format. I just need to figure out, something I haven't yet done with success, the correct format for the syntax to choose a specific shell32.dll icon. When I do this type of thing where the icon reference is all within the same line: GUICtrlSetImage(-1, @SystemDir & "\shell32.dll", 240, 0) GUISetIcon(@SystemDir & "\shell32.dll", 133) the right icon is shown in both places, the GUI itself and the button, with no errors. But these are embedded in the body of the document and that's not desirable. By using variables, I don't have to track down what to change when I recycle code, I just change what is in the variables section that I place right at the top of all my scripts and just put in the new references for the new script, like this (though this is missing the icon references which give errors at this stage): ;================================================================== ; VARIABLES - without icon references as they don't work yet if I put icon numbers: $icon_for_GUI = @SystemDir & "\shell32.dll" $icon_for_CLEAR_button = @SystemDir & "\shell32.dll" ;================================================================== In other words, I get errors with this type of thing in the variables section: ;================================================================== ; VARIABLES - without icon references as they don't work yet if I put icon numbers: $icon_for_GUI = @SystemDir & "\shell32.dll", 240 $icon_for_CLEAR_button = @SystemDir & "\shell32.dll", 133 ;================================================================== I've tried everything that I can think of, along these lines but I'm missing something simple as nothing I've tried along the lines below has worked so far: $icon_for_GUI = '@SystemDir & "shell32.dll", 240' $icon_for_GUI = (@SystemDir & "shell32.dll", 240) $icon_for_GUI = @SystemDir & "shell32.dll", '240' (I know, dumb, but I just tried everything ...) Etc., etc. I get this type of error when I try anyting like the above: Error: Illegal text at the end of statement (one statement per line). So it's just a question of figuring out how to get the icon references to work when extracted to a variable, not to re-do the script, which kind of defeats the purpose. Thank you once again. I'm hoping I explained it better and that someone here knows how to put the icon reference into the variable so that no errors happen and I can customize icons without having loose icons in folders all over my hdd <lol>. Cheers! Edited November 21, 2014 by Diana (Cda) Link to comment Share on other sites More sharing options...
BrewManNH Posted November 21, 2014 Share Posted November 21, 2014 (edited) Do it this way. ;================================================================== ; VARIABLES - without icon references as they don't work yet if I put icon numbers: $icon_File = @SystemDir & "\shell32.dll" $icon_for_GUI = 240 $icon_for_CLEAR_button = 133 ;================================================================== GUICtrlSetImage(-1, $icon_File, $icon_for_GUI, 0) GUISetIcon($icon_File, $icon_for_CLEAR_button) Edited November 21, 2014 by BrewManNH Diana (Cda) 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Diana (Cda) Posted November 25, 2014 Author Share Posted November 25, 2014 (edited) Do it this way. ;================================================================== ; VARIABLES - without icon references as they don't work yet if I put icon numbers: $icon_File = @SystemDir & "\shell32.dll" $icon_for_GUI = 240 $icon_for_CLEAR_button = 133 ;================================================================== GUICtrlSetImage(-1, $icon_File, $icon_for_GUI, 0) GUISetIcon($icon_File, $icon_for_CLEAR_button) Now _that_ is "bloody brilliant", as they say in Harry Potter <lol>!! So easy! And isn't that they way it always is. I _knew_ it was do-able; I just was going nowhere fast and re-hashing the same old thing <g>. I'm going to be free of having little icons all over the place now!! Beautiful. I played around a bit with the syntax to get something generic enough to work for all my future needs. Granted, probably not elegant or anything, but it sure as heck is perfect for me. All my GUIs now can have this type of format at the top, along with any other variables I might need/use in any given script: ; ICONS FROM SHELL32.DLL: From - BrewManNH MVPs / Posted 21 November 2014 - 06:45 PM [http://www.autoitscript.com/forum/topic/165797-how-to-apply-icons-from-shell32dll/]: ; Original syntax examples for non-variable, "direct" shell32.dll icon references, GUI and BUTTON: 1. GUISetIcon(@SystemDir & "\shell32.dll", 133) / 2. GUICtrlSetImage(-1, @SystemDir & "\shell32.dll", 240, 0) $IconSourceFile_Shell32_dll = @SystemDir & "\shell32.dll" ;------------------------------------------- $shell32_dll_icon_for_GUI = "133" $shell32_dll_icon_for_CLEAR_BUTTON = "240" ;================================================================================================================= And then in the body of the code, where it's needed: GUICtrlSetImage(-1, $IconSourceFile_Shell32_dll, $shell32_dll_icon_for_CLEAR_BUTTON, 0) GUISetIcon($IconSourceFile_Shell32_dll, $shell32_dll_icon_for_GUI) Like I said, probably not elegant coding, or anything, but it sure as heck does the job for me, and then some!! I love it. Thank you!!! Much appreciated. Edited November 25, 2014 by Diana (Cda) 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