LV_GetNext(0, "F") returns always 0

Get help with using AutoHotkey and its commands and hotkeys
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

LV_GetNext(0, "F") returns always 0

18 Feb 2016, 16:08

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
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

18 Feb 2016, 17:01

Did you change the GUI name/number or did you add another ListView?
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

18 Feb 2016, 17:04

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

Code: Select all

Gui, new,+HwndBundleList,Bundle Switcher
Gui, Add, ListView, r20 w580 vMyListView gMyListView Grid, Icon|Name|Status|Description|Path|Picture
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

Code: Select all

LV_GetText(name, FocusedRowNumber, 5)
via context I get nothing.

So it seems that it had lost the connection to the Listview ???
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

18 Feb 2016, 18:08

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 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 03:18

Code: Select all

Gui, new,+HwndBundleList,Bundle Switcher
creates a nameless, numberless GUI accessible only by the HWND. All LV_...() functions are using the default GUI to address the ListView control.
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
Menu labels are non-GUI threads using 1 as their default. That's why you have to set the default GUI at least:

Code: Select all

Gui, %BundleList%:Default
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 03:47

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
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 04:41

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
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 05:16

just me wrote:It must be done within the menu labels:...
:thumbup: Thanks a lot!

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 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 08:20

What do you mean with "I tried also to remove the "name definition ..."?
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 09:02

I replaced

Code: Select all

Gui, new,+HwndBundleList,Bundle Switcher
with
Gui, new,,Bundle Switcher
and thought that without a special name it would be the "default-GUI"
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 11:22

The Hwnd is a handle to the GUI window which can be used instead of a GUI name or number.

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

#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
lexikos
Posts: 6653
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 17:54

Peter2 wrote:... thought that without a special name it would be the "default-GUI"
It is, but not for the Menu thread.
Creates a new window and sets it as the default for the current thread.
Just like Gui, something: Default, it does not apply to other threads.
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

19 Feb 2016, 18:13

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?
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
just me
Posts: 6526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: LV_GetNext(0, "F") returns always 0

20 Feb 2016, 02:20

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.
Peter2
Posts: 243
Joined: 21 Sep 2014, 14:38
Location: CH

Re: LV_GetNext(0, "F") returns always 0

20 Feb 2016, 13:32

Perfect. Thanks.
I hope other beginners will benefit too from this detailed thread.
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, flipmania, Gully, jesusarell, Odlanir, SuperFoobar, v3Van and 204 guests