C# Click and drag or Mouse Wheel with PostMessage / SendMessage

China☆狼群 提交于 2021-02-05 09:42:40

问题


I am creating a CONSOLE application, I need to scroll a certain part of the window from positions (x = 350, y = 240) to (x = 350, y = 120) (vertical scroll), I tried different ways but I couldn't. I was also unable to use the WM_MOUSEWHEEL option. Follow the code I use for clicks that work perfectly, I just need to adapt it to click and drag or determine a Y point on the window and use the mouse scroll. Could you please help me? Sorry for bad English, I used a translator.

public class Win32
{
    public const int WM_KEYDOWN = 0x100;
    public const int WM_KEYUP = 0x101;
    public const int WM_COMMAND = 0x111;
    public const int WM_LBUTTONDOWN = 0x201;
    public const int WM_LBUTTONUP = 0x202;
    public const int WM_LBUTTONDBLCLK = 0x203;
    public const int WM_RBUTTONDOWN = 0x204;
    public const int WM_RBUTTONUP = 0x205;
    public const int WM_RBUTTONDBLCLK = 0x206;

    [DllImport("User32.dll")]
    public static extern Int32 PostMessage(int hWnd, int Msg, int wParam, IntPtr lParam);

}

static void Main(string[] args)
{
    IntPtr WinHandle = User32.FindWindow(null, "My Window");

    Win32.PostMessage((int)WinHandle, Win32.WM_LBUTTONDOWN, 0x00000001, CreateLParam(350, 240));
    Thread.Sleep(100);
    Win32.PostMessage((int)WinHandle, Win32.WM_LBUTTONUP, 0x00000000, CreateLParam(350, 120));
    Console.Write("Done");
    Console.ReadKey();
}

来源:https://stackoverflow.com/questions/62488594/c-sharp-click-and-drag-or-mouse-wheel-with-postmessage-sendmessage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!