Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App sometimes gets cut when maximized #182

Closed
NotroDev opened this issue Feb 6, 2023 · 2 comments
Closed

App sometimes gets cut when maximized #182

NotroDev opened this issue Feb 6, 2023 · 2 comments

Comments

@NotroDev
Copy link

NotroDev commented Feb 6, 2023

Describe the bug

App sometimes gets cut in left top corner when maximized.

Steps to reproduce the bug

  1. Create window like this https://github.com/NotroDev/SkEditorPlus/blob/main/SkEditorPlus/MainWindow.xaml.cs
  2. Minimize it
  3. Maximize it by moving it to screen's top

Expected behavior

No response

Screenshots

image

NuGet package version

HandyControls (Custom version) 3.4.0

IDE

Visual Studio 2022

Framework type

.Net 6.0

Windows version

Windows 11 (22000)

Additional context

HandyControls' version is 3.4.4.

@NotroDev
Copy link
Author

NotroDev commented Feb 9, 2023

I think I fixed it with this code:

[DllImport("user32.dll")]
static extern IntPtr GetWindow(IntPtr hWnd, uint wCmd);
const uint GW_HWNDNEXT = 2;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);


private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
    FixCut();
}

private void FixCut()
{
    if (WindowState == WindowState.Maximized)
    {
        IntPtr hWnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;

        IntPtr hNext = hWnd;
        do
            hNext = GetWindow(hNext, GW_HWNDNEXT);
        while (!IsWindowVisible(hNext));

        SetForegroundWindow(hNext);

        Activate();
    }
}

private void Window_StateChanged(object sender, EventArgs e)
{
    FixCut();
}

@ghost1372
Copy link
Owner

ghost1372 commented Mar 10, 2023

Tnx but i am not working with wpf anymore

ghost1372 added a commit that referenced this issue Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants