Re: Duplicate entries in drop down box



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 drop
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?
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Entwicklung von Unix-Anwendung mit C++ (m/w)/ NRW : Ref.-Nr.: 37302/1
    ... I am responsible for design and implementation of the persistent data server working with mySQL. ... Developed within very short time the product was successfully installed ... Reengineering and implementing a display tool for Experimental Physics Industrial Control System ... Developed an operator interface under X Window for High Energy Physics Accelerator Control System. ...
    (de.markt.arbeit.d)
  • Re: loosing messages leakes my app...
    ... It posts messages to a window, ... why don't you always use PostMessage? ... threads rely on the control, then you should not destroy the control before the ... POSSIBLY know the unique target window for which this is intended. ...
    (microsoft.public.vc.mfc)
  • Re: Owner Draw STATIC Window with XP Themes
    ... >> You should open a theme once per window... ... Each OpenThemeData has a matching CloseThemeData. ... say, "Well, CloseThemeData doesn't take an HWND, it takes only an HTHEME, so ... The following code sample demonstrates how to draw a button control. ...
    (microsoft.public.vc.mfc)
  • Re: Owner Draw STATIC Window with XP Themes
    ... >> You should open a theme once per window... ... Each OpenThemeData has a matching CloseThemeData. ... say, "Well, CloseThemeData doesn't take an HWND, it takes only an HTHEME, so ... The following code sample demonstrates how to draw a button control. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Repost for MS: UnsafeNativeMethods.CallWindowProc NullReferenc
    ... I'd be interested to analyse the dump also. ... Using the .NET Reflector to look at the Control ... > requires a valid window handle, ... > If you look at the implementation of NativeWindow, ...
    (microsoft.public.dotnet.framework.windowsforms)