Add Gui context Menu items on the fly

Get help with using AutoHotkey and its commands and hotkeys
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Add Gui context Menu items on the fly

30 Apr 2017, 06:54

Hi,

I was wonder if someone might be so kind and point me in the right direction regarding creating Gui rightclick context Menus on the fly based on a channellist that varies in lenght depending on what channels the user has. In my case I have 14 favourite channels in an array and I wonder if it might be possible to create 14 Menu items and 14 Labels with a function or something like that? Right now I have done it the common way with one Menu command and one label for each channel. However some other user could for example have +50 channels. But spawning a context menu for +50 channels when it cover most of the screen area, wouldnt look very nice though.

So if any of you guys have done this before or knows some good scripts in this area or simply having good ideas upon an approach, please let me know.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Add Gui context Menu items on the fly

30 Apr 2017, 15:27

It would have been cool if this had worked although I dont understand why it wouldnt:

Code: Select all

  FavArray := ["S1HD", "SV2HD", "TV3"]
  Menu, DVBVContextMenu, Add
  Menu, DVBVContextMenu, DeleteAll
  For k, v in FavArray {
	ChannelName := v
	ChannelNumber := "FavChannel_" . k
	;msgbox % ChannelName "`n" ChannelNumber
    Menu, DVBVContextMenu, Add, %ChannelName%, %ChannelNumber%, +Radio
  }
just me
Posts: 7436
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Add Gui context Menu items on the fly

01 May 2017, 03:30

Hi zcooler, why do you need a special label for each menu item?
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Add Gui context Menu items on the fly

01 May 2017, 04:03

Hello just me,
Well, each menu item label sends a different channel switching command (postmessage) or COM SendCommand.

Code: Select all

FavChannel_1:
PostMessage, 0xB2C2, 0x0815, 0x08D,, ahk_class TfrmMain    ;Channelchange to SVT1 HD 0x08E=SVT2, 0x08F=TV3 etc.
;iDVBViewer.SendCommand(11)                                  ;Channelchange to Favourite 1
Im not sure if I want to continue finding out if dynamic assigning of Menus is possible, cuz it turns out displaying tooltips on menus items are somewhat complicated and therefor a less interesting option to venture further into. So I decided to try out building a GUI Context Menu instead, but am struggeling hard with alingning the colums of radio pic controls with channelnames text controls :oops:

Code: Select all

CheckedIMG := "F:\TV\test\MediaLauncher\icons\radiobutton_checked.png"
MaxChannelsPerColumn := "15"           ; max number of rows per column for show checkboxes
FavArray := ["SVT1 HD", "SVT2 HD", "TV3", "TV4", "Kanal 5", "TV6", "Sjuan", "TV8", "Kanal 9", "TV10", "TV12", "Discovery Channel", "Barnkanalen/SVT24", "Kunskapskanalen"]
Gui, ChannelContextMenu:New, ;-Border +Caption +OwnerDVBV
;Gui, Margin, 0, 0
Gui, Margin, 10, 10
;Gui, Color, FFFFFF
Gui, Font, s9, Arial
For index, title in FavArray {
  ;ChannelName := v
  ;ChannelNumber := "FavChannel_" . k
	;msgbox % ChannelName "`n" ChannelNumber
    ;Menu, DVBVContextMenu, Add, %ChannelName%, %ChannelNumber%, +Radio
	IsChecked := Channel_name[title]
	PicOptions := A_Index = 1 ? "xm Section w10 h10" : (Mod(A_Index, MaxChannelsPerColumn) = 1) ? "ys Section" : "xs y+10 w10 h10"
	Gui, Add, Pic, %PicOptions% Checked%IsChecked% vCRadio%index% +hwndHRADIO gCheckChannel  AltSubmit, %CheckedIMG%
	RBControls .= "|CRadio" . index
    RadioControls[HRADIO + 0] := title
	TextOptions := A_Index = 1 ? "ys" : (Mod(A_Index, MaxChannelsPerColumn) = 1) ? "ys Section" : "ys y+10"
	Gui, Add, Text, %TextOptions% vShowCB%index% +hwndHShowCB gFavChannel_, % title
	GBControls .= "|ShowCB" . index
    CopyControls[HShowCB + 0] := title
  } 
; Alternatively, Link controls can be used:
Gui, Add, Link,, Click <a href="www.google.com">here</a> to launch Channel List.
Gui, Font, norm
Gui, Show
return
CheckChannel:
return
FavChannel_:
return
Later on Im planning to mimic the blue highlighting OnMouseOver Menu items on the GUI also, but first things first.
just me
Posts: 7436
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Add Gui context Menu items on the fly

01 May 2017, 04:10

You might store the different values for PostMessage in an associative array (key = favchannel name), too.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Add Gui context Menu items on the fly

01 May 2017, 04:50

Yes, that was how i though I would handle it when the GUI context menu is working. Nonetheless I will abandon the Menu because of the Tooltip issue. The tooltip is an important key feature displaying Now and Next StartTime and TVshowEPGName for each channel :)

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, bby, DenisS, Enlapse, Hash817, mikeyww, RaptorX and 47 guests