C# 告诉一个单独的窗口滚动

C# 告诉一个单独的窗口滚动,c#,windows,winforms,winapi,C#,Windows,Winforms,Winapi,我需要能够以编程方式上下滚动一个窗口,只要屏幕上有一个点。我已经设法使用Windows API检索句柄,但无法使其向上或向下滚动 假设以下代码: //retrieves the correct window. IntPtr hWnd = Win32.WindowFromPoint(new Point(xPos, yPos)); Win32.Rect rect = default(Win32.Rect); //retrieves a rectangle with the desir

我需要能够以编程方式上下滚动一个窗口,只要屏幕上有一个点。我已经设法使用Windows API检索句柄,但无法使其向上或向下滚动

假设以下代码:

//retrieves the correct window.
IntPtr      hWnd = Win32.WindowFromPoint(new Point(xPos, yPos));

Win32.Rect  rect = default(Win32.Rect);

//retrieves a rectangle with the desired windows dimensions 
Win32.GetWindowRect(hWnd, ref rect);

//Insert scroll code here...

要滚动窗口,您需要通过调用带有相应参数的
SendMessage
向其发送windows消息-有关滚动和相关消息等的完整详细信息,请参阅

更新-根据评论:

另一个选项可能是调用
hWnd
-根据注释,不应使用调用
ScrollwindowEx
,因为这会在显示状态和相应窗口的内部状态之间产生不一致

您是否尝试过将函数与和消息一起使用


同时检查(Pinvoke版本)。即使是帖子也可能对你有所帮助

绝对不想使用ScrollWindowEx;这可能会在屏幕上移动位,但底层控件仍将保持原来的状态(因为其内部状态不会更改),这会给用户带来很大的混乱!建议不要使用SetScrollInfo;这是控件内部用于更新滚动条位置的内容,但它不会影响控件的内部状态,相反,最终会导致滚动条与视觉效果不同步。WM_H/VSCROLL是你最好的选择。你提供的帖子实际上提供了正确的解决方案。