Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have continue to find handling WM_PAINT for my application a challenge.

I repaint by copying from a memory compartible DC to window DC using BitBlt a follows.

C++
case WMN_PAINT:
hdc = BeginPaint(hWnd,&ps);
BitBlt(hdc,ps.rcPaint.left,ps.rcPaint.top,
ps.rcPaint.right-ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top,memDC,ps.rcPaint.left, + iHpos, ps.rcPaint + iVpos,SRCCOPY);
EndPaint(hWnd,&ps);

where memDC - memmory compartible DC,
iHpos = Hprizontal; scroll position, iVpos - verticical scroll position


I write from a buffer to the memeory DC memDC and allow the system to copy from the memDC to window.

The big problem is that once iVpos and iHpos exceed the size of the memory DC proper display collpses.

I can handle repaint for text only or bitmap only well, but once it is a mixture of text and bitmap rendered on a DC i9n unpredictable manner I end up using this memory DC approach.


My buffer is organised in a manner similar to this

C++
class Buffer
{ 
   vector<int> iPageCount;
   vector<int> icharCount;
   vector<tchar> chChar;
   vector<int> icharXpos;
   vector<int> icharYPos;

  vector<int> iImageCount;
  vector<string> sImagePath;
  vector<int> iImageXpos;
  vector<int> iImageYpos;
};

I attempted to do a page by page rendering but the same problem was faces. how do I tackle this issue of memmory DC limit exeeding problem.

How does internet explorer, MS word amd others handle repainting from the view point of scrolling.

The problem is a problem of repaint, scrolling and memory DC.

Please, how do I solve this problem


I really don't know that the above method is called double bufferig. I use only one memory DC. What really is the double buffering? How is it used?



Someone said how can use SetWindowOrg to solve this problem, how is it done?
Posted
Updated 17-Oct-12 6:18am
v4
Comments
Santhosh G_ 17-Oct-12 9:49am    
http://www.codeproject.com/Articles/3175/Displaying-Bitmap-with-Scrolling

This article might be helpful for you.

1 solution

As you have found out, double buffering via a memory DC works only up to a certain limit. If your virtual drawing plane becomes very big, this technique requires increasingly more memory to buffer your entire contents.

Scrolling works best by using the API call ScrollWindow and in addition painting the uncovered part of the window.

As long as your entire contents is no more than a couple of window widths or heights, it is very efficient to draw the uncovered part by BitBlt-ing from your big buffered bitmap.

For larger contents you can generate the memory bitmap in chunks on-demand and feed the uncovered parts from their. This requires quite some buffer management code in your software. As alternative, you might want to depart from the double-buffering approach and generate the contents in WM_PAINT just on demand and only the slips that are needed by the scrolling mechanism. This is not as efficient, but a lot easier to implement.

Browsers use generally the more complicated approach with full double buffering. But don't think that their code is easy and compact.
 
Share this answer
 
Comments
Gbenbam 17-Oct-12 11:26am    
Please, where can I get examples of any or both of the two profered solution you suggested.
Gbenbam 17-Oct-12 11:34am    
Please, where can I get examples of any or both of the two profered solution you suggested. I mean the following proferred solution of yours.


For larger contents you can generate the memory bitmap in chunks on-demand and feed the uncovered parts from their. This requires quite some buffer management code in your software. As alternative, you might want to depart from the double-buffering approach and generate the contents in WM_PAINT just on demand and only the slips that are needed by the scrolling mechanism. This is not as efficient, but a lot easier to implement.
nv3 17-Oct-12 17:22pm    
Unfortunately, I don't have a nice compact example at hand. But let's start with the scrolling mechanism you use. If you amend your question by the code you use for scrolling, I will try to point you in the right direction.

In order to help you, please tell us the size of the content you are trying to display. That would help to choose the right approach to your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900