Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/EasyWindowsApplication/Core/Application.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyWindowsApplication.Common;
using System.Diagnostics;
using EasyWindowsApplication.Common;
using EasyWindowsApplication.Share;
using EasyWindowsApplication.Core.LayoutEngine;
using EasyWindowsApplication.Core.Windowing;
Expand Down Expand Up @@ -64,6 +65,11 @@ public void Initialize()
ControlActivatorRegistry.EnsureInitialized();
_router = new MasterRouter(_registry);

Debug.Assert(
UiDefaultsProvider.IsInitialized,
"UiDefaultsProvider debe inicializarse (UseWinApi / UseWpf / …) " +
"antes de registrar la clase de ventana.");

foreach (var window in _windows)
{
if (window.IsAlternative)
Expand Down
6 changes: 5 additions & 1 deletion src/EasyWindowsApplication/Core/MasterRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,13 @@ internal nint WndProc(nint hwnd, uint msg, nint wParam, nint lParam)
// Handle WM_ERASEBKGND — paint window background, then LayoutGroup backgrounds on top
if (msg == WM.ERASEBKGND)
{
bool painted = false;

if (_windowBrushes.TryGetValue(hwnd, out var windowBrush))
{
Win32.GetClientRect(hwnd, out RECT rect);
Win32.FillRect(wParam, ref rect, windowBrush);
painted = true;
}

if (_layoutGroupBackgrounds.TryGetValue(hwnd, out var backgrounds))
Expand All @@ -288,9 +291,10 @@ internal nint WndProc(nint hwnd, uint msg, nint wParam, nint lParam)
Win32.FillRect(wParam, ref r, brush);
Win32.DeleteObject(brush);
}
painted = true;
}

return 1;
if (painted) return 1;
}

// Handle WM_CTLCOLOR* — return control background brush
Expand Down
10 changes: 2 additions & 8 deletions src/EasyWindowsApplication/Core/UiDefaults/CoreUiDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ internal abstract class CoreUiDefaults : IDefaultUiValues
public abstract FontSpec DefaultFont { get; }

public virtual Color DefaultForeground
=> ColorFromSysColor(Win32.GetSysColor(COLOR_WINDOWTEXT));
=> ColorFromSysColor(Win32.GetSysColor(Win32.COLOR_WINDOWTEXT));

public virtual Color DefaultBackground
=> ColorFromSysColor(Win32.GetSysColor(COLOR_WINDOW));
=> ColorFromSysColor(Win32.GetSysColor(Win32.COLOR_WINDOW));

public virtual Thickness DefaultPadding => new(3);
public virtual int DefaultControlSpacing => 6;
Expand All @@ -43,10 +43,4 @@ protected static Color ColorFromSysColor(int colorRef)
(byte)(colorRef & 0xFF),
(byte)((colorRef >> 8) & 0xFF),
(byte)((colorRef >> 16) & 0xFF));

// SysColor indices (winuser.h)
private const int COLOR_WINDOW = 5;
private const int COLOR_WINDOWTEXT = 8;
private const int COLOR_BTNFACE = 15;
private const int COLOR_BTNTEXT = 18;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ private sealed class CoreFallbackDefaults : CoreUiDefaults
private static IDefaultUiValues _current = new CoreFallbackDefaults();

public static IDefaultUiValues Current => _current;
public static bool IsInitialized => _current is not CoreFallbackDefaults;

public static void Set(IDefaultUiValues defaults)
=> _current = defaults ?? throw new ArgumentNullException(nameof(defaults));
Expand Down
6 changes: 6 additions & 0 deletions src/EasyWindowsApplication/Core/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace EasyWindowsApplication.Core;

internal static partial class Win32
{
// ── System Color Indices (winuser.h) ──
internal const int COLOR_WINDOW = 5;
internal const int COLOR_WINDOWTEXT = 8;
internal const int COLOR_BTNFACE = 15;
internal const int COLOR_BTNTEXT = 18;

// ── Message Loop ──
[LibraryImport("user32.dll", SetLastError = true)]
internal static partial int GetMessageW(out MSG lpMsg, nint hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
Expand Down
4 changes: 2 additions & 2 deletions src/EasyWindowsApplication/Core/Windowing/Procedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal static unsafe nint CreateMainWindow(
hInstance = hInstance,
hIcon = hIconLarge,
hCursor = 0,
hbrBackground = 0,
hbrBackground = (nint)(Win32.COLOR_WINDOW + 1),
lpszMenuName = 0,
lpszClassName = classNamePtr,
hIconSm = hIconSmall
Expand Down Expand Up @@ -124,7 +124,7 @@ internal static unsafe nint CreateAlternativeWindow(
hInstance = hInstance,
hIcon = 0,
hCursor = 0,
hbrBackground = 0,
hbrBackground = (nint)(Win32.COLOR_WINDOW + 1),
lpszMenuName = 0,
lpszClassName = classNamePtr,
hIconSm = 0
Expand Down
3 changes: 3 additions & 0 deletions src/EasyWindowsApplication/Core/Windowing/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace EasyWindowsApplication.Core.Windowing;

internal static partial class Win32
{
// ── System Color Indices (winuser.h) ──
internal const int COLOR_WINDOW = 5;

[LibraryImport("user32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static partial ushort RegisterClassExW(ref WNDCLASSEXW lpWndClass);

Expand Down
Loading