Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

scrolling with SendMessage or PostMessage

Posted on 2001-06-29
8
Medium Priority
?
1,951 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

671 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