LV_Modify show end of string

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
julesverne
Posts: 42
Joined: 18 Apr 2017, 14:39
Contact:

LV_Modify show end of string

Post by julesverne » 31 May 2020, 01:00

Hi all, I'm not seeing in the docs that this is possible so asking to the world.

The question is simply in a ListView can you show the end of a long string rather than the beginning?

Example in my case is a long file path.

C:\somefolder\somefolder\somefolder\somefile.ext

If I set my columns to show only a specified width and the path is longer than that, I'd rather see for example:

mefolder\somefolder\somefile.ext

as opposed to what I currently see:

C:\somefolder\somefolder\somefol

the options LV_Modify(1, "Right") doesn't achieve this.

Thanks in advance!
Jules
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: LV_Modify show end of string

Post by BNOLI » 31 May 2020, 01:57

Code: Select all

; Get ListView column width with SendMessage (by Shimanov)
; 
; https://docs.microsoft.com/en-us/windows/win32/controls/lvm-getcolumnwidth
; https://autohotkey.com/board/topic/6073-get-listview-column-width-with-sendmessage/

Gui, Add, ListView,, column 1|c2
	LV_Add( "", "85385-485-384jdsf", "12" )
	LV_ModifyCol()
Gui, Show

Process, Exist
WinGet, hw_gui, ID, ahk_class AutoHotkeyGUI ahk_pid %ErrorLevel%

SendMessage, 0x1000+29, 0, 0, SysListView321, ahk_id %hw_gui%
width_c0 := ErrorLevel

SendMessage, 0x1000+29, 1, 0, SysListView321, ahk_id %hw_gui%
width_c1 := ErrorLevel

MsgBox, %
	( Join
		"column 1 width = " width_c0
		"`nc2 width = " width_c1
	)
return

GuiClose:
ExitApp
Not tested. Probably useful if someone wants to do any text length vs cell-width math + SubStr() to display only the last part of the string ...
It'll not provide the functionality you've requested. JFTR :shifty:
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
julesverne
Posts: 42
Joined: 18 Apr 2017, 14:39
Contact:

Re: LV_Modify show end of string

Post by julesverne » 31 May 2020, 16:59

Thank you. I appreciate the code snippet. I'm sure it'll come handy in the future. Unfortunately, yeah, won't really do what I was looking for. Been thinking of some hacky way of doing it where I sendkeys to move the cursor to the end, but that won't work for every row at the same time. Doing a substring to show only the ending would mean if user wanted to see the beginning of the string, they wouldn't be able to.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: LV_Modify show end of string

Post by BNOLI » 31 May 2020, 17:21

Doing a substring to show only the ending would mean if user wanted to see the beginning of the string, they wouldn't be able to.
Yep, but you could display the full path, if the users mouse hovers over that fixed-length cell, either using a tooltip or at the status bar of the GUI.
Good luck :)
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

Re: LV_Modify show end of string

Post by Albireo » 31 May 2020, 17:28

Is it the file name displayed with a path in ListView or is it some other long text?
If it is filename, I would split the filename into two parts with SplitPath and show the path in one column and the filename in the next.
For example .:

Code: Select all

#EnvAdd
#SingleInstance force

FileName := "C:\somefolder\somefolder\somefolder\somefile.ext"
SplitPath FileName, fName, fPath
Gui, Add, ListView, x20 y20 r5 w310 grid, FilePath|FileName
	LV_Add( "", fPath, fName )
	LV_ModifyCol(1, 200)
	LV_ModifyCol(2, 100)
Gui, Show, x100 y100 w350 h200, Filenames
Post Reply

Return to “Ask for Help (v1)”