Solved

Flickering CComboBox in MFC ActiveX Control

Posted on 1998-12-21
9
872 Views
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:
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
Comment
Question by:murrayc
  • 5
  • 4
9 Comments
 

Author Comment

by:murrayc
ID: 1326532
Edited text of question
0
 

Accepted Solution

by:
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:

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
 

Author Comment

by:murrayc
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.
0
 

Expert Comment

by:yoffe
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?

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Expert Comment

by:yoffe
ID: 1326536
yoffe@flex.net
0
 

Author Comment

by:murrayc
ID: 1326537
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
 

Expert Comment

by:yoffe
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.

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
 

Author Comment

by:murrayc
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.
0
 

Expert Comment

by:yoffe
ID: 1326540
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 104
Hibernate methods 2 58
sum67 challenge 35 89
isEverywhere  challenge 19 64
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now