Skip to content

Commit

Permalink
🪄 Fixed some grammatical errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanchenLin committed Jun 19, 2024
1 parent 55bbcd9 commit 5758ae4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ public static void InitializeDpiManager()
public static int GetDpiForWindow(HWND handle)
{


if (IsPerMonitorV2Awareness)
{
var hMonitor = MonitorFromWindow(handle, MonitorFlags.MONITOR_DEFAULTTONEAREST);

GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var dpiX, out _);
GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_DEFAULT, out var dpiX, out var dpiY);

return (int)dpiX;
return (int)dpiY;
}

return DeviceDpi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override void WndProc(ref Message m)
}
}



base.WndProc(ref m);
}
Expand Down Expand Up @@ -78,29 +78,55 @@ protected void CheckResetDPIAutoScale(bool force = false)
}
}

bool _isPerformDpiChanged = false;

private bool WmDpiChanged(ref Message m)
{
if (_isPerformDpiChanged) return false;

_isPerformDpiChanged = true;

var oldDeviceDpi = _deviceDpi;
var newDeviceDpi = Macros.SignedHIWORD(m.WParam);
var suggestedRect = Marshal.PtrToStructure<RECT>(m.LParam);



if (m.HWnd == (nint)0) return false;

var hWnd = m.HWnd;

ScaleFactor = SystemDpiManager.GetScaleFactorForWindow(hWnd);



_deviceDpi = newDeviceDpi;

var maxSizeState = _targetForm.MaximumSize;
var minSizeState = _targetForm.MinimumSize;
_targetForm.MinimumSize = Size.Empty;
_targetForm.MaximumSize = Size.Empty;

var scaleFactor = (float)newDeviceDpi / oldDeviceDpi;

GetWindowRect(hWnd, out var lpCurrentRect);

//#if NET8_0_OR_GREATER

// if (scaleFactor != 1.0f && lpCurrentRect == suggestedRect)
// {
// suggestedRect.Size = new Size((int)(suggestedRect.Width * scaleFactor), (int)(suggestedRect.Height * scaleFactor));
// }

// System.Diagnostics.Debug.WriteLine($"{scaleFactor} {lpCurrentRect.Location} {lpCurrentRect.Size} -> {suggestedRect.Location} {suggestedRect.Size}");

//#endif



SetWindowPos(hWnd, HWND.NULL, suggestedRect.left, suggestedRect.top, suggestedRect.Width, suggestedRect.Height, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);


var scaleFactor = (float)newDeviceDpi / oldDeviceDpi;

_targetForm.MinimumSize = SystemDpiManager.CalcScaledSize(minSizeState, new SizeF(scaleFactor, scaleFactor));
_targetForm.MaximumSize = SystemDpiManager.CalcScaledSize(maxSizeState, new SizeF(scaleFactor, scaleFactor));
Expand All @@ -115,6 +141,7 @@ private bool WmDpiChanged(ref Message m)

WindowDpiChanged?.Invoke(this, new WindowDpiChangedEventArgs(oldDeviceDpi, newDeviceDpi));

_isPerformDpiChanged = false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace WinFormium.JavaScript;
public static class JavaScriptWindowBindingObjectRegister
{

public static AppBuilder RegsiterWindowBindingObject<T>(this AppBuilder appBuilder, Func<IServiceProvider, T> registerDelegate) where T : JavaScriptWindowBindingObject
public static AppBuilder RegisterWindowBindingObject<T>(this AppBuilder appBuilder, Func<IServiceProvider, T> registerDelegate) where T : JavaScriptWindowBindingObject
{

appBuilder.Services.AddScoped<JavaScriptWindowBindingObject>(registerDelegate);

return appBuilder;
}

public static AppBuilder RegsiterWindowBindingObject<T>(this AppBuilder appBuilder) where T : JavaScriptWindowBindingObject
public static AppBuilder RegisterWindowBindingObject<T>(this AppBuilder appBuilder) where T : JavaScriptWindowBindingObject
{
if(appBuilder.ProcessType == ProcessType.Main)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override ResourceResponse GetResourceResponse(ResourceRequest request)

if (File.Exists(physicalFilePath))
{
response.ContentBody = File.OpenRead(physicalFilePath);
response.ContentBody = File.Open(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //File.OpenRead(physicalFilePath);
response.ContentType = CefRuntime.GetMimeType(Path.GetExtension(physicalFilePath).Trim('.')) ?? "text/plain";
}
else
Expand Down

0 comments on commit 5758ae4

Please sign in to comment.