Flickering CComboBox in MFC ActiveX Control

I have created an ActiveX control using the MFC ActiveX Control Wizard, and have added controls dynamically. I have no problems with CButton, CEdit, etc, but CComboBoxes flicker when their text is edited. For some reason the Active Control is being sent paint messages continually.

I create a ComboBox like so:

In OnDraw(), I move it like so:
m_ComboBox.MoveWindow(m_Rect_ComboBox, TRUE);
Who is Participating?
yoffeConnect With a Mentor Commented:
I believe the reason you are receiving continuous paint messages is because you are telling (through your MoveWindow call) it to repaint continuously!   The third argument indicates, when TRUE, requests a repaint.   When you get your repaint, you are calling MoveWindow again, thus sending another paint message.   Try using UpdateWindow in the OnDraw method, like such:


If you need to move the combo box or resize it, this is when you should make your call to MoveWindow.   Consequently, you should use UpdateWindow, not MoveWindow, in your OnDraw for all of the controls you are drawing to the canvas.   If you need any more details, let me know.

murraycAuthor Commented:
Edited text of question
murraycAuthor Commented:
From the MFC documentation, it seems that the BOOL bRepaint parameter of CWnd::MoveWindow() should specify whether the control itself is sent a PAINT message, not the parent window.

Using UpdateWindow() after MoveWindow(rect, FALSE) seems to be equivalent to MoveWindow(rect, TRUE).

I need to use MoveWindow() to ensure that the controls stretch to fit the size of the ActiveX control.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Can you send me a skeleton portion of your code...just the containing the control (and subcontrol) creation.

Consequently are you tesing the control in the test container or another app?

Also, just out of curiosity, when is your rect getting set?

murraycAuthor Commented:
I describe the technique used at http://www.geocities.com/SiliconValley/Bay/1283/learning/windows/createactivex.html. I will correct the article when I have a solution.

I am testing in the ActiveX Control Test Container.

The rect is being changed whenever the user resizes the control. So I can fix the problem by using a member boolean m_bRedrawNeeded. But I think that is excessive. Maybe most controls do not redraw themselves if their new rect is the same as the old, but ComboBox doesn't do this check. However, I still don't understand why all those PAINT messages are being sent.

I assume that you have been using a similar technique without this problem.

Thanks for your time, by the way.
The technique you referred to (at geocites.....) seems straightforward and correct.   However, let me suggest the following just from the standpoint of style.   Why not call MoveWindow in response to a WM_SIZE message in the parent? And UpdateWindow from the OnDraw.   Further, if the control you are creating should be visible as soon as it is created, you should use the WS_VISIBLE flag in the call to Create.

Also, something else that I should warn you of.   When handling the ON_SIZE, it is good to insure that the WM_CREATE message has already been sent.   This can be accomplished by using a BOOL member in the variable to store if the controls (within the activeX control) have already been created.   What I have commonly seen and used is storing pointers to the controls.


instead of:
CListCtrl m_listMyList;

CListCtrl *m_pList;

in OnCreate use:
m_pList = new CListCtrl;
if (m_pList)

in OnSize use:
if (m_pList)
   //do size calcs
   m_pList->MoveWindow(..., TRUE);

in OnDraw use:
if (m_pList)

Like, I said, there is nothing fundamentally wrong (that I can see from you question, the web page to which you refered, or your follow up coments) with what you are doing.   Until I see your code, I'm afraid that I cant diagnose your problem any further.   As a suggestion, create a dummy project (ActiveX ctrl) and add only a ComboBox control to it.   Draw the control to the canvas and see if it flickers.   If it doesnt, add the rest of your controls.   If it still doesnt flicker, then there is some other part of you code that is posting WM_PAINT messages into the message queue.
murraycAuthor Commented:
Yes, I have solved it temporarily by only moving the controls when they need to be moved. Are you sure that you want to see the code? I could email it, but I'm sure you don't have the time. Thanks for all the input, it was nice to know at least that I wasn't too far out on a limb.
I'm just happy that I could help.   If you have any more problems, post away...we'll be here.   Good luck.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.