Alright, so you kinde use the buttons from right to left^^. My intuition wanted to use them from left to right, so first the Add button and then the rest. It works now how you said.
About the Icons. I made it ignore the ChooseIcon button when no rows were selected. Fixed it now. I also hid the 2nd and the 3rd column.
Let me know what you think.
Code: Select all
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
#SingleInstance,Force
#Include LV_EX.ahk
Gui, Add, Button, hidden x5 y5 gExecute, Execute
gui, Color, c000000 RGB ; Background of the GUI, not the ListView
Gui +AlwaysOnTop +resize
Gui, Font,S10, Verdana ; Font Size of Fields
Gui, Show, x100 y100 w500 h500
Gui, Add, ListView, xm r20 w700 Grid sort -ReadOnly +hscroll +BackgroundTrans Color cAqua vMyListView gListViewHandler, Name | FilePath | IcoPath
gui, Color,, 0xEAFAF1
Gui, Font,S10 bold cblack, Verdana
Gui, Add, Edit, x100 y5 w200 ys vProgram hwndOne
SetEditCueBanner(One, "Program Name")
Gui, Font,S10 bold cred, Verdana
Gui, Add, Edit, x100 y475 w600 xm vSearch gSearch hwndThree
SetEditCueBanner(Three, "Program Search")
Gui, Add, Button, x600 y5 gAddItem,% "Add"
Gui, Add, Button, x650 y5 gAddexe,% "File Location"
Gui, Add, Button, x757 y5 gAddicon,% "Choose Icon"
OnExit, UpdateFile
SelectedRow := 0
IconWidth := 50
IconHeight := 50
IconBitDepth := 24
InitialCount := 1 ; The starting Number of Icons available in ImageList
ImageListID := DllCall( "ImageList_Create", Int,IconWidth, Int,IconHeight
, Int,IconBitDepth, Int,InitialCount
, Int,GrowCount )
LV_SetImageList( ImageListID, 1 ) ; 0 for large icons, 1 for small icons
If FileExist("MovieList.txt") { ; Add data from MovieList.txt to ListView
;FileCopy, MovieList.txt, MovieList%A_Now%.txt ;incremental backup
Loop, Read, MovieList.txt
{
If (A_index = 1 && SubStr(A_LoopReadLine, 1, 1) = "x") {
WinPos := A_LoopReadLine
Continue
}
Else
{
Loop, Parse, A_LoopReadLine , CSV
RowData%A_Index% := A_LoopField
NewIcon := IL_Add(ImageListID, RowData3)
LV_Add("Icon" . NewIcon, RowData1,RowData2,RowData3)
}
}
}
SizeCols()
Menu, MyContextMenu, Add, Edit, EditItem
Menu, MyContextMenu, Add, Delete, DeleteItem
Menu, Tray, Add, Show MovieList, ShowMovieList
If FileExist("MovieList.txt") {
Gui, Show, %WinPos% , MovieList
}
Else
{
WinGetPos,X1,Y1,W1,H1,Program Manager
X2 := W1-800
Gui, Show, x%x2% y50 , MovieList
}
Hotkey, ^!a, ShowMovieList
Return
ShowMovieList:
Gui, Show,, MovieList
Return
MyListView:
If (A_GuiEvent = e) ;Finished editing first field of a row
LV_ModifyCol(2,"Sort")
If (A_GuiEvent = ColClick) ;Clicked column header
{
If A_EventInfo = 2 ;Number of column header clicked
LV_ModifyCol(2,"SortDesc")
}
UpdateFile()
Return
GuiContextMenu: ; Launched in response to a right-click or press of the Apps key.
If A_GuiControl <> MyListView ; Display the menu only for clicks inside the ListView.
Return
LV_GetText(ColText, A_EventInfo,1) ;Gather column data in string EditText
EditText := ColText
Loop 3
{
LV_GetText(ColText, A_EventInfo, A_Index+1)
EditText := EditText . "|" . ColText
}
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
Return
EditItem: ;Move row from ListView columns into edit fields
SelectedRow := LV_GetNext()
StringSplit, RowData, EditText , |
Loop, 9
{
GuiControl, , Rowdata%A_Index%
}
GuiControl, ,Button1, Update
Return
DeleteItem: ;Deletes selected rows
MsgBox, 4100, Delete Program?, Delete Program? Click Yes or No?
IfMsgBox No ;Don't delete
Return
RowNumber = 0 ; This causes the first iteration to start the search at the top.
Loop ; Since deleting a row reduces the RowNumber of all other rows beneath it,
{ ; subtract 1 so that the search includes the same row number that was previously
RowNumber := LV_GetNext(RowNumber - 1) ; found (in case adjacent rows are selected):
If not RowNumber ; The above returned zero, so there are no more selected rows.
Break
LV_Delete(RowNumber) ; Clear the row from the ListView.
}
UpdateFile()
Return
AddItem: ;Add new or update ListView row
Gui, Submit, NoHide
If !NewIcon {
NewIcon := IL_Add( ImageListID, Runexe ) ; Create a new entry in the imagelist for this program.
IconFile := Runexe
NewIconIndex := 0 ; The fist icon in the resource.
}
SelectedRow := LV_GetNext()
If (SelectedRow = 0) {
LV_Add("Icon" . NewIcon, Trim(Program),Trim(Runexe), Trim(IconFile))
} Else {
LV_Modify(SelectedRow,"Icon" . NewIcon, Program, IconFile)
LV_ModifyCol(1,"Sort")
SelectedRow := 0
GuiControl, ,Button1, Add to list
GuiControl,,edit, ;this would remove the text from Edit1 control
}
Return
UpdateFile: ;When exiting
DetectHiddenWindows On
UpdateFile()
ExitApp
Return
GuiSize: ; Widen or narrow the ListView in response to the user's resizing of the window.
If (A_EventInfo = 1) ; The window has been minimized. No action needed.
Return
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) ; Otherwise, the window has been resized or maximized. Resize the ListView to match.
Return
UpdateFile() { ;Saves data to file when ListView updated
FileDelete, MovieList.txt
WinGet, Min, MinMax, MovieList
If Min = -1
WinRestore, MovieList
WinGetPos, X, Y, Width, Height, MovieList
Width -= 16
Height -= 38
FileAppend, x%x% y%y% w%Width% h%Height% `n, MovieList.txt
Loop % LV_GetCount()
{
RowNum := A_Index
Loop, 2
{
LV_GetText(Text, RowNum, A_Index)
TrimText := Trim(Text)
FileAppend, "%TrimText%"`,, MovieList.txt
}
LV_GetText(Text, RowNum, 3)
TrimText := Trim(Text)
FileAppend, "%TrimText%"`n, MovieList.txt
}
}
SizeCols() { ;resize all columns, hide Column 9, Column 10 NoSort
Loop, % LV_GetCount("Column")
{
LV_ModifyCol(A_Index,"AutoHdr")
}
LV_ModifyCol(1, 300)
LV_ModifyCol(2, 0)
LV_ModifyCol(3,0) ; This was "AutoHdr" but you wanted col3 to be hidden.
LV_ModifyCol(3,"NoSort")
}
#IfWinActive, MovieList ; CTRL+A to Select All
^a::LV_Modify(0,"Select")
#IfWinActive
Addexe:
Gui, Submit, NoHide
FileSelectFile, exePath, 3,, Select Program, (*.exe ) ; displays a standard dialog that allows the user to choose a picture
Runexe := exePath
;GuiControl,, Program,% exePath
Return
Addicon:
;FileSelectFile, file, 32,, Pick a file to check icons., *.ico
IconFile := FileSelectIcon(NewIconIndex, "Pick an icon.")
; The imagelist already exists and linked to the listview.
;ImageListID := IL_Create(10,10,1) ; Create an ImageList to hold 10 small icons.
;LV_SetImageList(ImageListID,1) ; Assign the above ImageList to the current ListView.
NewIcon := IL_Add(ImageListID, IconFile, 0)
SelectedRow := LV_GetNext()
If (SelectedRow = 0)
Return
LV_Modify(SelectedRow, "Icon" . NewIcon . " Col3", IconFile)
LV_ModifyCol("Hdr") ; Auto-adjust the column widths.
Return
OpenFile:
MsgBox OpenFile: This lable seem to not take part in the script and is thus not updated with the changes DyaTactic made.
LV_Delete()
FileSelectFile, file, 32,, Pick a file to check icons., *.*
ImageListID := IL_Create(1,1) ; Create an ImageList to hold 10 small icons.
LV_SetImageList(ImageListID,1) ; Assign the above ImageList to the current ListView.
Loop ; Load the ImageList with a series of icons from the DLL.
{
Count := Image ; Number of icons found
Image := IL_Add(ImageListID, file, A_Index) ; Omits the DLL's path so that it works on Windows 9x too.
If (Image = 0) ; When we run out of icons
Break
}
Loop, %Count% ; Add rows to the ListView (for demonstration purposes, one for each icon).
LV_Add("Icon" . A_Index, " " . A_Index)
LV_ModifyCol("Hdr") ; Auto-adjust the column widths.
Return
IconNum:
Clipboard := file . ", " . A_EventInfo
Msgbox %Clipboard% `r added to Clipboard! `r %A_ScriptDir%
; Run c:AutoHotkey/iconsext.exe /save %file% %A_ScriptDir%/icons -icons,, Hide
Return
Search:
ListViewHandler:
if A_GuiEvent = DoubleClick
{
LV_GetText(FileName, A_EventInfo, 2) ; Get the text of the first field.
Execute(Filename)
}
return
Execute:
Row := LV_GetNext()
If (Row) {
LV_GetText(FileName, Row, 2)
Execute(Filename)
}
Return
Execute(Filename) {
Run %FileName%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileName%".
}
SetEditCueBanner(HWND, Cue) {
Static EM_SETCUEBANNER := (0x1500 + 1)
Return DllCall("User32.dll\SendMessageW", "Ptr", HWND, "Uint", EM_SETCUEBANNER, "Ptr", True, "WStr", Cue)
}
GuiEventEmpty() {
GuiControlGet, ConText,, EditCon, Text
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
WinGetClass, ConClass, % "ahk_id" OutputVarControl
If ( ConText = "" ) {
GuiControl,, EditCon, PlaceHolder
GuiControl, Disable, EditCon
OnMessage( 0x111, "" )
}
}
GuiEventLeave() {
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
WinGetClass, ConClass, % "ahk_id" OutputVarControl
If ( ConClass = "Edit" ) {
GuiControl,, EditCon
GuiControl, Enable, EditCon
Sleep, 1000
OnMessage( 0x111, "GuiEventEmpty" )
}
}
FileSelectIcon(ByRef IconIndexOut:=0, Prompt:="Choose an file with icons") {
FileSelectFile, sIconPath, 1, , %Prompt%, Icons (*.ico; *.icl; *.exe; *.dll)
If !sIconPath
Return ""
nIndex := 0
GoTo SkipIconIndex ; This simplifyes the system, only allowing the first icon of a file to be selected.
VarSetCapacity(wIconPath, 260 * 2)
DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "str", sIconPath, "int", -1, "str", wIconPath, "int", 260)
DllCall("shell32\PickIconDlg", "Uint", hWnd, "str", sIconPath, "Uint", 260, "intP", nIndex)
RegExMatch(sIconPath, "U)%\K[^\\]+(?=%)", SysVar) ; Find 'SystemRoot' in '%SystemRoot%\system32'.
; Expand system variables if one is used.
If SysVar {
EnvGet ExpSysVar, %SysVar%
sIconPath := StrReplace(sIconPath, "%" SysVar "%", ExpSysVar)
}
;VarSetCapacity(sIconPath, 260)
;DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wIconPath, "int", -1, "str", sIconPath, "int", 260, "Uint", 0, "Uint", 0)
SkipIconIndex:
IconIndexOut := nIndex
Return sIconPath
}