Url to Button

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Url to Button

07 Sep 2020, 04:03

Okay... I've decided to redo my program.... What I need to know is how when you pick a file through an add button, instead of it putting the url to the file, that it puts a button in the listview instead, that links to the file you created? Just need direction on how to do this, whether an individual helping, or links to help me learn how. Thank you and blessings.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Url to Button

07 Sep 2020, 04:38

So you want the newly selected file to become a new row in the ListView and when you click the row/item in the ListView the file/URL is opened? This code should get you far I guess. Let me know what you need more.

Code: Select all

EnvGet, UserProfile, USERPROFILE

Gui Add, ListView, gLVEvents, Name|URL
LV_Add(, "UserProfile", UserProfile)    ; Add one row to the ListView.
LV_ModifyCol()    ; Auto size columns.
Gui Show
Return

LVEvents:
if (A_GuiEvent = "DoubleClick") {
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	LV_GetText(FilePath, A_EventInfo, 2)
    MsgBox You double-clicked '%RowText%'. (%FilePath%)
	Run % FilePath
}
return
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

07 Sep 2020, 04:48

@DyaTactic

Thank you much.


Yeah I have the listview already adding the url and name... what I don't get it how to turn the URL it puts int he row and make it a button that keeps the url path connected with the button, so when hit, it opens the url.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Url to Button

07 Sep 2020, 05:12

You can change the listview to another view which hides the file path. Though adding actual buttons like the ones from "Gui, Add, Button" is not a thing with de default functions of Autohotkey. You can even add the AltSubmit option to detect normal clicks. That way it can run the URL with a single click but it sill won't look like a button.

Code: Select all

EnvGet, UserProfile, USERPROFILE

Gui Add, ListView, gLVEvents +IconSmall, Name|URL    ; +IconSmall instead of the defauld ReportView.
LV_Add(, "UserProfile", UserProfile)    ; Add one row to the ListView.
LV_ModifyCol()    ; Auto size columns.
Gui Show
Return

LVEvents:
if (A_GuiEvent = "DoubleClick") {
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	LV_GetText(FilePath, A_EventInfo, 2)
    MsgBox You double-clicked '%RowText%'. (%FilePath%)
	Run % FilePath
}
return
Another option is to forget the listview and just create a lot of buttons. Though it is quite challanging to maintain such a list of controls. I made a class to make lists of controls. I am afraid te documentation very unstructured but with an example you might get it working.

Let me know what you think.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

07 Sep 2020, 05:21

DyaTactic wrote:
07 Sep 2020, 05:12
You can change the listview to another view which hides the file path. Though adding actual buttons like the ones from "Gui, Add, Button" is not a thing with de default functions of Autohotkey. You can even add the AltSubmit option to detect normal clicks. That way it can run the URL with a single click but it sill won't look like a button.

Code: Select all

EnvGet, UserProfile, USERPROFILE

Gui Add, ListView, gLVEvents +IconSmall, Name|URL    ; +IconSmall instead of the defauld ReportView.
LV_Add(, "UserProfile", UserProfile)    ; Add one row to the ListView.
LV_ModifyCol()    ; Auto size columns.
Gui Show
Return

LVEvents:
if (A_GuiEvent = "DoubleClick") {
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	LV_GetText(FilePath, A_EventInfo, 2)
    MsgBox You double-clicked '%RowText%'. (%FilePath%)
	Run % FilePath
}
return
Another option is to forget the listview and just create a lot of buttons. Though it is quite challanging to maintain such a list of controls. I made a class to make lists of controls. I am afraid te documentation very unstructured but with an example you might get it working.

Let me know what you think.
Okay, what about icons? If I can't add buttons, then maybe icons would work? Thank you again. I would just rather not have the URL showing when I click add, so maybe lhrow an icon there instead?
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Url to Button

07 Sep 2020, 05:36

This is with icons added from shell32.dll. Just like the example in the documentation for IL_Create.

Code: Select all

EnvGet, UserProfile, USERPROFILE

Gui Add, ListView, w250 gLVEvents +Icon, Name|URL
ImageListID := IL_Create(10,, 1)  ; Create an ImageList to hold 10 large icons.
LV_SetImageList(ImageListID)  ; Assign the above ImageList to the current ListView.
Loop 10  ; Load the ImageList with a series of icons from the DLL.
    IL_Add(ImageListID, "shell32.dll", A_Index) 

LV_Add("Icon4", "UserProfile", UserProfile)

Loop 10  ; Add rows to the ListView (for demonstration purposes, one for each icon).
    LV_Add("Icon" . A_Index, A_Index, "n/a")

Gui Show
Return

LVEvents:
if (A_GuiEvent = "DoubleClick") {
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
	LV_GetText(FilePath, A_EventInfo, 2)
    MsgBox You double-clicked '%RowText%'. (%FilePath%)
	Run % FilePath
}
return
garry
Posts: 3787
Joined: 22 Dec 2013, 12:50

Re: Url to Button

07 Sep 2020, 06:43

you can hide the 2nd column ( url ) , click on column-1

Code: Select all

;- Url to Button 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=80725

Gui Add, ListView, vLV1 gLVEvents +altsubmit w130, Name|URL
LV_Add("","Autohotkey","https://www.autohotkey.com/boards")
  LV_ModifyCol(1,100)
  LV_ModifyCol(2,0)
Gui, Show, w130,TEST
Return
;----------
Guiclose:
Exitapp
;----------
LVEvents:
Gui,1:Listview,LV1
if (A_GuiEvent = "Normal") {
	LV_GetText(FilePath, A_EventInfo, 2)
	Run % FilePath
}
return
;=========================================
OR , see ICON + NAME and start PROGRAM / URL

Code: Select all

#warn
#noenv
Setworkingdir,%a_scriptdir%
Gui,2:default
Gui,2: -DPIScale
Gui,2: Font,s14 CBlack,Lucida Console
e4x=
(Ltrim Join`r`n
VOLUME;Sndvol.exe;sndvol
CHARMAP;Charmap.exe;charmap
Notepad;Notepad.exe;notepad
mozilla;%a_programfiles%\Mozilla Firefox\Firefox.exe;%a_programfiles%\Mozilla Firefox\Firefox.exe
Autohotkey;%a_programfiles%\AutoHotkey\AutoHotkey.exe;https://www.autohotkey.com/boards/
)
Gui,2:Add, ListView, backgroundGray grid x10 y5  h460 w430 +hscroll altsubmit vMLV1A gMLV1B      , Icon|Icon_path|Program
LV_ModifyCol(1,400)
LV_ModifyCol(2,0)
LV_ModifyCol(3,0)
;ILStatus := IL_Create(1,1,0)                ;small
ILStatus := IL_Create(1,1,1)                ;bigger
LV_SetImageList(ILStatus, 1)
gosub,lb
gui,2:show, x100 y10 h480 w430,TEST
return
;-----------
2Guiclose:
exitapp
;-----------
lb:
Gui,2:Submit,nohide
Gui,2:ListView,mlv1a
LV_Delete()
GuiControl,2: -Redraw,MLV1a
loop,parse,e4x,`n,`r
  {
  x:=a_loopfield
  c1=
  c2=
  c3=
  IconNumber := IL_Add(ILSTATUS, "%pictxx05%" )      ;- clear with picture which not exist
  stringsplit,C,x,`;,
  SplitPath,c2, name, dir, ext, name_no_ext, drive
  IconNumber := IL_Add(ILSTATUS, C2 )
  LV_Add("icon" . IconNumber ,C1,name_no_ext,C3)
  }
GuiControl,2: +Redraw,MLV1a
LV_ModifyCol(1,"right")     ;- move text to right
return
;-----------------------------------------------------------------
mlv1b:
Gui,2:submit,nohide
Gui,2:ListView, mlv1a
If A_GuiEvent = Normal
 {
 LV_GetText(C3,A_EventInfo,3)
 try
 run,%c3%
 }
return
;=================================================================
Image
Last edited by garry on 08 Sep 2020, 08:07, edited 1 time in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Url to Button

07 Sep 2020, 11:34

His/her (probably outdated?) target was a) to show an image of the listed media file that currently has the focus within the listview (I've recommended creating an image-panel with the height of the listview to the right of it), and b) start the respective media file with VLC, if whatever event will get triggered (click on the image, its listview row, ...).
Unfortunately, a quite common "double-click" on a listview row/item has executed its assigned media file twice OR (AFAICS) has tried to execute non-media-related content OR were not updating the 'path-var' - so VLC went nuts. Correct me if I'm wrong. :think:
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

07 Sep 2020, 12:58

BoBo wrote:
07 Sep 2020, 11:34
His/her (probably outdated?) target was a) to show an image of the listed media file that currently has the focus within the listview (I've recommended creating an image-panel with the height of the listview to the right of it), and b) start the respective media file with VLC, if whatever event will get triggered (click on the image, its listview row, ...).
Unfortunately, a quite common "double-click" on a listview row/item has executed its assigned media file twice OR (AFAICS) has tried to execute non-media-related content OR were not updating the 'path-var' - so VLC went nuts. Correct me if I'm wrong. :think:
Hey @BoBo , I actually started a different file, and thank you tremendously for the help you have given me. I have the media file playable and working when I click on them... So I can add the video and VLC will play them accordingly to their row numbers. What I see is lots of examples of icons being used in listview, but they are actually implanted within the file instead of actually picking the icon you want to use and then insert it into the listview. I think that is where my problem is. I can get the filepath url to show in the listview, but can't transform the url into an image.

Then the issue of this LONG url showing for the path to the file... and hiding that column so that it's not seen. The image below is what I have so far, and if I double click, it opens photoshop. I can add anything in there and it will run it: exe's, mp3's, mp4, or images. So I did figure out how to play VLC's finally, with much help from you. Just need that long path invisible lol

P.S. a "He" :) :superhappy:
Attachments
capture14.jpg
capture14.jpg (19.03 KiB) Viewed 1904 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Url to Button

07 Sep 2020, 13:35

Instead of loading an icon from a DLL, simply set the path to an image that will be loaded instead (shrinked to the scale of an icon).

:arrow: IL_Add

PS. your GUI looks much better now :thumbup:
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

07 Sep 2020, 13:47

BoBo wrote:
07 Sep 2020, 13:35
Instead of loading an icon from a DLL, simply set the path to an image that will be loaded instead (shrinked to the scale of an icon).

:arrow: IL_Add

PS. your GUI looks much better now :thumbup:
I've been trying to, but I have this so far. I can get it to post the icon for all rows, but when I try to put into the loop, it won't do it individually.

Code: Select all

AddItem:                 ;Add new or update ListView row
Gui, Submit, NoHide
ImageListID := IL_Create(10,10,1)
IL_Add(ImageListID, Geticon, 1)
LV_SetImageList(ImageListID, 1)

If (SelectedRow = 0)
	
LV_Add("", Trim(Program),Trim(Runexe),Trim(icoPath))
Else {
LV_Modify(SelectedRow,"", Program, Runexe, icoPath)
	LV_ModifyCol(1,"Sort")
	SelectedRow := 0
	GuiControl, ,Button1, Add to list
	GuiControl,,edit, ;this would remove the text from Edit1 control
}
Attachments
capture15.jpg
capture15.jpg (20.93 KiB) Viewed 1897 times
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

07 Sep 2020, 18:37

Okay, well in order to not open another thread based on the same thing I'm working on, I'll just post in here.

1. Can't figure out how to hide the long path the submit puts into the listview url, or make it a button that links the the urlpath
2. Can't figure out icons yet... Gotta find a way to add in a loop so each get their own icon...

So far that's where I"m at now. I'll be googling and searching... Thank you.

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 | File | Icon

Gui, Font,S10 cblack, Verdana 
Gui, Add, Edit, x100 y5 w200 ys vProgram hwndOne
SetEditCueBanner(One, "Program Name")

Gui, Font,S10 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    :=  2
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 )
											; 0 for large icons, 1 for small icons


LV_SetImageList( ImageListID, 1 )

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
			LV_Add("", 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 (SelectedRow = 0)
	
LV_Add("", Trim(Program),Trim(Runexe),Trim(icoPath))
Else {

	LV_Modify(SelectedRow,"", Program, Runexe, icoPath)
	LV_ModifyCol(1,"Sort")
	SelectedRow := 0
	GuiControl, ,Button1, Add to list
	GuiControl,,edit, ;this would remove the text from Edit1 control
}

SizeCols()
UpdateFile()
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, 9
       {
          LV_ModifyCol(A_Index,"AutoHdr")
       }
       LV_ModifyCol(9, 0)
       LV_ModifyCol(10,"AutoHdr")
       LV_ModifyCol(10,"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,, Runexe,% exePath
Return


Addicon:
Gui, Submit, NoHide		
FileSelectFile, icoPath, 3,, Select Icon, (*.ico )		; displays a standard dialog that allows the user to choose a picture
Geticon := icoPath
GuiControl,, Geticon,% icoPath
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" )	
	}
}
Attachments
capture17.jpg
capture17.jpg (42.21 KiB) Viewed 1857 times
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

08 Sep 2020, 00:52

Okay, I have the icon being added, but the same one over and over.. also a little "1" is there that's annoying. Here is the code.

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    :=  2
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 )
											; 0 for large icons, 1 for small icons


LV_SetImageList( ImageListID, 1 )


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
			LV_Add("", 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 (SelectedRow = 0)
	
LV_Add("", Trim(Program),Trim(Runexe),Trim(icoPath))

Else {
	
	LV_Modify(SelectedRow,"", Program, Runexe, icoPath)
	
	LV_ModifyCol(1,"Sort")
	SelectedRow := 0
	
	GuiControl, ,Button1, Add to list
	GuiControl,,edit, ;this would remove the text from Edit1 control
	
}

SizeCols()
UpdateFile()
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, 9
       {
          LV_ModifyCol(A_Index,"AutoHdr")
       }
       LV_ModifyCol(9, 0)
       LV_ModifyCol(10,"AutoHdr")
       LV_ModifyCol(10,"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,, Runexe,% exePath
Return


Addicon:
FileSelectFile, file, 32,, Pick a file to check icons., *.*
if file =
	return


 

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.
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

OpenFile:
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" )	
	}
}
Attachments
capture18.jpg
capture18.jpg (57.15 KiB) Viewed 1637 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Url to Button

08 Sep 2020, 01:19

Code: Select all

Addicon:
FileSelectFile, file, 32,, Pick a file to check icons., *.*												; >> creating variable 'file'										
if file = 							
	return

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.
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)  										; >> static 'file' var\path content, means the same icon/image for all rows
	
     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

OpenFile:
LV_Delete()
FileSelectFile, file, 32,, Pick a file to check icons., *.*									; >> using the same variable name 'file' again, why??
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)											; >> variable 'file' (that contains the path to the icon/image) stays static therefore you'll get the same icon again and again
	
     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							; >> c:AutoHotkey/...    vs    c:\Autohotkey\...
Return
Guessing. See ;>> comments. Untested.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

08 Sep 2020, 02:56

@BoBo

Thank you much for that.... It does the same thing as my previous image, so back at square one. I've been on this all day.. driving me mad. :headwall: :headwall:

There's a... uh... conflict between my adding to the rowdata and the images... I need to somehow mix them together I think. Brain dead at the moment, so no idea yet. I tried to loop the images and I ended up with like 100 rows in a few seconds LOL; gotta learn how to do this or me go mad. But I don't give up on things, so I'll keep on the high road until it's workable. Thanks again.

Here is the add items that I think conflict with the icons.

Code: Select all

AddItem:                 ;Add new or update ListView row
Gui, Submit, NoHide

If (SelectedRow = 0)
	
LV_Add("", ("Icon" . A_Index, "     " . A_Index), Trim(Program),Trim(Runexe))

Else {
	
	LV_Modify(SelectedRow,"",("Icon" . A_Index, "     " . A_Index), Program, Runexe)
	
	LV_ModifyCol(1,"Sort")
	SelectedRow := 0
	
	GuiControl, ,Button1, Add to list
	GuiControl,,edit, ;this would remove the text from Edit1 control
	
}
Then here is my new code, removing the first select icon.

Code: Select all

Addicon:

FileSelectFile, file, 32,, Pick a file to check icons., *.ico

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.
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
Any suggestions are appreciated. Okay, back to the drawing board :superhappy: :superhappy: :superhappy: I know the A_Index is why it's throwing Icon0 there b/c it's not in a loop. But it I change it much, then it stops adding to the saved file.
Attachments
capture19.jpg
capture19.jpg (48.45 KiB) Viewed 1536 times
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

08 Sep 2020, 06:20

Ugggg... Been looking for a good example of image arrays that are not already pre-embedded into the file itself. Anyone have any, would be awesome :)
just me
Posts: 9530
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Url to Button

08 Sep 2020, 08:51

Not sure what you want exactly, but this will add an icon only for files from which an icon could be extracted.

Code: Select all

#NoEnv
SetBatchLines, -1
Gui, Add, ListView, w600 h600, Icon|Name|Path
HIL := IL_Create(10, 5, 1) ; large icon image list
LV_SetImageList(HIL, 1)    ; used as a small icon image list for the report style

Loop, Files, D:\AutoHotkey\AHK_L\*.*, F ; <<<<<<<<<< must be adjusted
{
   If (ICO := IL_Add(HIL, A_LoopFileFullPath))
      LV_Add("Icon" . ICO, "", A_LoopFileName, A_LoopFileFullPath)
   Else
      LV_Add("Icon99999", "", A_LoopFileName, A_LoopFileFullPath)

}
Until (A_Index = 10)

LV_ModifyCol()
Gui, Show, , Icons
Return

GuiClose:
ExitApp
If you want to show one default icon for all other files, add it as the first icon and change the Else branch to

Code: Select all

   Else
      LV_Add("", "", A_LoopFileName, A_LoopFileFullPath)
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Url to Button

08 Sep 2020, 14:06

I took the whole code and ajusted a few things. Most of itwas the icon system as -just me- did, I implemented my own solotion however so if you like the code of -just me- more go ahead and change it.
This code does take an icon from the file automatically and allows to pick an icon from an icon resource, including .dll's, with the 'Choose icon' button.
I am sure it needs some more tuning but first things first: Does it work on your side and is it an improvement? It does work on my side and I think it is an improvement but as -just me- said, I am also not 100% sure what you want so let me know how this version works.

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
	
	NewIcon := IL_Add( ImageListID, Runexe )	; Create a new entry in the imagelist for this program.
	
	SelectedRow := LV_GetNext()
	If (SelectedRow = 0) {
		
		LV_Add("Icon" . NewIcon, NewIcon . "     " .  Trim(Program),Trim(Runexe), Trim(Runexe))

	} Else {
		
		LV_Modify(SelectedRow,"Icon" . NewIcon, NewIcon . "     " .  Program, Runexe)
		
		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, 9
       {
		  LV_ModifyCol(A_Index,"AutoHdr")
       }
       LV_ModifyCol(1, 150)	; As far as I can see you use only three columns: Name, FilePath and IcoPath.
       LV_ModifyCol(9, 0)	; As far as I can see you use only three columns: Name, FilePath and IcoPath.
       LV_ModifyCol(10,"AutoHdr")
       LV_ModifyCol(10,"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:
	SelectedRow := LV_GetNext()
	
	If (SelectedRow = 0)
		Return
	
	;FileSelectFile, file, 32,, Pick a file to check icons., *.ico
	IconFile := FileSelectIcon(NewIconIndex, "Pick a file to check icons.")
	
	; 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, NewIconIndex)
	
	LV_Modify(SelectedRow, "Icon" . NewIcon . " Col3", IconFile)
	LV_ModifyCol("Hdr")  ; Auto-adjust the column widths.
Return

OpenFile:
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 a file with icons") {
	FileSelectFile, sIconPath, 1, %A_WinDir%\System32, %Prompt%, Icons (*.ico; *.icl; *.exe; *.dll)
	If !sIconPath
		Return ""
	
	nIndex := 0
	
	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)
	}

	IconIndexOut := nIndex
	Return sIconPath
}
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Url to Button

09 Sep 2020, 04:38

@DyaTactic and @just me

Thank you both for examples. I do appreciate them. As clarification, I have an add button. I choose a program that I want to add to the listview, then I choose the icon for that program, then I click the add button to show the icon and the program in the listview. Since I have programs that I use all over different directories on my computer and even back up drives, I want to be able to add then individually, and not have them in a directory like all the examples are that I've found. I could use those programs for a movie list or something that will all be in one directory, but it won't work for me with files all over the place. As you see in the previous images, I have the program being add properly, although I don't want the path showing to the program, but that is a later task. I also have it showing an icon. WHen I add the icon, however, it shows the same icon no matter what program I add. I am guessing I need some type of array that will loops a variable that holds the path to the program. Still trying to figure out how I can do it.

Thanks again to you both!
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Url to Button

09 Sep 2020, 05:31

I choose a program that I want to add to the listview, then I choose the icon for that program, then I click the add button to show the icon and the program in the listview.
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
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton, Google [Bot] and 192 guests