Page 1 of 1

Toolbar question - set/modify listButton string options

Posted: 9 Mar 2018 17:53
by Harrison Pratt
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 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     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.

Re: Toolbar question - set/modify listButton string options

Posted: 11 Mar 2018 16:10
by Thomas Linder Puls
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).

Re: Toolbar question - set/modify listButton string options

Posted: 11 Mar 2018 22:14
by Harrison Pratt
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... ... s.85).aspx

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