au3scr Posted October 4, 2008 Share Posted October 4, 2008 How to Add image on button if shortcut file path is not *.exe? Here is my script that generates Buttons and sets image to button.1st it read all *.lnk files from desktop,2 nd it generates bottons from list, 3.rd it sets images for buttons thatway it reads file location from shortcut and then it gets icon from shortcuts location. But the problem is that if shortcut target file is NOT ending with *.exe then button dont get any icon. How I can make button have an Icon if shortcut's target file ends with *.txt or *.rar or if it is folder? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #Region ### START Koda GUI section ### Form= Global $FilesToArray = _FileListToArray(@DesktopDir, "*.lnk", 1) Global $Shortcuts[$FilesToArray[0]] $x = 0 $y = 0 $Form1 = GUICreate("Form1", 200, 447, 193, 125) $Button1 = GUICtrlCreateButton("(Not allowed)", 200, 120, 36, 36, BitOR($BS_PUSHBOX,$BS_FLAT,$BS_ICON)) GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0) $Button2 = GUICtrlCreateButton("(Not allowed)", 260, 100, 36, 36, BitOR($BS_PUSHBOX,$BS_FLAT,$BS_ICON)) GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0) For $i = 1 To $FilesToArray[0] -1 $file = FileGetShortcut (@DesktopDir & "\" &$FilesToArray[$i]) $Shortcuts[$i] = GUICtrlCreateButton($FilesToArray[$i],$x,$y,36,36,BitOR($BS_PUSHBOX,$BS_FLAT,$BS_ICON)) $imgpath = $File[0] GUICtrlSetImage(-1, $imgpath, 0) ;~ GUICtrlSetImage(-1, @WindowsDir &"\explorer.exe", 0) ;~ msgbox (1,1,$File[0]) $x = $x + 36 If $x > 200 Then $y = $Y + 36 $x = 0 EndIf Next GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd Link to comment Share on other sites More sharing options...
Valuater Posted October 4, 2008 Share Posted October 4, 2008 I took it a little further...expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #Region ### START Koda GUI section ### Form= Global $FilesToArray = _FileListToArray(@DesktopDir, "*.lnk", 1) Global $Shortcuts[$FilesToArray[0]] $x = 0 $y = 0 $Form1 = GUICreate("Form1", 220, 447, 193, 125) $Button1 = GUICtrlCreateButton("(Not allowed)", 200, 120, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON)) GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0) $Button2 = GUICtrlCreateButton("(Not allowed)", 260, 100, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON)) GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0) For $i = 1 To $FilesToArray[0] - 1 $file = FileGetShortcut(@DesktopDir & "\" & $FilesToArray[$i]) $Shortcuts[$i] = GUICtrlCreateButton($FilesToArray[$i], $x, $y, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON)) $imgpath = $file[0] If StringRight($imgpath, 4) = ".exe" Then GUICtrlSetImage(-1, $imgpath, 0) ElseIf StringRight($imgpath, 4) = ".txt" Then GUICtrlSetStyle(-1, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 27) ElseIf StringRight($imgpath, 4) = ".htm" Then GUICtrlSetStyle(-1, $BS_ICON) GUICtrlSetImage(-1, @ProgramFilesDir & "\Internet Explorer\iexplore.exe",0) ElseIf Not StringInStr($imgpath, ".") Then GUICtrlSetStyle(-1, $BS_ICON) GUICtrlSetImage(-1, @WindowsDir & "\explorer.exe",0) Else ; use others MsgBox(1, 1, $file[0]) EndIf $x = $x + 36 If $x > 200 Then $y = $y + 36 $x = 0 EndIf Next GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEndI did something very similar herehttp://www.autoitscript.com/forum/index.ph...st&p=3057488) 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