Is it possible to use SendMessage() to make CScrollView automatically to
modify the horizontal scroll bar position and scroll the client area, just
like an user click arrow button on horizontal scroll?
I just did as follows,
SendMessage(WM_HSCROLL, MAKELONG(SB_LEFT, 0), 0L);
However, it doesn't work.
Please help.
William
It's definitely possible to send WM_HSCROLL/WM_VSCROLL to cause scrolling.
Are you calling SendMessage from a scroll view member function? Because you
are using it unqualified, it amounts to this->SendMessage(). It appears
CScrollView uses those funny non-control scrollbars that you get when you
use the WS_HSCROLL/WS_VSCROLL styles, so your LPARAM is OK. You should use
MAKEWPARAM instead of MAKELONG, but it doesn't matter here.
--
Doug Harrison
Microsoft MVP - Visual C++
Yes. I called SendMessage() from myself-defined member function inside
CMyScrollView.
But from your response, I still don't know the solution if MAKELONG() is not
the problem as I am currently outside my office and can not test that.
Thanks
William
> Thanks Doug.
>
> Yes. I called SendMessage() from myself-defined member function inside
> CMyScrollView.
> But from your response, I still don't know the solution if MAKELONG() is not
> the problem as I am currently outside my office and can not test that.
MAKELONG is not the problem here; it's just preferable to use MAKEWPARAM to
make WPARAM. However, you did say earlier you wanted to simulate clicking
the arrow button, and SB_LEFT is not the way to do it. Try SB_LINELEFT
instead.
I just tried with the following code, but it doesn't work either.
SendMessage(WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), 0L);
However, if I use HWND of the horizontal scroll bar as lParam as follows,
it works.
CScrollBar* pWndCroll = GetScrollBarCtrl( SB_HORZ );
SendMessage(WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0),
(LPARAM )(pWndCroll->m_hWnd) );
So, why doesn't it work with lParam=0 just as MSDN describes about
WM_HSCROLL?
William
Short answer: if GetScrollBarCtrl returns non-NULL, you need to use the
HWND. Long answer: Looking at the WM_HSCROLL handler in CScrollView it
compares the translated LPARAM (pScrollBar) to the value returned by
GetScrollBarCtrl and does nothing if they don't match. Longer answer:
CScrollView::GetScrollBarCtrl appears to return NULL if the view has the
WS_xSCROLL style, and non-NULL if otherwise there is a CSplitterWnd
involved.
--
Jeff Partch [VC++ MVP]
Because your view isn't using the standard scrollbars. I just found this in
the documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFC_CScrollView.asp?frame=true
<q>
Scroll bars can appear in three places relative to a view, as shown in the
following cases:
Standard window-style scroll bars can be set for the view using the
WS_HSCROLL and WS_VSCROLL Windows Styles.
Scroll-bar controls can also be added to the frame containing the view, in
which case the framework forwards WM_HSCROLL and WM_VSCROLL messages from
the frame window to the currently active view.
The framework also forwards scroll messages from a CSplitterWnd splitter
control to the currently active splitter pane (a view). When placed in a
CSplitterWnd with shared scroll bars, a CScrollView object will use the
shared ones rather than creating its own.
</q>
So what I said earlier wasn't entirely correct. You'll have to determine
what type of scrollbar your view is using and construct the message
accordingly.
William