Solved

scrolling with SendMessage or PostMessage

Posted on 2001-06-29
8
1,858 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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