I used the code "ListView_2.ahk" from helpfile to create a listview with doubleclick and context-menu. The list works, doubleclick too, and right-click shows the context-menu and invokes the sub-routine. The only problem is
LV_GetNext(0, "F") returns always 0
Before I upload the code (where I broke something, because the example code is OK) I want to ask in a "common style":
Is there a common mistake that users make and which is overseen by me?
Any common hints relating this function?
Thanks
LV_GetNext(0, "F") returns always 0
LV_GetNext(0, "F") returns always 0
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
Did you change the GUI name/number or did you add another ListView?
Re: LV_GetNext(0, "F") returns always 0
I have only one GUI with one List, but
a) there is a loop which refreshes it sometimes (but the problem is before the refresh)
b) I gave the GUI a name
Something is broken between DoubleClick-Event and Context-menu.
Doubleclick works fine, based on the g-label. I can also store the Rownumber with it; I added "AltSubmit" to the GUI and can display all events, but if I use via context I get nothing.
So it seems that it had lost the connection to the Listview ???
a) there is a loop which refreshes it sometimes (but the problem is before the refresh)
b) I gave the GUI a name
Code: Select all
Gui, new,+HwndBundleList,Bundle Switcher
Gui, Add, ListView, r20 w580 vMyListView gMyListView Grid, Icon|Name|Status|Description|Path|Picture
Doubleclick works fine, based on the g-label. I can also store the Rownumber with it; I added "AltSubmit" to the GUI and can display all events, but if I use
Code: Select all
LV_GetText(name, FocusedRowNumber, 5)
So it seems that it had lost the connection to the Listview ???
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
So, here is the core of the code. It creates a listview, fills it with two lines and does something with double-click. With the context-menu (right-click) I want to extract the value of the clicked line - but I get nothing. Certainly I missed as usual a dot or a comma or something else ...
Code: Select all
#SingleInstance,Force
#NoEnv
; #NoTrayIcon
Gosub, ShowStartDialog
return
;; **********************************************************
;; **********************************************************
ShowStartDialog:
SS_REALSIZECONTROL := 0x40 ; erzwingt Grössenanpassung des Bildes in die Control
Gui, new,+HwndBundleList,Bundle Switcher
Gui -Resize -MaximizeBox Border ; ToolWindow
; Create the ListView and its columns:
Gui, Add, ListView, r20 w580 vMyListView gMyListView Grid , Icon|Name|Status|Description|Path|Picture
Gui, Add, Button, x+15 w70 Default , Quit ; xm puts it at the bottom left corner.
; Bundles durchsuchen, Liste aufbauen
; zaehler := 0
Gosub, ListBundle
; Create a popup menu to be used as the context menu:
Menu, MyContextMenu, Add, Go to folder, ContextGoToFolder
Menu, MyContextMenu, Add, Display Icon, ContextDisplayIcon
Gui , Show
OnMessage(0x200, "WM_MOUSEMOVE")
return
;;; **********************************************************
ListBundle:
Gosub, pruefung
; baue die Liste auf
if listeninhalt
{
Loop, Parse, listeninhalt, | ; zerhacke die Liste jeweils am Trennstrich
{ ;
StringSplit, zeileninhalt, A_LoopField,`t ; zerhacke den String an den Tabulatoren
LV_Add("Icon" . A_Index,,zeileninhalt1,zeileninhalt2,zeileninhalt3,zeileninhalt4,zeileninhalt5)
}
LV_ModifyCol(1, 30) ; icon
LV_ModifyCol(2, "Auto") ; Auto-size
LV_ModifyCol(3, 40) ; Status
LV_ModifyCol(3, "Text Center") ; Status
LV_ModifyCol(4, 350) ; Description
LV_ModifyCol(5, "Auto") ; Auto-size
LV_ModifyCol(6, 30) ; Iconpath
;LV_ModifyCol(3, "Text") ; For sorting, indicate that the Size column is an integer.
}
return
;;; **********************************************************
pruefung:
listeninhalt = name-a`tstatus-a`tbeschreibung-a`tc:\temp`ticon-a
listeninhalt = %listeninhalt%|name-b`tstatus`t-bbeschreibung`tC:\windows`ticon-b
return
;;; **********************************************************
MyListView:
fullpath :=
name :=
msgbox I am the doubelclick
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
; Show the menu at the provided coordinates, A_GuiX and A_GuiY. These should be used
; because they provide correct coordinates even if the user pressed the Apps key:
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
;;; **********************************************************
; zwei Routinen gemeinsam starten und dann erst aufteilen
ContextDisplayIcon: ; The user selected "DisplayIcon" in the context menu.
ContextGoToFolder: ; The user selected "GoToFolder" in the context menu.
; For simplicitly, operate upon only the focused row rather than all selected rows:
; FocusedRowNumber := LV_GetNext(0, "F") ; Find the focused row.
; MsgBox %FocusedRowNumber%
; if not FocusedRowNumber ; No row is focused.
; return
MsgBox %A_ThisMenuItem%
IfInString, A_ThisMenuItem, Display Icon ; User selected "DisplayIcon" from the context menu.
{
MsgBox a %FocusedRowNumber%
LV_GetText(name, A_EventInfo, 6)
Run %name%,, UseErrorLevel
}
else ; User selected "GoToFolder" from the context menu.
{
MsgBox b %FocusedRowNumber%
LV_GetText(name, A_EventInfo, 5)
Run %name%,, UseErrorLevel
}
msgbox %xname%
if ErrorLevel
MsgBox Could not perform requested action on %name%.
return
;; **********************************************************
ButtonQuit:
ExitApp
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
Code: Select all
Gui, new,+HwndBundleList,Bundle Switcher
Menu labels are non-GUI threads using 1 as their default. That's why you have to set the default GUI at least:The default window name for a GUI thread is that of the window that launched the thread. Non-GUI threads use 1 as their default.
Source: GUI Events, Threads, and Subroutines
Code: Select all
Gui, %BundleList%:Default
Re: LV_GetNext(0, "F") returns always 0
just me
thanks. I tried now to
a) add Gui, %BundleList%:Default in different placers and
b) removed the name of the GUI
but nothing changed. Is it possible that you modify my code above that it is working (or tell me exactly where I have to change what?).
Thanks in advance
thanks. I tried now to
a) add Gui, %BundleList%:Default in different placers and
b) removed the name of the GUI
but nothing changed. Is it possible that you modify my code above that it is working (or tell me exactly where I have to change what?).
Thanks in advance
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
It must be done within the menu labels:
Code: Select all
;;; **********************************************************
; zwei Routinen gemeinsam starten und dann erst aufteilen
ContextDisplayIcon: ; The user selected "DisplayIcon" in the context menu.
ContextGoToFolder: ; The user selected "GoToFolder" in the context menu.
; For simplicitly, operate upon only the focused row rather than all selected rows:
Gui, %BundleList%:Default ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
FocusedRowNumber := LV_GetNext(0, "F") ; Find the focused row.
MsgBox %FocusedRowNumber%
if not FocusedRowNumber ; No row is focused.
return
MsgBox %A_ThisMenuItem%
IfInString, A_ThisMenuItem, Display Icon ; User selected "DisplayIcon" from the context menu.
{
MsgBox a %FocusedRowNumber%
LV_GetText(name, A_EventInfo, 6)
Run %name%,, UseErrorLevel
}
else ; User selected "GoToFolder" from the context menu.
{
MsgBox b %FocusedRowNumber%
LV_GetText(name, A_EventInfo, 5)
Run %name%,, UseErrorLevel
}
msgbox %xname%
if ErrorLevel
MsgBox Could not perform requested action on %name%.
return
Re: LV_GetNext(0, "F") returns always 0
Thanks a lot!just me wrote:It must be done within the menu labels:...
BTW: I tried also to remove the "name definition" and thought that the GUI will be "Default", but it did not work either - only with your code.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
What do you mean with "I tried also to remove the "name definition ..."?
Re: LV_GetNext(0, "F") returns always 0
I replaced
and thought that without a special name it would be the "default-GUI"
Code: Select all
Gui, new,+HwndBundleList,Bundle Switcher
with
Gui, new,,Bundle Switcher
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
The Hwnd is a handle to the GUI window which can be used instead of a GUI name or number.
Source: Gui, New [, Options, Title]
If you want to use AHK's default GUI number (which is 1 in case that no name or number was specified) in combination with the New sub-command, you'd have to specify Gui, 1:New, ....
Code: Select all
Gui, New ; Creates a new unnamed and unnumbered GUI.
Gui, Name: New ; Creates a new GUI, destroying any existing GUI with that name.
If you want to use AHK's default GUI number (which is 1 in case that no name or number was specified) in combination with the New sub-command, you'd have to specify Gui, 1:New, ....
Code: Select all
#NoEnv
Gui, 1:New, , My GUI Window
Gui, Show, w400 h400
MsgBox, 0, A_DefaultGUI, The current default GUI is %A_DefaultGUI%.
Return
GuiClose:
MsgBox, 0, % "Bye, bye!", The label %A_ThisLabel% has been called!
ExitApp
Re: LV_GetNext(0, "F") returns always 0
It is, but not for the Menu thread.Peter2 wrote:... thought that without a special name it would be the "default-GUI"
Just like Gui, something: Default, it does not apply to other threads.Creates a new window and sets it as the default for the current thread.
Re: LV_GetNext(0, "F") returns always 0
I mentioned the "ListView_2.ahk" from the help file.
It does not use Gui, new, and this is why is can handle the menu thread without Gui, .... Default ...
Right?
It does not use Gui, new, and this is why is can handle the menu thread without Gui, .... Default ...
Right?
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: LV_GetNext(0, "F") returns always 0
Yes, without New and any name or number it will create a GUI with the default number 1. And
... Non-GUI threads use 1 as their default.
Re: LV_GetNext(0, "F") returns always 0
Perfect. Thanks.
I hope other beginners will benefit too from this detailed thread.
I hope other beginners will benefit too from this detailed thread.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Who is online
Users browsing this forum: Google [Bot], Raymondbit and 377 guests