szukalem szukale i znalazlem ale nie wiem dlaczego nie dziala :(
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public enum WMessages : int
{
WM_LBUTTONDOWN = 0x201, //Left mousebutton down
WM_LBUTTONUP = 0x202, //Left mousebutton up
WM_LBUTTONDBLCLK = 0x203, //Left mousebutton doubleclick
WM_RBUTTONDOWN = 0x204, //Right mousebutton down
WM_RBUTTONUP = 0x205, //Right mousebutton up
WM_RBUTTONDBLCLK = 0x206, //Right mousebutton doubleclick
WM_KEYDOWN = 0x100, //Key down
WM_KEYUP = 0x101, //Key up
}
private void button1_Click(object sender, EventArgs e)
{
if (PositionX.Text.Length > 0 && PositionY.Text.Length > 0 && WinowsName.Text.Length > 0)
{
int x = Convert.ToInt16(PositionX.Text);
int y = Convert.ToInt16(PositionY.Text);
ControlClickWindow(WinowsName.Text, "left", x,y, false);
}
}
public void _SendMessage(IntPtr handle, int Msg, int wParam, int lParam)
{
IntPtr test = SendMessage(handle, Msg, wParam, lParam);
button1.Text = test.ToString();// wynik 0
}
public int MakeLParam(int LoWord, int HiWord)
{
return ((HiWord << 16) | (LoWord & 0xffff));
}
public IntPtr FindWindow(string wndName)
{
return FindWindow(null, wndName);
}
public void ControlClickWindow(string wndName, string button, int x, int y, bool doubleklick)
{
IntPtr hWnd = FindWindow(null, wndName);
//button1.Text = hWnd.ToString();
int LParam = MakeLParam(x, y);
//button1.Text = LParam.ToString();
int btnDown = 0;
int btnUp = 0;
if (button == "left")
{
btnDown = (int)WMessages.WM_LBUTTONDOWN;
btnUp = (int)WMessages.WM_LBUTTONUP;
}
if (button == "right")
{
btnDown = (int)WMessages.WM_RBUTTONDOWN;
btnUp = (int)WMessages.WM_RBUTTONUP;
}
if (doubleklick == true)
{
_SendMessage(hWnd, btnDown, 0, LParam);
_SendMessage(hWnd, btnUp, 0, LParam);
_SendMessage(hWnd, btnDown, 0, LParam);
_SendMessage(hWnd, btnUp, 0, LParam);
}
if (doubleklick == false)
{
_SendMessage(hWnd, btnDown, 0, LParam);
_SendMessage(hWnd, btnUp, 0, LParam);
}
}
prosze o pomoc
po wpisaniu parametrow zero reakcji
pzdr Andrzej