Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My app's document contains redered images, ellipse, rectangles, lines etc. For as long as I don't scroll past the memory dc bitmap size, display comes out fine, but ones I scroll over a distance greater than the memory dc bitmap size,the display goes hay-wire. How can I resolve this. All examples online assumes the scroll range will be within the memory dc bitmap size
range.

What I have tried:

I have spent several hours googling. Examples seen online were not useful.
Posted
Updated 22-Mar-24 16:10pm

If I understand you right, you are trying to "draw a picture" (which is what all text and lines end up as when they are rendered for actual display) that is bigger than the bitmap you are drawing into.

Imagine this: you have a whiteboard on your office wall, and you have a picture of a cat you want to draw. You draw it's head and that fills the whiteboard. if you start to draw the body, you will be drawing on the wall around the whiteboard, and it's feet and tail will require you drawing on the carpet.
Nobody is going to be happy about that - and cleanup is going to be a bitch!

Your two options for the whiteboard are to scale the cat so the whole cat fits on the board and you don't need to draw on the walls at all; or to rub out the head and draw the lower half of the head and bit of the body, then erase that and draw a lower bit, and so on.

That's the choices you have to make with your software: if you draw outside the bitmap then you will be writing in memory that is in use for other things - so scale the picture of scroll it by successively redrawing a small portion as needed - depending on what your software is trying to do!
 
Share this answer
 
Comments
Gbenbam 23-Mar-24 12:38pm    
I believe that successively drawing small portion as needed may be what I need. Could you possibly help a contrived example codes. Examples online are not too relevant. Should you decide to help with the contrived sample code. It might be good if you read my comment to the second solution below. It represents the challenge. I have tried in the past to draw content successively as needed, but no algorithm that I came up with has been able to do it
OriginalGriff 23-Mar-24 12:58pm    
Have a look at how the .NET PrintDocument class is used: it handles pages in a pretty simple way.
Google will find you tutorials on how to work with it which will help you understand what you need to do in your code.
Gbenbam 23-Mar-24 21:06pm    
Okay, I saw the .Net Document class. What it is doing is exactly what I am doing now. I am writing one page per time to the device context. All is going on fine with that except that there is flickering. To eliminate the flickering I decided to write first to a memory dc. That's where the problem starts from.
OriginalGriff 24-Mar-24 2:53am    
So check the size of the memory block you allocated. Remember that the bitmap is likely to need four bytes per pixel!
What is meant by scrolling in this case is unclear.
I assume that an image is to be drawn that is larger than the window. If the image is not to be scaled to the size of the window, you will only see the part of the image that fits into the window. Window content scrolling can now be realized in different ways. Either everything is on a large bitmap and a section of it is blitted into the visible window, or the section to be displayed is generated from the data.
In either case, you may of course only use memory that belongs to you. If it is not possible to request a sufficiently large memory "for everything" from the system, the only option is to calculate which data is visible and which is not. You only really need memory for the visible data.
 
Share this answer
 
v2
Comments
Gbenbam 23-Mar-24 12:30pm    
Okay, say I have a sixty page document with images, lines . ellipses , text all drawn by my app. If I want to view page 60, I will have to scroll down. There is no way the memory dc bitmap can reasonably be as large as the sixty page document if each page is A4 paper size.

Do you mind giving me an example of calculating which data is visible?
merano99 23-Mar-24 15:07pm    
It would probably be better if you discussed your problem based on your current source code, e.g. a link. Without knowing exactly how your data is currently displayed, but based on the requirement that it should be based on Win32, the article Custom Controls in Win32 API: Scrolling by Martin Mitáš would be a possible starting point. There is the "Advanced scrolling example".

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