Re: Duplicate entries in drop down box
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 18 Aug 2006 20:54:42 -0400
The first problem you have to deal with is that you must *NOT* access any control from a
different thread. Period. So whatever code you have to do this, you have to rewrite it
to NOT touch that control.
The usual way to handle this, you use a PostMessage from the worker thread to the main GUI
thread and the main GUI thread takes this message and adds things to the combo box. Do
not touch ANY window owned by one thread from another thread (PostMessage doesn't touch
windows; it touches the thread's input queue). Do not use GetCount in a thread. Do not
do AddString in a thread. Do not touch the control.
I have no idea what you mean by "call (CInstrumentStatusDlg *)", since I see nothing here
that implies a call. I see a cast, which is a compile-time trick that says "I'm going to
lie to you about what this type is, so trust me".
I have no idea what is wrong, but the very presence of the GetCount says "this code is
flawed beyond recovery" so there's nothing to talk about until the code is fixed.
joe
On 18 Aug 2006 15:14:16 -0700, "whiskers" <whisk3rs@xxxxxxx> wrote:
I have several predefined values in the properties dialog of a dropJoseph M. Newcomer [MVP]
down CComboBox which get duplicated at run time.
I tracked the number of elements in the drop down box via
CComboBox.GetCount() and discovered that when my program creates a
thread, which receives a pointer to the dialog, the number of elements
in the drop down box doubles when I cast the dialog:
void Thread(void *lpParam)
{
CInstrumentStatusDlg * pIS = (CInstrumentStatusDlg *)lpParam;
then pIS->dropBox.GetCount() returns 2x the number of required
elements
I'm guessing that when I call (CInstrumentStatusDlg*), it repopulates
the values in the drop down box... which is strange, I'd suppose MFC
would not allow that to happen. How do I prevent this from happening?
Singleton implementation? Manual addition of values to the drop down
box? Something else?
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Duplicate entries in drop down box
- From: whiskers
- Duplicate entries in drop down box
- Prev by Date: Re: OO architecture in MFC
- Next by Date: Re: Application icon
- Previous by thread: Re: Duplicate entries in drop down box
- Next by thread: Re: Duplicate entries in drop down box
- Index(es):
Relevant Pages
|