Hey guys,

I have a window and I would like to attach a vertical scrollbar to it. Simple enough. The window is approximately 300 pixels tall and I have enough content to fill up about 900 pixels. However, this isn't simply text like notepad, but consists of text, buttons, and other child controls.

My question is: How do I go about implementing scrolling on a window that contains child controls? I can only seem to find information on owner drawn client areas that you manually adjust. Is there a way to let the controls do all of their normal drawing but clip them against the viewport?

I tried separating out the scroll bars into another window that acts like a scroll panel and that window then contains the window with all of the real content as a child. I thought I would just draw my child window to an offscreen DC and then blit the proper rectangle off of the DC and into my scroll panel window. The problem is I can't keep my child window from drawing in the scroll panel window. And, even if I completely override WM_PAINT and do nothing, that window's children all still get drawn.

I am going nuts! Does anybody know the proper way to implement something like this? Sheesh, game development is so much easier. :)

- Chris
Posted on 2002-08-27 20:03:26 by bit
Why don't you create a child window inside your main window (no borders) and use the vertical scrollbar offset to move that child window inside the main window?
Posted on 2002-08-27 22:12:49 by comrade
Comrade,

If I am undertanding you correctly your method sounds like what I was doing while trying to bitblt the contents of the child window. Both methods just take into account the offsets. The problem I have with either of these methods is the following:

My main container window (inside a tab control) is something like 500 pixels by 300 pixels. The child window with all of the content is about 500 pixels by 900 pixels. So, when the child draws inside of the main window it chops off my custom border at the bottom of the main window. If I could control when the child's draw happened and bitblt manually, then I could make this work with the offset method you describe. However, just letting the child draw on it's own paints over what I have already drawn and wanted to have displayed in the first place.

I guess what I really need for the above method to work is a way for the child window to be 500 pixels by 800 pixels, but for it to be displayed in the main window at a size of 498 pixels by 298 pixels instead of 500 x 300 (which is the true size of its parent, the main window).

Hope that made sense. Spaciba.

- Chris
Posted on 2002-08-27 22:29:44 by bit
Why are you blitting it manually? Just move the child window with MoveWindow or SetWindowPos and Windows shall take care of the rest.
Posted on 2002-08-27 22:50:47 by comrade
Yeah, I figured out that I couldn't bitblt it manually. I wanted to do it manually so I could write to an offscreen buffer and deal with the scrolling all in one shot.

And, I figured out why my border was disappearing on me. So, I moved the border drawing code into the child window and had it use the size of the parent's client rect after all other drawing has taken place. Kinda' seems like a kludge, but it looks good and works okay.

Anyway, with that border problem fixed I think the scrolling code will work okay. All I have left to do is figure out how to actually obtain the amount to offset by in the child window.

Thanks for your help. It spurred me in the right direction to fixing the problem.

- Chris
Posted on 2002-08-27 23:05:43 by bit