Word-like background

How do I get a view that looks like that provided by
Microsoft Word.
There you write on a nice white sheet of paper in front
of a gray background.
The Visual C++ document-/view architecture offers a view
with its origin in the upper left corner of the parent
window. What is the best (preferred) way to move the
point (0,0) a bit down and to the left, and how do I get
the gray background.
I tried to change the x and y elements of CREATESTRUCT
within the PreCreateWindow of my ScrollView, but it
somehow didn't work!?
Another way might be painting the whole thing
(OnEraseBkgnd with a white Rectangle over it, shifting
the ViewportOrg), but this seems to be a bit primitive!
So, how do they do it at Microsoft?
LewisAsked:
Who is Participating?
 
RONSLOWConnect With a Mentor Commented:
There is no built-in support in Windows for a white drawing page with grey surrounds - it's up to you to paint it that way.

You fill the area around your "page" with the grey background color (use ::GetSysColor(COLOR_APPWORKSPACE) to find out the color).  You fill the "page: itself with the white color (use ::GetSysColor(COLOR_WINDOW) for this). The draw your text/graphics over this.

CScrollView has a routine (FillOutsideRect()) for filling outside the page you define - you can use this in your OnEraseBkgnd to do the grey background - but you still need to paint the inside of the page white (as above).

Of course, for smooth appearance, you would use an off-screen bitmap (ie. create a dc for the bitmap, draw inot it, then BitBlt it onto the view). You would also only redraw the rectangle which needs it (use GetClipBox()).

Let me know if you require any further details on this.

0
 
LewisAuthor Commented:
Could you provide the exact code necassary?
What functions are affected (OnEraseBkgnd, OnDraw,...)?
How to move (0,0) so that future drawing commands will
not have to worry about any offsets?

Apart from that, could you explain the last paragraph
(off-screen bitmap) more closely?
0
 
RONSLOWCommented:
I'll check for sample code for you - it'd be tricky sending you my own code becuase of all the other things that happen would confuse the issue - but I'm sure I can find a smaple that shows you how to use FillOutsideRect within OnEraseBkgrnd (check the on-line help for FillOutsideRect for a starting point).

OnDraw should fill the area in which your page is defined ([0,0]..[maxx,maxy]) with the current window colour then draw your other stuff on top.  OnEraseBkgrnd should fill outside the rect with the appworkspace color.  You can use SetWindowExt,SetViewportExt etc function with MM_ANISOTROPIC to define how your logical page space maps onto the client area (pixels) of the window.

I will try to send you some code on off-screen bitmaps.  The idea is that in your OnDraw you create a compatible bitmap (using the size of the GetClipBox to limit it if you want).  You create a DC and select the bitmap into it, the do your drawing into THAT dc instead of the one passed into OnDraw.  When finished, flush the GDI and use BitBlt to copy from the bitmap dc onto the view dc in one hit, avoiding any flicker.

Anyway, I'll see what I can dig out for you - okease give me your eMail address as it is very tricky posting long code smaples here (I can eMail you a ZIP instead).

0
 
LewisAuthor Commented:
Hi,
did you dig out anything for me? Sorry for asking again,
but I have a deadline to meet in three weeks.
Lewis
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.