Re: How to preserve CListbox contents between dialogs
I agree that the global "Listbox" approach wouldn't work as you wouldn't be
able to assign a listbox to multiple dialogs. However, I have made dialogs
that are sort of global (non-modal) that I keep around for the life of the
application and just show and hide them as needed (settings, file browser,
things like that). That approach might work for OP. However, the virtual
list control approach works really fast and if the data is available in a
document somewhere it could be loaded and stored for the life of the program
(and modified as needed) and the list controls would always reflect it.
I've almost abandoned using list boxes these days. I'd rather use a single
column list control with or without a header. I find them to be easier to
use and much more flexible. I used to use list boxes with pre-loaded values
for shorter lists, but those are so difficult to translate since the values
are stored in the RC file as hex so the translators almost never even notice
them. I dynamically load everything now.
Tom
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:cpre33t59bmfg54og3s1rgv186dsrs9p2r@4ax.com...
The global window approach probably won't work. ALthough there is a
SetParent operation,
it is not really trustworthy, and has a lot of issues because there is
still a parent link
maintained in the kernel that you can't see, and can't change. It would
not surprise me if
your perceived problems are directly related to these issues.
How many items are in the list? Consider using the CListBox::InitStorage
method to
improve performance.
You can also use virtual listboxes that are filled "on demand" and
therefore don't have to
be preloaded. I would consider either of these before the SetParent
solution.
joe
On Tue, 01 May 2007 08:04:38 -0700, Henryk Birecki
<soaringpilot@sbcglobal.net> wrote:
In my MFC based application that shares code between PC and PocketPC I
have three CListBox type objects that I want to be able to share
between different Dialogs that are invoked with DoModal at different
times. CListBox contents are pretty much static, but it takes a long
time (especially on older PocketPCs) to initialize them with
information. I wanted to Create global CListBox windows and then share
them between dialogs as needed. So in InitDialog I create listboxes
(WS_CHILD|LBS_NOTIFY...) if they are not windows yet and fill them
with their content. Otherwise I just set the dialog as their parent
with SetDialog. In the dialog OnDestroy I set listbox parent to NULL
so it is not destroyed with the dialog. This almost works. The problem
is that depending on what is happening between dialog invocations,
second time a dialog is opened message mapping between dialog and
listbox is lost so for instance ON_LBN_SELCHANGE(IDC_ListBox1,
OnSelchangeList) in the dialog code has no effect (dialog never
receives notification), and the listbox does not get re-painted
properly (no erase of background).
Can someone point me to proper way of preserving listbox contents
between dialog invocations? Using a long lived nonmodal dialog will
not work for me as I need different ones at different times.
Thanks in advance,