Toolbar question - set/modify listButton string options

Discussions related to Visual Prolog
Post Reply
Harrison Pratt
VIP Member
Posts: 263
Joined: 5 Nov 2000 0:01

Toolbar question - set/modify listButton string options

Post by Harrison Pratt » 9 Mar 2018 17:53

How can I dynamically or statically add strings to a toolbar listButton? The Create Project Item wizard creates a listButton with an empty list in ProjectToolbar.pro. It is possible to edit the generated code, but the list is regenerated as [] when the project is rebuilt -- and we are amply warned to avoid modifying that code. :wink:

Code: Select all

constants % in ProjectToolbar.pro     style : vpiToolbar::style = tb_top.     controlList : vpiToolbar::control_list =         [             tb_ctrl(id_file_new, pushb, resId(idb_NewFileBitmap), "New;New File", 1, 1),             % ... lines deleted here ...             tb_text(id_tb_1_3, tb_static, 60, 0, 5, 10, 0x0, "LBuTest:"),             tb_lbut(id_tb_1_2, 128, ["one","two","three"], b_true, 0), % <== THIS LIST IS CREATED AS []             vpiToolbar::separator,             tb_ctrl(id_help_contents, pushb, resId(idb_HelpBitmap), "Help;Help", 1, 1)         ].
vpiToolbar::setValue/3 can set/unset the listbox item selected (I think) but I can't find any way to initialize or modify the listbutton selection list. It might be convenient in the future to be able to define/edit the initial strings n the creation wizard, but dynamic modification would be much more useful.

User avatar
Thomas Linder Puls
VIP Member
Posts: 2333
Joined: 28 Feb 2000 0:01

Re: Toolbar question - set/modify listButton string options

Post by Thomas Linder Puls » 11 Mar 2018 16:10

The toolbar code has not really entered the PFC age. Anyways, this seems to work:

Code: Select all

clauses     create(Parent) :-         Toolbar = vpiToolbar::create(style, Parent, controlList),         LBut = uncheckedConvert(windowHandle, gui_native::getDlgItem(Toolbar, id_tb_1_2)),         vpi::lboxClear(LBut),         vpi::lboxAdd(LBut, ["one", "two", "three"]),         ...
(The lboxClear is actually not necessary here, because it is already empty).
Regards Thomas Linder Puls
PDC

Harrison Pratt
VIP Member
Posts: 263
Joined: 5 Nov 2000 0:01

Re: Toolbar question - set/modify listButton string options

Post by Harrison Pratt » 11 Mar 2018 22:14

Thanks for the very useful tip, Thomas! I can create everything I need from that.

I didn't know that gui_native::getDlgItem/2 could be so useful.

From MSDN (my underscoring): You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifier...

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Looking to the future, I suspect that using the Ribbon control will be a more sustainable strategy.

Post Reply