Solved

scrolling with SendMessage or PostMessage

Posted on 2001-06-29
8
1,621 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 140
Separate into files by filename 12 75
sumNumber challenge 16 109
Problem to event 3 76
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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

16 Experts available now in Live!

Get 1:1 Help Now