Advertisement
Valiante

_ChooseIcon function

Feb 1st, 2024
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.59 KB | None | 0 0
  1. Func _ChooseIcon($fFileName = "")
  2.  
  3.     Local $_CI_IconCount, $_CI_FileName, $_CI_SelectedIconName, $_CI_IconRadios[30], $_CI_Labels[30],$_CI_NewFile
  4.     Local $_CI_oldEventMode = Opt("GuiOnEventMode",0)
  5.     Local $_CI_StartIndex = 1
  6.     Local $arTemp[2]
  7.     If FileExists($fFileName) Then
  8.         Local $_CI_FileName = $fFileName
  9.     Else
  10.         Local $_CI_FileName = @SystemDir & "\shell32.dll"
  11.     EndIf
  12.  
  13.     Local $_CI_hGui=GUICreate("Choose Icon:", 385, 450, -1, -1, -1, $WS_EX_ACCEPTFILES)
  14.     GUICtrlCreateGroup("", 5, 1, 375, 40)
  15.     GUICtrlCreateGroup("", 5, 50, 375, 350)
  16.     Local $_CI_hFile = GUICtrlCreateInput($_CI_FileName, 12,  15, 325, 16, -1, $WS_EX_STATICEDGE)
  17.     GUICtrlSetState(-1, $GUI_DROPACCEPTED)
  18.     GUICtrlSetTip(-1, "You can drop files from shell here...")
  19.     Local $_CI_hStatus = GUICtrlCreateInput("", 90, 49, 200, 16, $ES_READONLY, $WS_EX_STATICEDGE)
  20.     Local $_CI_hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
  21.     Local $_CI_Next = GUICtrlCreateButton("&Weiter -|>",310,410)
  22.     Local $_CI_Back = GUICtrlCreateButton("<|- &Zurück",20,410)
  23.     Local $_CI_OK = GUICtrlCreateButton("Icon wählen:",120,410)
  24.     GUICtrlSetState(-1,$GUI_DISABLE)
  25.     Local $_CI_Icon = GUICtrlCreateIcon("",0,190,404,32,32)
  26.  
  27.     For $iCntRow = 0 to 4
  28.         For $iCntCol = 0 to 5
  29.             $iCurIndex = $iCntRow * 6 + $iCntCol
  30.             $_CI_IconRadios[$iCurIndex] = GUICtrlCreateRadio("", 55 * $iCntCol + 25, 65 * $iCntRow + 75, 45, 45,$BS_ICON+$BS_PUSHLIKE)
  31.             $_CI_Labels[$iCurIndex] = GUICtrlCreateLabel("1", 55 * $iCntCol+12, 65 * $iCntRow + 120, 58, 20, $SS_CENTER)
  32.             GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT )
  33.         Next
  34.     Next
  35.  
  36.     _CI_NewFileLoad($_CI_FileName,$_CI_IconCount, $_CI_hFile)
  37.     _CI_Update($_CI_IconRadios, $_CI_Labels, $_CI_hStatus, $_CI_StartIndex, $_CI_IconCount, $_CI_FileName, $_CI_SelectedIconName)
  38.     GUISetState ()       ; will display an  dialog box with 1 checkbox
  39.     ; Run the GUI until the dialog is closed
  40.     While 1
  41.         $gMsg = GUIGetMsg()
  42.         Switch $gMsg
  43.             Case $_CI_IconRadios[0] To $_CI_IconRadios[29]
  44.                 For $i = 0 To 29
  45.                     If GUICtrlRead($_CI_IconRadios[$i]) = $GUI_CHECKED Then
  46.                         $_CI_SelectedIconName = 1*GUICtrlRead($_CI_Labels[$i])
  47.                         GUICtrlSetImage($_CI_Icon,$_CI_FileName,$_CI_SelectedIconName)
  48.                         GUICtrlSetState($_CI_OK,$GUI_ENABLE)
  49.                         ExitLoop
  50.                     EndIf
  51.                 Next
  52.  
  53.             Case $_CI_hFileSel
  54.                 $_CI_NewFile = _CI_NewFileLoad( _
  55.                                     FileOpenDialog("Select Icon file:", GUICtrlRead($_CI_hFile), "Icon-Files (*.exe;*.dll;*.ocx;*.icl;*.ico)") _
  56.                                     ,$_CI_IconCount, $_CI_hFile)
  57.                     If Not ($_CI_NewFile == -1) Then
  58.                         $_CI_FileName = $_CI_NewFile
  59.                         GUICtrlSetState($_CI_Back,$GUI_DISABLE)
  60.                         GUICtrlSetState($_CI_OK,$GUI_DISABLE)
  61.                         $_CI_StartIndex = 1
  62.                         $_CI_SelectedIconName = 0
  63.                         GUICtrlSetImage($_CI_Icon,"")
  64.                         _CI_Update($_CI_IconRadios, $_CI_Labels, $_CI_hStatus, $_CI_StartIndex, $_CI_IconCount, $_CI_FileName, $_CI_SelectedIconName)
  65.                     EndIf
  66.  
  67.             Case $_CI_Back
  68.                 If $_CI_StartIndex - 30 >= 0 Then $_CI_StartIndex -= 30
  69.                 If $_CI_StartIndex - 30 < 0 Then
  70.                     GUICtrlSetState($_CI_Back,$GUI_DISABLE)
  71.                 EndIf
  72.                 GUICtrlSetState($_CI_Next,$GUI_ENABLE)
  73.                 _CI_Update($_CI_IconRadios, $_CI_Labels, $_CI_hStatus, $_CI_StartIndex, $_CI_IconCount, $_CI_FileName, $_CI_SelectedIconName)
  74.  
  75.             Case $_CI_Next
  76.                 If $_CI_StartIndex + 30 <= $_CI_IconCount Then $_CI_StartIndex += 30
  77.                 If $_CI_StartIndex + 30 > $_CI_IconCount Then
  78.                         GUICtrlSetState($_CI_Next,$GUI_DISABLE)
  79.                 EndIf
  80.                 GUICtrlSetState($_CI_Back,$GUI_ENABLE)
  81.                 _CI_Update($_CI_IconRadios, $_CI_Labels, $_CI_hStatus, $_CI_StartIndex, $_CI_IconCount, $_CI_FileName, $_CI_SelectedIconName)
  82.  
  83.             Case $GUI_EVENT_CLOSE
  84.                 SetError(1)
  85.                 ExitLoop
  86.             Case $_CI_OK
  87.                 Local $arTemp[2] = [$_CI_FileName,$_CI_SelectedIconName]
  88.                 ExitLoop
  89.         EndSwitch
  90.     Wend
  91.  
  92.     GUIDelete($_CI_hGui)
  93.     Opt("GuiOnEventMode",$_CI_oldEventMode)
  94.     Return $arTemp
  95. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement