I'm building a little scrolling text box, using the Petzold
book as a guide.
I'm working only on the vertical scroll bar now. I'll add
the horizontal scrollbar when this is working.
I have scroll set to be invisible until needed.
As I add text to be displayed I call SetScrollInfo to update
the nMax value. I'll want the thumb bar to reflect the size
of the data, so SetScrollInfo's Redraw is passed as true.
The problem is that SetScrollInfo() is passing WM_SIZE to
WinProc() with a new smaller width, by 20 pixels, that
reflects the size it would be if the scroll bar is displayed.
But this is when only a couple of lines are displayed and the
scrollbar isn't needed. SetScrollInfo then makes a second
call is then made to WinProc passing a WM_SIZE with a width
that is 20 pixels larger, returning the client area width to
the size it had before I called SetScrollInfo.
This causes me several concerns. First, I didn't
design the code to be recursive. My WM_SIZE processing also
calls SetScrollInfo(), which sounds to me like I may be
looking at some endless recursion trap.
I'm planning on setting a flag when calling SetScrollInfo()
and clearing it upon return, so my WM_SIZE process can decide
if this is a "real" resize.
Is there a better method of dealing with this?
Thanks
Larry
It's pretty hard to know when the "real" WM_SIZE comes in. Also, there
are several other causes of spurious WM_SIZE messages. I've given up on
it and set the scroll info in WM_PAINT instead. When you get that the
size has settled and is available with GetWindowRect or GetClientRect.
--
Scott McPhillips [VC++ MVP]
< Snip >
> It's pretty hard to know when the "real" WM_SIZE comes in. Also, there
> are several other causes of spurious WM_SIZE messages. I've given up on
> it and set the scroll info in WM_PAINT instead. When you get that the
> size has settled and is available with GetWindowRect or GetClientRect.
Thanks Scott:
I'm going to do my resize processing with a call to GetClientRect()
in the WM_PAINT clause, as you suggest.
Do you service the WM_SIZE message in WndProc()?
Larry
Yes, if there are child windows to manage. Moving them around generates
WM_PAINT, and one doesn't want to do that in WM_PAINT (!)