-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
– Integer
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?– Maurício Morhy
@Integer u can help me? Please!
– Maurício Morhy
Some controls need to be focused to interpret windows messages, otherwise it simply discards the message.
– user178974