C# Click and drag or use mouse scroll (Postmessage/Sendmessage)

Asked

Viewed 97 times

-1

I’m 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 scrolling), tried in several ways but could not. I also could not use the WM_MOUSEWHEEEL 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 of the window and use mouse scrolling. Please, could you help me?

public class Win32
{
    // The WM_COMMAND message is sent when the user selects a command item from 
    // a menu, when a control sends a notification message to its parent window, 
    // or when an accelerator keystroke is translated.
    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();
}
  • Please next time serach about that: https://stackoverflow.com/questions/6716275/how-do-i-set-the-position-of-the-mouse-cursor-from-a-console-app-in-c

  • As an example of the code I posted, I am Working in a specific window, taking the Handle from it and Triggering the click, I tried to use [DllImport("user32.dll")]
 static extern bool SetCursorPos(int hWnd, int X, int Y);

 public static void SetCursorPosition(int hWnd, int x, int y)
 {
 SetCursorPos(hWnd, x, y);
 }
Win32.SetCursorPosition((int)WinHandle, 350, 240); unsuccessful, any idea how to work?

  • @Integer u can help me? Please!

  • Some controls need to be focused to interpret windows messages, otherwise it simply discards the message.

1 answer

0

I don’t quite understand the problem, but if what you need is something in which specific areas of your console need to have idenpenedente scroll, then maybe you have a project that can help you

inserir a descrição da imagem aqui

This creates some components that can be used in projects whose proposal is to create an application-console: https://github.com/goblinfactory/konsole

And for independent scroll creation it uses buffer so it can emulate scroll behavior.

public void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop)
{
    int xOffset = targetLeft - sourceLeft;
    int yOffset = targetTop - sourceTop;

    var direction = GetDirection(xOffset, yOffset);

    switch (direction)
    {
        case Direction.Down:
            ScrollDown(-yOffset, sourceLeft, sourceTop, sourceWidth, sourceHeight);
            break;
        default:
            throw new NotSupportedException("No other direction other than scrolling Down is currently supported. Please wait for next major release.");
    }
}
  • It is not in a console window that I need to use scroll, it is in a specific application through the Handle.

  • It is not in the console application that I need to use the mouse scroll, it is in a specific window through the Handle.

  • Maybe https://stackoverflow.com/a/15335557/3263616 This link will help you!

  • What should I search to learn how to make these square/rectangular windows in console application?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.