Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendMessage(WM_HSCROLL,,,)

792 views
Skip to first unread message

William

unread,
Jun 16, 2005, 8:48:59 AM6/16/05
to
Hi,

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


Doug Harrison [MVP]

unread,
Jun 16, 2005, 11:25:42 AM6/16/05
to

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++

William

unread,
Jun 16, 2005, 1:05:44 PM6/16/05
to
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.

Thanks
William

Doug Harrison [MVP]

unread,
Jun 16, 2005, 2:12:32 PM6/16/05
to
On Fri, 17 Jun 2005 02:05:44 +0900, William wrote:

> 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.

William

unread,
Jun 16, 2005, 9:11:37 PM6/16/05
to
Thanks Doug.

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

Jeff Partch [MVP]

unread,
Jun 16, 2005, 9:42:39 PM6/16/05
to
"William" <po...@mx15.freecom.ne.jp> wrote in message
news:uBfhEmtc...@TK2MSFTNGP12.phx.gbl...

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]


Doug Harrison [MVP]

unread,
Jun 16, 2005, 9:50:24 PM6/16/05
to

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

unread,
Jun 16, 2005, 10:15:11 PM6/16/05
to
Thanks Jeff a lot.

William

William

unread,
Jun 16, 2005, 10:43:50 PM6/16/05
to
Thanks Doug very much.
0 new messages