private void button2_Click(object sender, EventArgs e) { IntPtr parentWindow = ZS.Common.Win32.API.FindWindow(null, txtWindowTitleA.Text); if (parentWindow == null || parentWindow == IntPtr.Zero) { AppendText("没有找到父窗口!"); return; } IntPtr childWindow = ZS.Common.Win32.API.FindWindow(null, txtWindowTitleB.Text); if (childWindow == null || childWindow == IntPtr.Zero) { AppendText("没有找到子窗口!"); return; } IntPtr newHWND = ZS.Common.Win32.API.SetParent(childWindow, parentWindow); ZS.Common.Win32.API.RECT rec = new Win32.API.RECT(); ZS.Common.Win32.API.GetWindowRect(parentWindow, ref rec); ZS.Common.Win32.API.MoveWindow(childWindow, 0, 0, rec.right - rec.left, rec.bottom - rec.top, true); AppendText("返回结果:" + newHWND.ToString()); AppendText("处理完成!"); }
private void button8_Click(object sender, EventArgs e) { Win32.API.RECT rec = new Win32.API.RECT(); Win32.API.GetWindowRect(new IntPtr(Int32.Parse(txtWindowHandle.Text)), ref rec); AppendText(rec.ToString()); this.Location = new Point(rec.left, rec.top); this.Size = new Size(rec.right - rec.left, rec.bottom - rec.top); }
// 发送鼠标左键点击- private void button4_Click(object sender, EventArgs e) { if (rbtByHandle.Checked) { IntPtr handle = new IntPtr(Int32.Parse(txtWindowHandle.Text)); // 获取控件的坐标 Win32.API.RECT rec = new Win32.API.RECT(); Win32.API.GetWindowRect(handle, ref rec); Win32.API.SendMessage(handle, Win32.SystemDefinedMessages.WM_LBUTTONDOWN, Win32.SystemDefinedMessages.MK_LBUTTON, rec.left + (rec.top << 16)); //Win32.API.SendMessage(handle, Win32.SystemDefinedMessages.WM_LBUTTONUP,0, rec.left + (rec.top << 16)); } }
private void Ms1_MouseMove(object sender, Win32.Mouse.MouseEventArgs args) { IntPtr parent = new IntPtr(Int32.Parse(txtWindowHandle.Text)); Win32.API.RECT rec = new Win32.API.RECT(); Win32.API.GetWindowRect(parent, ref rec); Win32.API.POINT pt = new Win32.API.POINT(); if (args.X >= rec.left && args.X <= rec.right && args.Y > rec.top && args.Y < rec.bottom) { pt.X = args.X - rec.left; pt.Y = args.Y - rec.top; } IntPtr target = Win32.API.ChildWindowFromPointEx(parent, pt, 0x0000); if (target != IntPtr.Zero) { String txt = Win32.API.GetWindowText(target); AppendText(target + ":" + txt); } }