using System; using System.Drawing; using System.Runtime.InteropServices; using Bentley.ResourceManagement; namespace ShrlAlgo.MsAddins.Views { /// /// CustomTool.xaml 的交互逻辑 /// public partial class CustomToolSettings : Bentley.MstnPlatformNET.WPF.ToolSettingsHost { public CustomToolSettings() { InitializeComponent(); } [DllImport("stdmdlbltin.dll", SetLastError = true)] public static extern int mdlNativeWindow_getToolSettingsWindow(out IntPtr windowPp); [DllImport("nativewindow.dll", SetLastError = true)] public static extern int mdlNativeWindow_setSize(IntPtr windowP, int width, int height); public override void Attach(IMatchLifetime addIn) { base.Attach(addIn); // ElementHost.Width = (int)RenderSize.Width; // ElementHost.Height = (int)RenderSize.Height; mdlNativeWindow_getToolSettingsWindow(out IntPtr windowPp); mdlNativeWindow_setSize(windowPp, ElementHost.Width, ElementHost.Height); } /// /// 根据缩放比重新调整控件大小 /// public new void AdjustWidthAndHeight() { double dipScale = GetDipScale(); Width *= dipScale; Height *= dipScale; } /// /// 获取显示器缩放比 /// /// public double GetDipScale() { Graphics g = Graphics.FromHwnd(IntPtr.Zero); double dipScale = 1; switch (g.DpiX) { case 96: dipScale = 1; break; case 120: dipScale = 1.25; break; case 144: dipScale = 1.5; break; case 168: dipScale = 1.75; break; case 192: dipScale = 2; break; } return dipScale; } } }