Hi all. First post here for me.

Just a quick note: I'm not very good in VC++. In fact, I only started using it a few days ago. I have done some C++ coding in the past, but it was quite a while ago. I guess all that qualifies me as a newbie. I searched for similar issues to mine but nothing I found seemed to fit my problem.

On to the point: I'm trying to write a program that will scroll the current window of any* program in response to certain keyboard inputs. Essentially, I want certain keys on the keyboard to have the same** effect as clicking on the scroll bar arrows.

* Actually, it doesn't have to be absolutely any program. Just the standard windows stuff will be enough - IE, Word, Excel, etc.
** It doesn't have to behave exactly like a scroll bar arrows; the number of lines can be different. The important thing is I don't want the cursor (if any) to move, I just want the window to scroll.

I figured I could use SendMessage, but it doesn't seem to work. This is what I'm trying:
Code:
SendMessage(GetForegroundWindow(), WM_HSCROLL, SB_LINERIGHT, 0);
myFile << "Sent message to " << (int)GetForegroundWindow() << " msg = " << WM_HSCROLL  << " wParam = " << SB_LINERIGHT << " lParam = " << 0 << "\r\n";
The second line is just outputting to a logfile so I can be sure the code is getting to that point, which it is.

Here's what I'm seeing in the logfile:
Sent message to 12059976 msg = 276 wParam = 1 lParam = 0
The window handle changes as the current window changes, so it seems to be picking up the current window handle OK. The problem is, every program I've tried this with does nothing. Except MS Publisher, which does something very weird: It doesn't scroll the window contents, but forces the scrollbar all the way to the right where it gets "stuck", and doesn't move in response to clicking the arrows, although the window contents scroll.

This seems to tell me that Publisher is getting some kind of message related to the scroll bars, but is not interpreting it properly. Maybe the other programs are seeing some kind of invalid message as well, but simply ignore it completely?

In the end I have two questions:
What am I doing wrong?
Is SendMessage the best way to scroll windows?