Double Buffering, Reduce flicker of child control

Hello,

I have CWnd that wraps a third party control (TX4OLE).  Currently the
third party control paints to the screen and our code draws on top of
it.  This process can produce a bit of flicker and I am trying to
eliminate this using double buffering.  Is there any way I can
redirect the output of the control into a memory buffer?  I already
handle WM_PAINT calls in the window proc, but there doesn't seem to be
any way to change the device context the control uses.  Any help or
ideas are appreciated.

Thanks,
Jay

0
3/5/2007 4:43:01 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
914 Views

Similar Articles

[PageSpeed] 40

On Mar 5, 11:43 am, "Jay Hamilton" <jayhamilto...@gmail.com> wrote:
> Hello,
>
> I have CWnd that wraps a third party control (TX4OLE).  Currently the
> third party control paints to the screen and our code draws on top of
> it.  This process can produce a bit of flicker and I am trying to
> eliminate this using double buffering.  Is there any way I can
> redirect the output of the control into a memory buffer?  I already
> handle WM_PAINT calls in the window proc, but there doesn't seem to be
> any way to change the device context the control uses.  Any help or
> ideas are appreciated.
>
> Thanks,
> Jay


Greets Jay,

We have had an identical issue. We are considering different
approaches,
but the current 'fix'  (read:  hack)  makes a considerable difference
if you have
no other alternatives.

Note that this approach will only help providing:
- The image you are drawing on top of does not change very often
- You are able to detect when the image does change (without having to
examine pixels)
- A single flicker whenever the image changes is acceptable


Just by reading the above restrictions may give you some insight on
the method I
am proposing. In essense, you take a snapshot of the image whenever it
has
changed. For every other WM_PAINT you recieve (until the image changes
again),
you perform double-buffering using your snapshot.

1)  Intercept WM_PAINT message before it reaches the 3rd party control
2)  Determine if the 3rd party control image has changed
   if yes:  allow 3rd party control to process WM_PAINT, then copy the
entire client rect to a memory buffer  (snapshot), then continue to
step 3
   if no :  do not redirect WM_PAINT to 3rd party control, continue to
step 3
3)  Copy snapshot to backbuffer
4)  Draw your custom content into backbuffer
4a)  CLIP REGIONS*
5)  Blit backbuffer to window DC
6)  ValidateRect(hWnd, NULL)   to signify that the paint was handled
(otherwise you may get a never-ending flood of WM_PAINT)



*Note that blitting the backbuffer to the window DC is likely going to
be the slowest operation. If maintaining decent performance is
important
you can use clipping regions  (NOT update regions)  to give a
substantial speed boost to the backbuffer->winDC step;   we
experienced a 10x performance increase after generating clip regions
and selecting them into the winDC.

4a)  CLIP REGIONS   (Extra Credit)    ;)
  i)  Generate a combined HRGN that minimally contains all the pixels
that need to be drawn. For lines, polygons, ellipses, etc. you can
'record' a path when drawing and create a region from this using
PathToRegion(). For text or other complex shapes you can simply add a
rect that encapsulates the complex shape.
 ii)  Combine this HRGN with a previously saved one;  but keep the
uncombined one separate so you can store it later as the previously
saved for next WM_PAINT. This is for 'undrawing' the old contents.
iii)  Select the combined clip region into the window DC
(SelectClipRgn)

If you are crazy or desperate enough to follow through with this
technique, which does work, I have one final piece of advice:
DO NOT USE UNION TO COMBINE REGIONS    (in GDI
CombineRgn(RGN_OR)       in GDI+    Region::Union).
The algorithm is bugged and you will lose entire sections when the
regions are unioned. Proof of this bug at this URL:
http://www.opac.ch/bugs/

To merge regions you will need to use them inverted  (ie:  instead of
starting with empty region and using RGN_OR/Union() to add to it,
start with infinite region and RGN_DIFF/Exclude() from it). Before
selecting into DC as a clip region, invert it  (XOR it with an
infinite region).


Best of luck,

-dp

0
dpeterson1 (10)
3/5/2007 9:20:47 PM
Will this article help?

  http://www.codeproject.com/gdi/flickerfree.asp

/ravi

=============
Ravi Bhavnani
http://ravib.com
VC++ MVP
=============

"Jay Hamilton" <jayhamiltoniv@gmail.com> wrote in message 
news:1173112980.768934.12690@8g2000cwh.googlegroups.com...
> Hello,
>
> I have CWnd that wraps a third party control (TX4OLE).  Currently the
> third party control paints to the screen and our code draws on top of
> it.  This process can produce a bit of flicker and I am trying to
> eliminate this using double buffering.  Is there any way I can
> redirect the output of the control into a memory buffer?  I already
> handle WM_PAINT calls in the window proc, but there doesn't seem to be
> any way to change the device context the control uses.  Any help or
> ideas are appreciated.
>
> Thanks,
> Jay
> 


0
ravib (5)
3/5/2007 9:46:36 PM
I found a working solution after some trial and error, this approach
seems to work great for me.  I also had to remove all calls to the
text control's Refresh fxn, but otherwise this is pretty straight
forward.  Thanks to those who replied, it helped point me in the right
direction-

void MyDerivedTextEditor::OnPaint()
{
	CDC* pDC = GetDC();

	CRect rectClient(0,0,0,0);
	GetClientRect(&rectClient);

	CDC memDC;
	memDC.CreateCompatibleDC(pDC);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap(pDC, rectClient.Width(),
rectClient.Height());
	memDC.SelectObject(&bmp);

	Print(&memDC, PRF_CHILDREN | PRF_CLIENT | PRF_OWNED);

	// Custom draw on top of memDC, e.g. circle some text
	...

	// Paint to the buffer
	pDC->BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &memDC, 0,
0, SRCCOPY);

	ReleaseDC(pDC);
}

BOOL MyDerivedTexteditor::OnEraseBckgnd()
{
	return TRUE;
}

0
3/6/2007 11:05:54 PM
Reply:

Similar Artilces:

painting list control border
Hi is it some way to do it? I have tried to do it by handling WM_NCPAINT but it's not work:( ---------------------------------------- LRESULT MyListCtrl::OnMyNCPaint(WPARAM wParam, LPARAM lParam) { CDC *pDC = GetDC(); pDC->FrameRect(&m_rcWindow,&m_brMainFrame_1); return FALSE; } ------------------------------------------------------------------- in message map i have added following macro: ON_MESSAGE(WM_NCPAINT, OnMyNCPaint) thanks in advance... Regards, SunFire "SunFire" <sunfire@noaccount.for.nntp> wrote in message news:bno7do$m5f$1@nemesis...

Problem with DOUBLE LETTERS and Backspace
Hello, A friend of mine is having the following problem: my computer refuses to type double leters or backspace to delete typing. Any ideas of what is causing this or how to fix it? Thanks ahead of time... This is not a chat room - no need to post multiple messages. --=81 Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. =20 After furious head scratching, Teched asked: | Hello, |=20 | A friend of mine is having the following problem: |=20 | my computer refuses...

double click does not open file
This subject was discussed before, i remember... but i can not view this from outlook because it says that the message has been removed from the server. is there anyone remembering the solution? Bur�in SARIHAN Here is the conversation from that thread Hi Gail I did the Excel Exe/regsever and the tools to options addins and the Ignore other application box was unchecked, you suggested and it still when I select an excel program it only goes to the Excel application and will not open the file until I go to file/open and re-find the file under local disk. I thought perhaps because the files...

Enable the autocomplete of text control (IE control) in CDHtmlDial
I am wondering how can I enable the autocomplete function with the (web) text control in CDHtmlDialg, similar to that when I browse it (HTML file) in the IE. ...

Control Code to set a Date
My Combo Box [cbOwnerName] has a Row Source [qPayableTotalForPayment] which has 9 Columns in combo box the last Column being [My Date]MyDate: Format([MaxOfBillDate],"d-mmm-yy") I want to code my Button to Change the date in [tbStartDate] to the date im [cbOwnerName] once selected I click Button to give that date in [tbStartDate] Thanks for any help.........Bob Hi Bob, If I am understanding correctly this should solve your problem. "OnClick" event Sub Command1_Click() Dim x as string x = me.cbOwnerName.Column(8) me.tbStartDate = x End Sub HTH, Nick "Bob V&q...

problem with losing control of a worksheet
I am completely flabbergasted; I am editing a worksheet which is 1/5th what it used to be - comparing two databases which are somewhat out of control. If two lines match exactly, I delete them, if two lines exist but do not match, I correct the database and delete them, and if there is an orphan, I hide it, with the intent of going back to match them against other databases. Now I am getting a weird display, with different words in column A, am unable to go below line 30, and am coming to the conclusion the worksheet has been compromised. I just printed off a section for further work...

Anybody know of an EDITABLE PAGINATION control?
Is there a .Net (preferably WPF) text editor that supports ON SCREEN pagination? I.e. a rich text box that visually shows the pages / page breaks ala Word "Print Layout" in that "looks like a piece of paper" feel? I have heard of people drawing ---- lines on top of the rich text editor to simulate the Word "Normal Mode". Would be nice to also support Word "Reading Mode" where you have the 2 x 2 or 4 x 4 screens. I know WPF has the DocumentPaginator objects, but those are read only. Kind of want the DocumentPaginator + editable. Is ther...

Double combo charts
I have a set of data: 4 columns columns are categories: DSD, 3PL, DCs, and Totals) by 5 rows (rows are years 2005 - 2009). I have successfully created a combo chart to show the first 3 columns as bars and the 4th (totals) as a line. I also have a nother chart (essentially the components of DCs) in a stacked column. My question is this: Can I have the side by side charts by year with one of those data series a stacked column AND the line for the totals all on the same graph. If you need a sample file, I have one with both graphs and data already completed. Any help would be appreciat...

Control Of Horizontal Page Break
When clicking on 'View - Page Break Preview', I am able to drag the page break to the right one column, so that all of the columns in my 'Print Area' are printed on the first page. Why is this so, and can I control this from VBA? Thanks for a response, Chuckles123 -- Chuckles123 ------------------------------------------------------------------------ Chuckles123's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=14948 View this thread: http://www.excelforum.com/showthread.php?threadid=319474 The way to control the number of pages that are prin...

Hiding Control BAsed on Check Box
I have a check box control on a form, "Complaint", which when unchecked I want the ComplaintClosed memo control greyed out. If Complaint is checked I then want the ComplaintClosed control to be visible and a message box to display. I have used the following code, but the ComplaintClosed control will only do as it should when I go to another recoed and then return to the current record. Any help would be greatly appreciated. Private Sub Form_Current() If Me!Complaint = 0 Then Me!ComplaintClosed.Enabled = False Else Me!ComplaintClosed.Enabled = True MsgBox "Compl...

View vs. Control
Hello all, this question concerns how a certain app be built - generaly - using MFC. App's function: To analyze simple text files that are supposed to obey strict formatting rules and warn on any mistakes it finds in the files (such as wrong positioning, expecting to find a number but encoutering a letter instead... etc.) So far, a standard MDI app with the "formatting rules" hard-coded inside it would do. But - The "formatting rules" themselves are several, meaning for this file the app will operate one set of rules, and for that file - another. So, I wish the ...

SDI | CTabCtrl in CFormView
Actually, I'm resizing the tab control fine, to the size of the FormView. Then, I call SendMessageToDescendants to get my tab to resize. Problem is that in OnSize of my CPropertyPage, I call GetClientRect and it always returns the same size. I assume, the size of the dialog resource. How can I resize my property page to fill the new width/height of the Tab Control? Or, how can I obtain the width and height of my tab control from within my PropertyPage? My property page doesn't seem to know the HWND of the Tab Control. I'm considering passing that in and then using that ...

assertion when trying to call funtion on control inside a cview
I created a CListCtrl object which is a member variable of my view class inside OnInitialUpdate(). void CMyView::OnInitialUpdate() { CView::OnInitialUpdate(); m_wndList.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_LIST | LVS_SINGLESEL, CRect(10,10,200,120), this, 999); } However, when I try to call a function on the control in another member function like OnSize(), I get an assertion error. void CMyView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); m_wndList.MoveWindow(CRect(10,10,cx-10,cy-10)); } What am I doing wrong? M1 wrote: > > I created a...

IE8 and ActiveX Control issues.....
I've recently upgraded from IE7 to IE8, and I'm running Windows XP with SP3. My problem with IE8 stems from using Facebook. Whenever I try to upload photo's, first, I'm told I must install ActiveX Controls, and all of a sudden, an error message pops up. The message says, and I quote; "iexplore.exe - Application Error The instruction at "0x10160068" referenced memory at "0x10160068". The memory could not be "written". Click on OK to terminate the program Click on CANCEL to debug the program" When I click on OK, all the p...

Org Chart: How do I connect a child to multiple parents?
I'm trying to create a support diagram in Powerpoint 2007 using SmartArt. I started an org chart, but my help desk, technichal support and super-users all funnel their issues to the same department for second-level support. It seems that when I create a child box in the org chart, it can only be linked to a single parent... how do I link that child to three parents? In this case, SmartArt isn't smart enough to do what you want it to do. If it's not too complex, you can create a new org chart by drawing rectangles and connector lines. That would allow you to (manually...

Processing "Control + C" keys in RichTextBox.KeyDown()
Hi there, I'm using a RichTextBox to create a custom editor, my class inherits from it. I've set to false the property ShortcutsEnabled and I need to handle the combination of keys Control + C. I've tried it in many ways using the modifiers of the KeyEventArgs, using GetKeyboardState(), using GetKeyState() in the RichEdit KeyDown event but it doesn’t work. I think the problem is that when the user press both keys the event is not fired for some reason, because if I check for the control key only it works and the same for the C key but when both are pressed it does...

using a pre-filled control on form load gives NULL
I have a form which has unbound controls PeriodStartDate and PeriodEndDate which are pre-filled on form load. I want to use these dates to filter the records available on the form. For all the options I have tried I get an Invalid use of NULL message. I am fairly certain it is because the user has not entered anything in the controls and that there is a way of forcing Access to "read" the values in them. I have the following (I will only give the start date), Dim strPeriodStartDate As String strPeriodStartDate = Me.PeriodStartDate ..... I have also used strPeriodSta...

Visual controling of stock level
I am wanting to create a spreadsheet that will allow me a visual coun on the level of stocks I have. I want to nominate an intended level of a product, have a colum showing items on back-order and also another column showing items i transit. I want it to display a message saying: � I need to order x qty of a product because it is below the intende level. � Display a message saying no order is needed due to being at th intended level. � A message showing a qty over the intended level. I guess the two columns (transit and back order) will need to b considered to allow the appropriate message...

make checks on the fly a double entry through accounts payable
with checks on the fly the step of posting to accounts payable is bypassed and this creates an out of balance issue between the cash account and the GL cash account ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/Ne...

How to reduce the size of a .pst file
Hello, Is there any way to reduce the size of a .pst file using Microsoft.Office.Interop.Outlook (programmatically start PST Compaction)? Any help would be appreciated. Tanya No. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Tanya" <Tanya@discussions.microsoft.com> wrote in message news:BCD61FCE-39DE-4605-8679-0537B19C2C57@microsoft.com... > Hello, > > Is there any way to reduce the ...

Control Toolbox: How do I use the "Combo Box?"
Hi, I need a drop down box in a particular cell, getting it there is easy, putting what I want in the drop down box/list is not! How do I get a "List" in the the combo box to read: 1, and then under that number I want 2, all the way up to 5. I want it to work so that I can see the drop down box and when it is selected I can see the numbers 1 thru 5 following each other in order, below each other. I have tried "Edit" under "Combo Box Object", that doesn't work! If I double click the "Combo Box" in the cell, I go into a "Microsoft Visual Basic&qu...

Reducing repetitive calculation not working
A B C 1 Fruit Qty =INDEX($1:$1048576,2,2):INDEX($1:$1048576,4,2) 2 Apple 1 3 Orange 2 4 Apple 3 Why does =SUMIF(A2:A4,"Apple",B2:B4) return the correct value ... .... while =SUMIF(A2:A4,"Apple",C1) returns a #VALUE error ? The reason I'm not including the formula in C1 as the sum_range in the SUMIF formula is to reduce the number of duplicate calculations (100,000+). I tried creating a name with the formula in C1 and using the name in the SUMIF formula as the sum_range and that works. But since the sum_range changes, I would have to use the OFFSET function to inc...

DPM 2010 new option to reduce volume size.
i've read in a previous mesage that: > - I couldn't find out how to reduce the size of the "Recovery point volume" > and increase the size of the "Replica volume". [venkat] you can increase replica volume by increasing per laptop allocation. the shrink option is not present in beta build, it will be available in RC. Which is wonderfull. I presume this "reducing" volumes also counts for repica volumes. A while ago I've als asked the question if there is a optimization option for defragmation of the partitions on which the ba...

Double Click Formula Cells
When you double click on a cell and there is a formula in the cell then the precendents are selected. Is there a way to turn this off or automatically go back to the cell you were on without any change to the window and its positioning. What is the VBA for this? Thanks in advance JJ Tools>Options>Edit Check "edit directly in cell" and you won't go to precedents. Application.EditDirectlyInCell = True Gord Dibben Excel MVP On Thu, 16 Sep 2004 13:34:07 +0100, "JJ" <f@o> wrote: >When you double click on a cell and there is a formula in the cell the...

How do controls get connected to variables in a CFormView?
Greetings! I am trying to modify a project that generates an ActiveX control. The control window is a CSplitterWnd with two panes, one on top of the other. The class representing the bottom pane is derived from CFormView. It has several controls, whose initial placement is determined by a resource. The controls are positioned in a routine called from the OnSize() event handler. That handler checks to see if m_hWnd of one of the control variables is pointing to a valid window yet, and if it is, it repositions all of the controls, happily referring to them by their variable names. The top ...