Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 928
  • Last Modified:

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);
0
murrayc
Asked:
murrayc
  • 5
  • 4
1 Solution
 
murraycAuthor Commented:
Edited text of question
0
 
yoffeCommented:
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:

m_ComboBox.UpdateWindow();

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.

0
 
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yoffeCommented:
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?

0
 
yoffeCommented:
yoffe@flex.net
0
 
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.
0
 
yoffeCommented:
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.
0
 
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.
0
 
yoffeCommented:
I'm just happy that I could help.   If you have any more problems, post away...we'll be here.   Good luck.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now