15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CScrollView::OnDraw override

Eric J.A. Bryant -- ejab@village.ios.com
Tuesday, August 13, 1996

Environment: VC++4.1/Win95

Hello all,
I am stumped with the CScrollView :: OnDraw override. I am simply trying
to output text to the screen (a raw LPSTR buffer -- not lines of text,
with '\n's only between paragraphs), using CScrollView as the base for my
SDI View. Yet the scrolling does not work properly, here is an abstract:

CScrollView::OnDraw(CDC *pDC)
{

CFont * prevFont = pDC->SelectObject(d_pFont);

CRect rect;
pDC->GetClipBox( &rect );
pDC->LPtoDP( &rect );

uiStyles = DT_WORDWRAP | ...
if ( d_lpTextBuffer )
	pDC->DrawText(d_lpTextBuffer, -1, rect, 
					uiStyle);
pDC->SelectObject(prevFont);
}

Now, am I not understanding the concept or should this work (don't answer
that)? What happens is that when I scroll up or down I get a ghost image
of the first line, overwriting the rest of the text -- the following
abstract is how the window looks with I scroll up twice:

	Top Line
	Top Line
	Top Line
	This is the fourth line

I've look everywhere for some reuse code or KB answers and I've come up
short. 

Thanks is advance.

Eric J. Bryant
MSKCC



Jeff Moss -- jeff.moss@gtri.gatech.edu
Wednesday, August 14, 1996

[Mini-digest: 5 responses]

>Now, am I not understanding the concept or should this work (don't answer
>that)? What happens is that when I scroll up or down I get a ghost image
>of the first line, overwriting the rest of the text -- the following
>abstract is how the window looks with I scroll up twice:
>
>	Top Line
>	Top Line
>	Top Line
>	This is the fourth line

You can try adjusting the viewport origin in your OnDraw() function using
this code as an example:

   static POINT pt;
   pt = GetScrollPosition();
   dc.SetViewportOrg(0, -pt.y);  // for vertical scrolling
   rect.bottom += pt.y;          // from your clipping rectangle


MOSS, JEFFREY N --- Research Scientist
ITL/CSITD 
Georgia Tech Research Institute
Georgia Institute of Technology
Atlanta Georgia, 30332

jeff.moss@gtri.gatech.edu

(404) 894-5959 (voice)
(404) 894-7080 (fax)

-----From: Danny Lauwers 

These are some ideas, just try them out...

1) you use GetClipBox to get the rect you use in the drawtext. The rect that
is returned is that part of the window that needs to be updated, and only
inside this clipbox rect you can draw, everything else is not.
2) CScrollView changes its origin, you can retrieve this by the
GetScrollPosition() function. This function will tell you that you have
scrolled 10 pixels by 20 pixels for example.
3) The ondraw you have made always redraws everything, but on the wrong
place. To test things, you just replace the rect of the DrawText function by
the complete size of your CScrollView. You must have set the Scroll ranges
of the ScrollView somewhere in the initialization. If you then scroll, the
origin of the ScrollView changes. This takes care of the correct position of
your text. The ClipBox takes care of the unwanted visual redraws of your text.
4) To make thinks faster and smarter, you could check the ClipBox and only
draw the text in that region. For this to happen you must to some
calculations of what line must be updated and give the correct string and
rect to the DrawText function.
5) If this is pure text, why not take a CRichEditCtrl or CEdit (<=64K) to do
the job ?

Hope this information help a bit !
Greetings
Danny Lauwers

==============================================================================
Ing. Danny Lauwers (dlauwers@innet.be) 
Intersoft Electronics		        Radar verification Hard- & software
Lammerdries 27			       	Fotofinish and timing of sportevents
2250 Olen Belgium Europe	        Footscan applications
Tel: +32 14 231811			and more ...
Fax: +32 14 231944			Checkout http://www.innet.be/intersoft
===============================================================================

-----From: "Bikkula, Ravi" 


Hey,
 For text scrolling there is an excellent class
CRowView in InsideVisualC++ book and also in check book
application.I have wrtten a scrollview for an application which
continuosly output text onto the screen using CRowView class
I think it gives you the right direction.

Thanx and Regards
...................................................................
Ravi Kumar Bikkula
GE Fanuc Automation
Albany, NY 12203 5189
Ph #  (518) 464-4695
mail :              Bikkula@albpig.cho.ge.com
-----From: "Lee, Benny" 


Eric,

In CScrollView::OnDraw, MFC magic has already modified the CDC's viewport 
origin.  My guess is that you don't need to call 'pDC->LPtoDP( &rect );'

Benny
-----From: "Jeff Pek" 

I'd bet your problem has to do with the DPtoLP call.
CScrollView::OnDraw sets up the logical coordinate system,
so that any CDC call you make can use logical coordinates.

What happens if you take out the LPtoDP call?

HTH - Jeff Pek





| Вернуться в корень Архива |