Link to home
Start Free TrialLog in
Avatar of phantros
phantros

asked on

scrolling with SendMessage or PostMessage

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
Avatar of jhance
jhance

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.
Avatar of ambience
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 .. :)
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(...)
Avatar of phantros

ASKER

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? :)
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey!
anybody here?
Alock this Q since my coments work
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
Force accepted

** Mindphaser - Community Support Moderator **