Files
MsAddIns/ShrlAlgo.MsAddIns/Views/CustomToolSettings.xaml.cs
2026-02-28 21:01:57 +08:00

66 lines
1.9 KiB
C#

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Bentley.ResourceManagement;
namespace ShrlAlgo.MsAddins.Views
{
/// <summary>
/// CustomTool.xaml 的交互逻辑
/// </summary>
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);
}
/// <summary>
/// 根据缩放比重新调整控件大小
/// </summary>
public new void AdjustWidthAndHeight()
{
double dipScale = GetDipScale();
Width *= dipScale;
Height *= dipScale;
}
/// <summary>
/// 获取显示器缩放比
/// </summary>
/// <returns></returns>
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;
}
}
}