先看效果,,为了达到更好的交互效果,我们自动化程序进行位置和大小调整时需要使得微信窗口也同步更新,以达到看上去一个整体效果。
依然是继承BaseMonitor类
实现思路是自动化程序的位置和大小改变事件中触发微信位置和大小的改变。
namespace OnlineRetailers.Extension.WXAuto.UIAuto.Monitor
{
///
/// 窗体大小或者位置调整改变
///
public class Form_Move_Monitor: BaseMonitor
{
public Window Window { get; set; }
public override void Monitor()
{
MonitorStatus = MonitorStatus.Monitoring;
SystemLog.Info("启动窗体移动同步微信移动监控");
Window.SizeChanged += Form_SizeChanged;
Window.LocationChanged += Form_LocationChanged;
}
private void Form_LocationChanged(object sender, EventArgs e)
{
if (MonitorStatus == MonitorStatus.Monitoring)
{
var id = WXWin32.GetWeiXin();
if (id != IntPtr.Zero)
{
Win32_Move_Window.Do(id,
(int)(SysTransform.TransformToPx(this.Window.Left) + MovePYUnit.Margin),
(int)SysTransform.TransformToPx(this.Window.Top) + MovePYUnit.WXTop + MovePYUnit.Margin);
SetShadow();
}
}
}
private void Form_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (MonitorStatus == MonitorStatus.Monitoring)
{
var id = WXWin32.GetWeiXin();
if (id != IntPtr.Zero)
{
Win32_SizeChange_Window.Do(id,
(int)(SysTransform.TransformToPx( this.Window.Width )- MovePYUnit.OpertionAreaWidth- MovePYUnit.Margin),
(int)SysTransform.TransformToPx(this.Window.Height )- MovePYUnit.WindowTop- MovePYUnit.BottomMargin);
}
}
}
public override void Break()
{
SystemLog.Info("关闭窗体移动同步微信移动监控");
Window.SizeChanged -= Form_SizeChanged;
Window.LocationChanged -= Form_LocationChanged;
ExecuteMonitorStop();
}
}
}
调用
public MainWindow()
{
Form_Move_Monitor windowMove = new Form_Move_Monitor();
windowMove.Window = this;
windowMove.Monitor();
}
(10)微信UI自动化-跟随微信窗口移动(C#)
(11)微信UI自动化-微信窗口跟随主窗体移动(C#)
因为文章所表达的意思可能无法满足每一位阅读需求,需要源码或者支持请联系作者QQ 978124155