Solved

scrolling with SendMessage or PostMessage

Posted on 2001-06-29
8
1,582 Views
Last Modified: 2013-11-20
I'm new to MFC and am making a simple CHtmlView based application which navigates to an HTML page with Navigate2().  The user can then click through to view other pages.  I am trying to make it so that the application will automatically scroll down a page being shown every time a timer event triggers.  I added a timer, and in CAppView::OnTimer I added the line:

SendMessage(WM_VSCROLL,SB_LINEDOWN);

However, this does nothing.  (the timer works, it's not the problem)

I've tried other functions, including PostMessage (same effect as SendMessage) and ScrollWindow() (the window scrolled but in a very useless and strange way)

I think SendMessage or PostMessage is the way to go, but I seem to be doing something wrong.  If you can provide any insight, or an alternative method, I'd really appreciate it.

Thanks,
  Phantros
0
Comment
Question by:phantros
8 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6239719
One thing to note, you certainly don't want to use SendMessage in your message handler to send a message to yourself.  That's a sure fire way to mess things up.

But the real difficulty here is that the WM_VSCROLL message itself doesn't really do anything.  Whatever window procedure that receives it must act appropriately on it.  In your MFC app, you want to define a handler for it, and then code the handler to scroll whatever it is you want to scroll when the message comes in.

While there are many ways of doing this, you probably want to use the CHtmlView::ScrollToPosition() member function in your handler for the message to get it scrolled to the desired location.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6240291
CHtmlView is derived from CFormView which derives from CScrollView and CScrollView has default implementaion for WM_HSCROLL and WM_VSROLL handlers, you dont need to add an explicit handler for these messages in that case.

Ever wonder how does HTML view manage to show all contents by scrolling without even a handler specified , this is due to CScrollView base.

The problem is with
SendMessage(WM_VSCROLL,SB_LINEDOWN);

For WM_VSCROLL

nScrollCode = (int)LOWORD(wParam);
nPos = (short int)HIWORD(wParam);

hwndScrollBar = (HWND) lParam;

does that help analyze what has been done wrong, i recommend you directly call OnScroll() and not SendMessage or ScrollWindow.

hope this helps .. :)
0
 
LVL 22

Expert Comment

by:ambience
ID: 6240292
incase you didnot get it , you need to pack up the scrollcode , scrollpos and handle in the WPARAM and LPARAM in SendMessage call , for the handler in CScrollView to work properly.

Better way is to call directly OnScroll(...)
0
 

Author Comment

by:phantros
ID: 6240348
Thanks guys, so far no luck though.

jhance: Actually, I've tried ScrollToPosition().  It just crashes when it reaches the line...for example:
     CPoint pt(0,0);
     ScrollToPosition(pt);
In fact, just trying to find where the scrollbar is crashes it, with a line like this:
     CPoint pt = GetScrollPosition();

ambience: I've tried OnScroll() and OnVScroll() and nothing seems to happen...

     OnScroll(SB_LINEDOWN,GetScrollPos(SB_VERT));
or
     OnVScroll(SB_LINEDOWN,GetScrollPos(SB_VERT),GetScrollBarCtrl(SB_VERT));


Maybe I should clarify what I've done a little bit.  Here are directions to duplicate it:
I created a new MFC Appwizard(exe) app called Mfcpractice, chose single document, got rid of activex controls support, and chose CHtmlView for a base class.  The other options I left the same.

In CMfcpracticeView::OnInitialUpdate() I changed the Navigate2 line...
     Navigate2(_T("C:\\My Documents\\index1.html"),NULL,NULL);
This is a simple HTML page long enough for me to test the scrolling with.

I added a command to the menu to start the scrolling, and this code:

void CMfcpracticeView::OnToolsAutomaticscrollingBegin()
{
     // TODO: Add your command handler code here
     SetTimer(1,1000,NULL);
}

I added a handler for OnTimer().  That is where I'm trying to do the scrolling.

I think what's keeping some of these things from working is that I'm not using SetScrollSizes() in OnDraw() and then drawing the stuff myself.  I'm instead getting the data with Navigate2().  It doesn't seem like I should have to draw the HTML code myself just to get it to scroll properly though.

What should I try next, or what did I do wrong with what I've tried so far? :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Accepted Solution

by:
migel earned 200 total points
ID: 6305802
Hi!
You send message to the wrong window:
here is code:
// I handle two commands ScrollTop And Scroll bottom
// I think that code clear enough to resolve your problem.
void CMfcieView::OnScrollTop()
{
     // TODO: Add your command handler code here
     char szText[80] = "";
     
     HWND hwndChild = m_hWnd; //::GetWindow(m_hWnd, GW_CHILD);
     while (hwndChild)
     {
          ::GetClassName(hwndChild, szText, 80);
          if (!stricmp("Internet Explorer_Server", szText))
               break;
          hwndChild = ::GetWindow(hwndChild, GW_CHILD);
     }
     if (hwndChild)
     {
          ::SendMessage(hwndChild, WM_VSCROLL, MAKELPARAM(SB_LINEUP, 0), NULL);
     }
}

void CMfcieView::OnScrollBottom()
{
     // TODO: Add your command handler code here
     char szText[80] = "";

     HWND hwndChild = m_hWnd; //::GetWindow(m_hWnd, GW_CHILD);
     while (hwndChild)
          {
          ::GetClassName(hwndChild, szText, 80);
          if (!stricmp("Internet Explorer_Server", szText))
               break;
          hwndChild = ::GetWindow(hwndChild, GW_CHILD);
          }
     if (hwndChild)
          {
          ::SendMessage(hwndChild, WM_VSCROLL, MAKELPARAM(SB_LINEDOWN, 0), NULL);
          }
}
0
 
LVL 12

Expert Comment

by:migel
ID: 6358394
Hey!
anybody here?
Alock this Q since my coments work
0
 
LVL 11

Expert Comment

by:griessh
ID: 7202176
Unless there is objection or further activity,  I will suggest to accept

     "migel"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7220557
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now