Help with disable contexts menu Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 03:10

Hii,

im using the main example of the listview doc to display a context menu.
i would like to know if it is possible to disable one or more contexts from the menu ?

example (cut,copy & undo disabled):
Image

thanks.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with disable contexts menu

Post by wolf_II » 29 Aug 2017, 03:24

see Menu, check out the list for Cmd, P3, P4, P5 for Disable, MenuItemName

User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 04:05

i missed that, tnx wolf

User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 05:31

I may add one more qustion:

I want to show in MyContextMenu in the first option of the list (%ID) the FocusedRowNumber,
but instead this i got just the name of the column itself which is always Com1.

i tryed to use LV_GetText(ID, FocusedRowNumber, 1) which wokrs well in other parts in the code,
but not in this part.

see notes in code:

Code: Select all

Gui Add, ListView, vMyListView w130 h80, Com1 | Com2
Gui Show,
LV_Add(,"word1","tiktak1")
LV_Add(,"word2","tiktak2")
LV_Add(,"word3","tiktak3")


FocusedRowNumber := LV_GetNext()  ; Find the focused row.
LV_GetText(ID, FocusedRowNumber, 1) ; Get the text of the 1st field.

; Create a popup menu to be used as the context menu:
Menu, MyContextMenu, Add, %ID%, ContextOpen ; why i got Com1 instead the FocusedRowNumber which sould be word1, word2 or word3 ?
Menu, MyContextMenu, Add, show row number 1, ContextOpen2
Menu, MyContextMenu, Add, show row number 2, ContextOpen3
return

GuiContextMenu:  ; Launched in response to a right-click
if A_GuiControl <> MyListView ; Display the menu only for clicks inside the ListView.
    return
Menu, MyContextMenu, Show
return

ContextOpen:
return

ContextOpen2:
FocusedRowNumber := LV_GetNext()  ; Find the focused row.
LV_GetText(ID, FocusedRowNumber, 1) ; Get the text of the 1st field.
MsgBox, %ID%
return

ContextOpen3:
FocusedRowNumber := LV_GetNext()  ; Find the focused row.
LV_GetText(ID, FocusedRowNumber, 2) ; Get the text of the 2nd field.
MsgBox, %ID%
return

GuiEscape:
GuiClose:
    ExitApp
Last edited by Tomer on 29 Aug 2017, 06:07, edited 1 time in total.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with disable contexts menu

Post by wolf_II » 29 Aug 2017, 05:50

Try to check what the variable FocusedRowNumber contains, after you assign a value to it. It shows 0 for me.
I don't really understand the variation of the numbers 1,2 and 3 in your code?? I expect typos? (Menu open 2 -> get text from 1, ...)
Also, is this meant to be dynamic?

User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 05:59

wolf_II wrote:Try to check what the variable FocusedRowNumber contains, after you assign a value to it. It shows 0 for me.
I don't really understand the variation of the numbers 1,2 and 3 in your code?? I expect typos? (Menu open 2 -> get text from 1, ...)
Also, is this meant to be dynamic?


its gets the focused row, thats why i added for example ContextOpen2 & ContextOpen3,
so you can see it works well showing row number 1 & row number 2.

if you take off FocusedRowNumber := LV_GetNext() you'll get Com1 aswell..

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with disable contexts menu

Post by wolf_II » 29 Aug 2017, 06:13

Sorry, I still don't understand your concept of Add, show row number 1, ContextOpen2 or Add, show row number 2, ContextOpen3.
If it is important, then please elaborate.

But I guess it's not important, your interest lies in the first line of the context menu.
Have you checked what FocusedRowNumber contains after you assign a value to it? it contains 0 when I check.

User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 06:58

its not important for what im asking for, just a example for how geting the selected row name.

i got 0 as well in the first FocusedRowNumber,
but in the second i got 1.
i guess that coz i cant get the FocusedRowNumber before the listview show.

anyway all im asking is showing the selected row name in the first ContextMenu list,
for example if i mouse right-click on "word2" then i'll have the text "word2" in the top of ContextMenu list,
if i mouse right-click on "word3" then i'll have the text "word3" in the top of ContextMenu list,
and so on..


maybe i should not use LV_GetNext() for this..

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Help with disable contexts menu  Topic is solved

Post by Nightwolf85 » 29 Aug 2017, 07:24

You can't create the menu before the user clicks and expect info from the users click location to be usable in the menu.

You will have to delete and re-create the menu after the user clicks, or at least the menuitems that are dependent on where they click:

Code: Select all

Gui, -MinimizeBox
Gui Add, ListView, vMyListView w130 h80, Com1 | Com2
Gui Show,
LV_Add(,"word1","tiktak1")
LV_Add(,"word2","tiktak2")
LV_Add(,"word3","tiktak3")
Menu, MyContextMenu, Add,, ; Creates the menu so it can be deleted and re-built.
Return

GuiContextMenu:  ; Launched in response to a right-click
if A_GuiControl <> MyListView ; Display the menu only for clicks inside the ListView.
    return
LV_GetText(ID, A_EventInfo, 1) ; Get the text of the 1st field.  -- A_EventInfo contains the row number right-clicked
Menu, MyContextMenu, DeleteAll ; Delete the entire menu
Menu, MyContextMenu, Add, %ID%, ContextOpen ; create the menu after getting the info.
Menu, MyContextMenu, Show
return

ContextOpen:
return

GuiEscape:
GuiClose:
    ExitApp

User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with disable contexts menu

Post by Tomer » 29 Aug 2017, 07:31

tnx Nightwolf85
works like a chram!

Post Reply

Return to “Ask for Help (v1)”