Skip to content

Commit

Permalink
Merge pull request #326 from XuanchenLin/master
Browse files Browse the repository at this point in the history
👾 修复了一些窗体渲染方面的BUG / 🎉 修复了 Subprocess 示例中 DemoWindow 对象没注册的问题。
  • Loading branch information
XuanchenLin authored Feb 17, 2023
2 parents c60cf96 + 00347b4 commit 6607f84
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 60 deletions.
8 changes: 5 additions & 3 deletions src/Demo/FormiumClient/FormiumClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
<ApplicationIcon>Resources\AppIcon.ico</ApplicationIcon>
<OutputType>WinExe</OutputType>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyName>NanUI Formium Demo Client</AssemblyName>
<PackageId>FormiumClient</PackageId>
<Product>NanUI FormiumClient</Product>
<Product>NanUI Formium Demo Client</Product>
<AssemblyTitle>NanUI 示例程序</AssemblyTitle>
<PackageId>$(AssemblyName)</PackageId>
<AssemblyName>$(AssemblyName)</AssemblyName>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>warnings</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>AnyCPU;x64;x86</Platforms>
<BaseOutputPath>$(BinDir)\$(MSBuildProjectName)\</BaseOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 4 additions & 5 deletions src/Demo/FormiumClient/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ public MainWindow()
// 在此处设置窗体的各种属性

MinimumSize = new Size(720, 480);
Size = new Size(1280, 800);
Size = new Size(1280, 720);

StartPosition = FormStartPosition.CenterScreen;

// Set up settings for BorderlessWindow style.
// 设置 Borderless 样式窗体的各项扩展属性,需要注意泛型T需要对应正确的WindowType
var style = UseExtendedStyles<BorderlessWindowStyle>();
//style.ShadowColor = ColorTranslator.FromHtml("#8B6A91");
//style.InactiveShadowColor = ColorTranslator.FromHtml("#EE3a3a3a");
style.InactiveShadowColor = ColorTranslator.FromHtml("#EE3a3a3a");
style.ShadowColor = ColorTranslator.FromHtml("#EE3a3a3a");
style.ShadowEffect = ShadowEffect.Huge;
style.CornerStyle = CornerStyle.Small;
style.ShadowEffect = ShadowEffect.Big;
style.CornerStyle = CornerStyle.Tiny;

// Set up Splash styles
// 设置启动画面的各种参数
Expand Down Expand Up @@ -120,7 +120,6 @@ protected override void OnReady()
// Register event handler when keyboard is pressed
// 注册按键事件
KeyEvent += MainWindow_KeyEvent;

}


Expand Down
2 changes: 1 addition & 1 deletion src/Demo/FormiumClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void Main()
// Enable single instance mode
// 启用单例
//app.UseSingleInstance((processId) => {
//app.UseSingleInstance((processId) => {
// // processId - 为已在运行中的进程实例ID
// // processId - The Id of the running instance
//});
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions src/Demo/FormiumClient/StartupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public StartupWindow()
AllowFullScreen = false;
EnableSplashScreen = false;
AllowSystemMenu = false;

//var style = UseExtendedStyles<BorderlessWindowStyle>();

//style.ShadowEffect = ShadowEffect.Glow;
//style.CornerStyle = CornerStyle.Tiny;

}

protected override void OnReady()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace FormiumClient;

internal class DemoWindowBinding : JavaScriptWindowBindingObject
public class DemoWindowBinding : JavaScriptWindowBindingObject
{
public override string Name { get; } = "Example/DemoWindow";
public override string JavaScriptCode { get; } = Properties.Resources.DemoWindowBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<BaseOutputPath>$(BinDir)\FormiumClient</BaseOutputPath>
<AssemblyName>$(AssemblyName)</AssemblyName>
<Product>NanUI Formium Demo Subprocess</Product>
<AssemblyTitle>NanUI 示例程序子进程</AssemblyTitle>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>AppIcon.ico</ApplicationIcon>
<StartupObject>FormiumClientSubprocess.Program</StartupObject>
<UseWindowsForms>True</UseWindowsForms>

<BaseOutputPath>$(BinDir)\FormiumClient</BaseOutputPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,6 +30,7 @@

<ItemGroup>
<ProjectReference Include="..\..\NetDimension.NanUI\NetDimension.NanUI.csproj" />
<ProjectReference Include="..\FormiumClient\FormiumClient.csproj" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/Demo/FormiumClientSubprocess/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal static class Program
[STAThread]
static void Main()
{
WinFormium.CreateRuntimeBuilder(app => { }).Build().RunAsSubprocess();
WinFormium.CreateRuntimeBuilder(app => {
app.RegisterJavaScriptWindowBinding(() => new FormiumClient.DemoWindowBinding());
}).Build().RunAsSubprocess();
}
}
12 changes: 3 additions & 9 deletions src/NetDimension.NanUI/Formium/Formium.Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ partial class Formium

internal void CreateBrowser()
{
var browserSettings = OnCreateBrowserSettings();


if (browserSettings == null)
{
browserSettings = WinFormium.DefaultBrowserSettings;
}

WebView = new FormiumWebView(this, browserSettings, StartUrl);
WebView = new FormiumWebView(this, _browserSettings, StartUrl);

WindowInfo = CefWindowInfo.Create();

Expand Down Expand Up @@ -342,7 +336,7 @@ internal void ResizeWebView()
}
else
{

if (IsWindowVisible(HostWindowHandle))
{
SetWindowPos(BrowserWindowHandle, HWND.NULL, 0, 0, rect.Width, rect.Height, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_SHOWWINDOW | SetWindowPosFlags.SWP_NOACTIVATE);
Expand Down Expand Up @@ -523,7 +517,7 @@ public void Reload(bool forceReload = false)
}

/// <summary>
/// Load page from the
/// Load page from the
/// </summary>
/// <param name="url"></param>
public void LoadUrl(string url)
Expand Down
36 changes: 34 additions & 2 deletions src/NetDimension.NanUI/Formium/Formium.HostWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NetDimension.NanUI;

using System;
using System.Runtime.InteropServices;

using NetDimension.NanUI.HostWindow;
using Vanara.PInvoke;
Expand Down Expand Up @@ -555,28 +556,37 @@ internal void CreateHostWindow()
{

Form innerWindow = null;
var defaultColor = _browserSettings.BackgroundColor;

switch (WindowType)
{
case HostWindowType.System:
innerWindow = new StandardHostWindow(this);
innerWindow.BackColor = Color.FromArgb(0xff, defaultColor.R, defaultColor.G, defaultColor.B);

_currentHostWindowStyle = new SystemWindowStyle(innerWindow);

break;
case HostWindowType.SystemBorderless:
innerWindow = new DwmFramelessHostWindow(this);
innerWindow.BackColor = Color.FromArgb(0xff, defaultColor.R, defaultColor.G, defaultColor.B);

_currentHostWindowStyle = new SystemBorderlessWindowStyle(innerWindow);

break;
case HostWindowType.Borderless:
innerWindow = new FramelessHostWindow(this);
innerWindow.BackColor = Color.FromArgb(0xff, defaultColor.R, defaultColor.G, defaultColor.B);

_currentHostWindowStyle = new BorderlessWindowStyle(innerWindow);

break;
case HostWindowType.Kiosk:
Sizable = false;
AllowFullScreen = false;
innerWindow = new StandardHostWindow(this);
innerWindow.BackColor = Color.FromArgb(0xff, defaultColor.R, defaultColor.G, defaultColor.B);

_currentHostWindowStyle = new KioskWindowStyle(innerWindow);
innerWindow.FormBorderStyle = FormBorderStyle.None;
innerWindow.WindowState = FormWindowState.Maximized;
Expand All @@ -595,6 +605,9 @@ internal void CreateHostWindow()
FormBorderStyle = FormBorderStyle.FixedSingle
};

innerWindow.BackColor = Color.FromArgb(defaultColor.A, defaultColor.R, defaultColor.G, defaultColor.B);



WinFormium.DefaultBrowserSettings.WindowlessFrameRate = 60;
_currentHostWindowStyle = new LayeredWindowStyle(innerWindow);
Expand All @@ -610,6 +623,11 @@ internal void CreateHostWindow()








FormHostWindow = innerWindow;


Expand Down Expand Up @@ -771,12 +789,26 @@ private bool OnHostWindowWndProc(ref Message m)
const string FORMIUM_ACTIVATED = "formium-app-activated";
const string FORMIUM_DEACTIVATE = "formium-app-deactivate";

if (m.Msg == (int)WindowMessage.WM_SIZE)
if (m.Msg == (int)WindowMessage.WM_SIZE || m.Msg == (int)WindowMessage.WM_WINDOWPOSCHANGED)
{
ResizeWebView();
}

if(m.Msg == (int)WindowMessage.WM_ACTIVATEAPP)
//if(m.Msg == (int)WindowMessage.WM_WINDOWPOSCHANGED)
//{
// var windowpos = Marshal.PtrToStructure<WINDOWPOS>(m.LParam);

// if((windowpos.flags & SetWindowPosFlags.SWP_NOSIZE)!= SetWindowPosFlags.SWP_NOSIZE)
// {
// ResizeWebView();

// }



//}

if (m.Msg == (int)WindowMessage.WM_ACTIVATEAPP)
{
var isAppActivate = false;

Expand Down
12 changes: 12 additions & 0 deletions src/NetDimension.NanUI/Formium/Formium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,27 @@ public abstract partial class Formium
/// </summary>
protected ServiceContainer IoC => WinFormium.Runtime?.Container;

private CefBrowserSettings _browserSettings;

public Formium()
{
_browserSettings = OnCreateBrowserSettings();


if (_browserSettings == null)
{
_browserSettings = WinFormium.DefaultBrowserSettings;
}

InitializeFormium();
}



private void InitializeFormium()
{


CreateHostWindow();
}

Expand Down
32 changes: 28 additions & 4 deletions src/NetDimension.NanUI/HostWindow/DwmFramelessHostWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public DwmFramelessHostWindow(Formium formium)

InitializeReflectedFields();


SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, false);



}
public WindowMessageDelegate OnWindowsMessage { get; set; }
public WindowMessageDelegate OnDefWindowsMessage { get; set; }
Expand All @@ -27,7 +33,8 @@ protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);

//DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED);

DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED);

//DwmExtendFrameIntoClientArea(hWnd, new MARGINS(0, this.Width, 0, this.Height));

Expand All @@ -47,6 +54,9 @@ private void AdjustWindowRect(ref RECT rect, WindowStyles style, WindowStylesEx
AdjustWindowRectEx(ref rect, style, false, exStyle);
}
}



internal Padding GetNonClientAeraBorders()
{
var rect = RECT.Empty;
Expand Down Expand Up @@ -75,22 +85,36 @@ protected override void WndProc(ref Message m)
{
if (m.Msg == (int)WindowMessage.WM_NCCALCSIZE && m.WParam != IntPtr.Zero)
{
var nccsp = Marshal.PtrToStructure<BorderlessWindow.NCCALCSIZE_PARAMS>(m.LParam);

if (IsZoomed(hWnd))
{
var nccsp = Marshal.PtrToStructure<BorderlessWindow.NCCALCSIZE_PARAMS>(m.LParam);
var ncBorders = GetNonClientAeraBorders();

nccsp.rgrc1 = nccsp.rgrc0;
nccsp.rgrc0.top -= ncBorders.Top;
nccsp.rgrc0.top += ncBorders.Bottom;
Marshal.StructureToPtr(nccsp, m.LParam, false);

m.Result = (IntPtr)0x0400;

Marshal.StructureToPtr(nccsp, m.LParam, true);

base.WndProc(ref m);
}
else
{
nccsp.rgrc0.top -= 1;
nccsp.rgrc0.bottom += 1;
nccsp.rgrc0.left -= 1;
nccsp.rgrc0.right += 1;

m.Result = IntPtr.Zero;

Marshal.StructureToPtr(nccsp, m.LParam, true);
}



return;
}

Expand All @@ -108,7 +132,7 @@ protected override void WndProc(ref Message m)
}
}

if(m.Msg == (int)WindowMessage.WM_PAINT)
if (m.Msg == (int)WindowMessage.WM_PAINT)
{

var hdc = BeginPaint(hWnd, out var ps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Xilium.CefGlue;
using Xilium.CefGlue;
using static Vanara.PInvoke.User32;

namespace NetDimension.NanUI.HostWindow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private MessageResponse OnObjectSetProperty(MessageRequest request)
string name = data.Name;
Guid propUuid = data.Uuid;
Guid objUuid = data.ObjectUuid;
JavaScriptValue value = JavaScriptValue.FromJson((string)data.Value);
var value = JavaScriptValue.FromJson((string)data.Value);

var target = JavaScriptProperty.Bag.SingleOrDefault(x => x.Uuid == propUuid);

Expand Down
5 changes: 4 additions & 1 deletion src/NetDimension.NanUI/Runtime/RuntimeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ internal int InitializeProcessOnly()

var exitCode = CefRuntime.ExecuteProcess(cefMainArgs, app, IntPtr.Zero);

//ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.BrowserProcessInitialized]?.Invoke(this, ApplicationProperties);

return exitCode;
}

Expand Down Expand Up @@ -208,11 +210,12 @@ This project is under MIT License.
settings.BrowserSubprocessPath = ChromiumEnvironment.SubprocessPath;
}


CefRuntime.Initialize(new CefMainArgs(args), settings, app, IntPtr.Zero);

ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.BrowserProcessInitialized]?.Invoke(this, ApplicationProperties);



foreach (var config in CustomResourceHandlerConfigurations)
{
config.OnResourceHandlerRegister();
Expand Down
Loading

0 comments on commit 6607f84

Please sign in to comment.