Giter Site home page Giter Site logo

Comments (4)

dotMorten avatar dotMorten commented on August 23, 2024 2

I just figured it out! If I restore position when I receive the WM_SHOWWINDOW message, there's no visible jump.

from winuiex.

dotMorten avatar dotMorten commented on August 23, 2024

I’ve tried but failed. Perhaps @marb2000 can suggest the right time to do this?

from winuiex.

mikebattista avatar mikebattista commented on August 23, 2024

@rkarman do you have any guidance here? The window size and position are getting loaded with the below. We're wondering if there's a better way to do this so all the window resizing is handled before we show anything to the user.

private void Window_Activated(object sender, WindowActivatedEventArgs args)
{
_window.Activated -= Window_Activated;
_window.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.High, () =>
{
LoadPersistence();
InitBackdrop();
});
if (BackdropConfiguration != null)
BackdropConfiguration.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
}

private void LoadPersistence()
{
if (!string.IsNullOrEmpty(PersistenceId))
{
try
{
if (ApplicationData.Current?.LocalSettings?.Containers is null ||
!ApplicationData.Current.LocalSettings.Containers.ContainsKey("WinUIEx"))
return;
byte[]? data = null;
var winuiExSettings = ApplicationData.Current.LocalSettings.CreateContainer("WinUIEx", ApplicationDataCreateDisposition.Existing);
if (winuiExSettings is not null && winuiExSettings.Values.ContainsKey($"WindowPersistance_{PersistenceId}"))
{
var base64 = winuiExSettings.Values[$"WindowPersistance_{PersistenceId}"] as string;
if(base64 != null)
data = Convert.FromBase64String(base64);
}
if (data is null)
return;
// Check if monitor layout changed since we stored position
var monitors = MonitorInfo.GetDisplayMonitors();
System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.MemoryStream(data));
int monitorCount = br.ReadInt32();
if (monitorCount < monitors.Count)
return; // Don't restore - list of monitors changed
for (int i = 0; i < monitorCount; i++)
{
var pMonitor = monitors[i];
if (pMonitor.Name != br.ReadString() ||
pMonitor.RectMonitor.Left != br.ReadDouble() ||
pMonitor.RectMonitor.Top != br.ReadDouble() ||
pMonitor.RectMonitor.Right != br.ReadDouble() ||
pMonitor.RectMonitor.Bottom != br.ReadDouble())
return; // Don't restore - Monitor layout changed
}
int structSize = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
byte[] placementData = br.ReadBytes(structSize);
IntPtr buffer = Marshal.AllocHGlobal(structSize);
Marshal.Copy(placementData, 0, buffer, structSize);
var retobj = (WINDOWPLACEMENT)Marshal.PtrToStructure(buffer, typeof(WINDOWPLACEMENT))!;
Marshal.FreeHGlobal(buffer);
// Ignore anything by maximized or normal
if (retobj.showCmd == SHOW_WINDOW_CMD.SW_INVALIDATE && retobj.flags == WINDOWPLACEMENT_FLAGS.WPF_RESTORETOMAXIMIZED)
retobj.showCmd = SHOW_WINDOW_CMD.SW_MAXIMIZE;
else if (retobj.showCmd != SHOW_WINDOW_CMD.SW_MAXIMIZE)
retobj.showCmd = SHOW_WINDOW_CMD.SW_NORMAL;
_restoringPersistance = true;
Windows.Win32.PInvoke.SetWindowPlacement(new Windows.Win32.Foundation.HWND(_window.GetWindowHandle()), in retobj);
_restoringPersistance = false;
}
catch { }
}
}

from winuiex.

mikebattista avatar mikebattista commented on August 23, 2024

Awesome!

from winuiex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.