Scrollbars

Started by
4 comments, last by CJ 24 years, 6 months ago
Few questions:

Did you derive your view from CScrollView? (probably a dumb question but I've come to the point at which I no longer assume anything)

Have you stepped through and checked to make sure that the image size settings you passed in are correct?

How does it respond to an attempt to resize?

What method did you use to put the image into the view?

Did you do anything to your CDC (default variable name is pDC) prior to/ during the OnDraw function that might cause your viewing rect to display improperly, such as override OnPrepareDC without passing it through the CScrollView version of OnPrepareDC?

-fel

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
1) Yes it is derived from CScrollView.

2) My OnDraw function looks like:

void CPictureShopView::OnDraw(CDC* pDC)
{
CPictureShopDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// TODO: add draw code for native data here
int ht;
int wh;

ht = pDoc->bmi.bmiHeader.biHeight;

wh = pDoc->bmi.bmiHeader.biWidth;
bmi = pDoc->bmi;
int bitcnt = (int)bmi.bmiHeader.biBitCount;
HDC hdc = ::GetDC(m_hWnd);

SetDIBitsToDevice(hdc,0,0,(DWORD)wh,(DWORD)ht,0,0,0, (WORD)ht,pDoc->bits,(LPBITMAPINFO)&bmi,DIB_RGB_COLORS);

}


Even when I don't pass the imageheight and imagewidth, i.e. Just pass 500 x 500....

By resizing the thing, it resizes normally...

Is there any function I have to use to have it scroll?


------------------
Dance with me......

Generally, no. The point of using CScrollView is to automatically enable scrolling. The thing is, though, that you took over where the program is generally supposed to draw the change in your visible rects (the OnDraw function)

You can attempt to solve this by calling
CScrollView::OnDraw() after your drawing calls. I'm not going to guarantee this is going to work, mostly because generally I avoid using a CScrollView and do the scroll logic myself (I have some really spiffy custom scroll bars I wrote that I prefer to use anyway), so I haven't tried this. For that matter, the way you set your bits there's a really good chance it won't... you might want to attempt to grab the proper (x,y) position that the scrollbar is throwing to you and use it for your source rect settings... with (0,0) it's not surprising it's stuck. Alternatively messing with your dest rect settings might work because MFC generally does clipping for you (woohoo!) Width and Height should just be the real width and height, they have nothing to do with your view rect really. The destination logic is probably easier, try using negative dest values and see what happens first, provided the OnDraw call doesn't work.
If that call to OnDraw and the extra logic for your rects does not work, then you're going to have to override the OnVScroll and OnHScroll functions yourself (don't forget to put in the proper message handlers up top) Also note that if you're going to do overrides on those there's really no point in deriving from CScrollView, you might just want to derive from CView and get it over with.

As for any extra functions? Nope, that should work if you can resolve your CDC issues.

-fel

~(To a coworker) "I said there's nothing you can't do in MFC. I did not say it would be easy."~

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Sorry, ain't working *pouts*

Could you, maybe please etc etc explain how to make your own scrollbars??

------------------
Dance with me......

Hi, I've got a problem with implementing scrollbars into my Multiple Document MFC program. I need the scrollbar in the child frame. That's where i get it after having changed the CView into CScrollView and using SetScrollSize int he following manner

SetScrollSizes(MM_TEXT, CSize(ImageWidth,ImageHeight));

My Draw function shows an image into the document.

I tried different ways of getting it moving, but none is working. The scrollbar keeps at the same place and only the left top of the image is shown.

If anyone of you knows how to do ths, I would appreciate it, thank you.

------------------
Dance with me......

You probably don't want to make your own scrollbars. I do it because I want them to do super spiffy stuff like internal resizing of the view.

You need to override OnHScroll and OnVScroll and define your viewing rects in that way. If you want I could take a look at it when I get home, icq or e-mail me if so (icq is preferable). You could also go take a look at www.codeguru.com to find instructions on using scroll bar overrides.

-fel

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement