将滚动命令发送到其他应用程序 [英] Sending scroll command to different application

查看:247
本文介绍了将滚动命令发送到其他应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个软件,该软件应该向另一个应用程序发送尽可能平滑的滚动命令.该目标应用程序投影在屏幕上,大量的人将阅读文本,然后滚动.
我的目标是不必一直坐着并用鼠标手动滚动,而不必使自动滚动更加流畅和一致.我所知道的最平滑的滚动是在按下提供箭头组图标的中间按钮,然后将鼠标向下平移时进行的.然后在像素级别上向下滚动,并且每行使用鼠标滚轮(不是选项).

该应用程序在单击后等待几秒钟,然后获取活动窗口的hWnd并将信号发送给它.

这是我的代码的一部分,无效.这是VB 6代码,但是这个问题应该适用于Windows环境中使用的几乎所有编程语言.
要使其正常工作,需要更改/添加哪些内容?
我为其他想法而感到高兴,希望它可以平滑地滚动...

I''m in the making of a software which should send a smoothest possible scrolling command to another application. This target application is projected on a screen and loads of people will be reading text which is then scrolling.
My goal is to not have to constantly sit and manually scroll with the mouse, and to have the automatic scrolling more smooth and consistent. The smoothest scrolling I know is made when pushing the middle button which gives the arrow group icon and then panning the mouse down below. Scrolling is down on pixel level then, and using the mouse wheel (not an option) is per line.

The application waits a couple of seconds after a click, then grabs the hWnd of the active window and sends the signals to it.

Here''s an extract of my code, which doesn''t work. This is VB 6 code, but the question should be applicable in almost any programming language used in the windows environment.
What needs to be changed/added for it to work?
I''m more than happy for other ideas for a smooth scrolling...

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal Wparam As Long, ByRef Lparam As Any) As Long

Public Declare Function GetForegroundWindow Lib "user32" () As Long

Public Const WM_VSCROLL As Integer = &H115
Public Const SB_THUMBPOSITION = 4
Public Const SB_THUMBTRACK = 5
Public Const SB_ENDSCROLL = 8
Public Const WM_MOUSEWHEEL = &H20A ''Works but not used...

Private Sub Send_Click()
  Dim lCurHwnd As Long
  Dim lResult As Long
  
  '' Wait 2 seconds and then grab window
  Sleep 2000
  lCurHwnd = GetForegroundWindow

  ''This works but is undesired:
  ''SendMessage lCurHwnd, WM_MOUSEWHEEL, WHEEL_DELTA * &H10000, 50

  lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBPOSITION, 100), 0)
  Sleep 1000
  lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 300), 0)
  Sleep 1000
  lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 400), 0)
  Sleep 1000
  lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 500), 0)
  Sleep 1000
  lResult = SendMessage(lCurHwnd, WM_VSCROLL, SB_ENDSCROLL, 0)
End Sub



我想我什至可能会偏离轨道...很难弄清楚发送中键单击的真正正确方法是哪种方法,它可以进行4向平滑平移滚动.我开始认为SB_THUMBTRACK与我的目标相去甚远...


现在,我进行了更多的实验,发现我可能会像这样逃脱:
(现在为C代码)



I think I might even be way off track... Having a hard time to figure out what''s really the right way to send the middle-button clicks which engages the 4-way smooth pan-scrolling. I''m starting to think SB_THUMBTRACK is far off from my goal...


I have now experimented a little more and found out I may get away with somehting like this:
(C code now)

int APIENTRY WinMain(....blabla..)
  HWND hwnd;
  char buf[BUF_LEN];
  int i;

  Sleep(2000);
  hwnd = GetForegroundWindow();
  GetWindowText(hwnd, buf, BUF_LEN);
  OutputDebugString(buf);
  OutputDebugString("\n");
    
  for (i=0; i<100; i++)
  {
    ScrollWindow(hwnd, 0, 1, (RECT*) NULL, (RECT*) NULL);
    UpdateWindow(hwnd);
    Sleep(50);
  }



但是,这会将滚动命令发送到鼠标下方的主窗口,这将导致文件"菜单以及顶部的其他所有内容在标题栏下方消失.刷新不能解决此问题.我需要保留需要滚动的客户端部分的hWnd,并且该鼠标在鼠标的下面.如何?



Yet this sends the scrolling commands to the main window under the mouse, which causes the "File" menu and everything else at the top to disappear under the title bar. A refresh doesn''t fix this. I need to get a hold of the hWnd of the client part which needs to be scrolled, and is under the mouse... How?

推荐答案

您可以使用 FindWindowEx [ GetNextWindow [
You can use FindWindowEx[^] to find the main window by class name and/or text. Then you can use GetNextWindow[^] to iterate throught the child controls until you get to the control (window) you want to send scroll commands to. Spy++ is an excellent tool to use to help debug such a task.


这篇关于将滚动命令发送到其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆