Link to home
Start Free TrialLog in
Avatar of murrayc
murrayc

asked on

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:
m_ComboBox.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | CBS_DROPDOWN | CBS_HASSTRINGS, m_Rect_ComboBox, this, IDC_COMBOBOX);

In OnDraw(), I move it like so:
m_ComboBox.MoveWindow(m_Rect_ComboBox, TRUE);
Avatar of murrayc
murrayc

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of yoffe
yoffe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of murrayc

ASKER

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.
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?

yoffe@flex.net
Avatar of murrayc

ASKER

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.

ex.

instead of:
CListCtrl m_listMyList;

use:
CListCtrl *m_pList;

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

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

in OnDraw use:
if (m_pList)
   m_pList->UpdateWindow();


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.
Avatar of murrayc

ASKER

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.