Flickering CComboBox in MFC ActiveX Control

Posted on 1998-12-21
Last Modified: 2013-11-20
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);
Question by:murrayc
  • 5
  • 4

Author Comment

ID: 1326532
Edited text of question

Accepted Solution

yoffe earned 150 total points
ID: 1326533
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.


Author Comment

ID: 1326534
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.
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 1326535
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?


Expert Comment

ID: 1326536

Author Comment

ID: 1326537
I describe the technique used at 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.

Expert Comment

ID: 1326538
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.

Author Comment

ID: 1326539
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.

Expert Comment

ID: 1326540
I'm just happy that I could help.   If you have any more problems, post away...we'll be here.   Good luck.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 75
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
no14 challenge 14 70
modThree challenge 4 96
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question