Skip to content

Commit

Permalink
Workaround for window maximize issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shatyuka authored and bagusnl committed Nov 29, 2023
1 parent 4e1f895 commit 44dc80d
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CollapseLauncher/Classes/Properties/InnerLauncherConfig.cs
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ public enum AppMode
public static Microsoft.UI.WindowId m_windowID;
public static Rect m_windowPosSize;
public static IntPtr m_windowHandle;
public static IntPtr m_oldWndProc;
public static Delegate m_newWndProcDelegate;
public static AppWindow m_appWindow;
public static OverlappedPresenter m_presenter;
public static MainPage m_mainPage;
22 changes: 22 additions & 0 deletions CollapseLauncher/XAMLs/MainApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Graphics;
@@ -164,6 +165,27 @@ public void InitializeWindowSettings()

MainFrameChangerInvoker.WindowFrameEvent += MainFrameChangerInvoker_WindowFrameEvent;
LauncherUpdateInvoker.UpdateEvent += LauncherUpdateInvoker_UpdateEvent;

// Install WndProc hook
const int GWLP_WNDPROC = -4;
m_newWndProcDelegate = (WndProcDelegate)WndProc;
IntPtr pWndProc = Marshal.GetFunctionPointerForDelegate(m_newWndProcDelegate);
m_oldWndProc = SetWindowLongPtr(m_windowHandle, GWLP_WNDPROC, pWndProc);
}

private delegate IntPtr WndProcDelegate(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam);

private IntPtr WndProc(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam)
{
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MAXIMIZE = 0xF030;
if (msg == WM_SYSCOMMAND && wParam == SC_MAXIMIZE)
{
// Ignore WM_SYSCOMMAND SC_MAXIMIZE message
// Thank you Microsoft :)
return 1;
}
return CallWindowProc(m_oldWndProc, hwnd, msg, wParam, lParam);
}

private void SetLegacyTitleBarColor()
6 changes: 6 additions & 0 deletions Hi3Helper.Core/Classes/Data/InvokeProp.cs
Original file line number Diff line number Diff line change
@@ -203,12 +203,18 @@ public struct WindowRect
[DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int index, uint value);

[DllImport("user32.dll")]
public extern static IntPtr SetWindowLongPtr(IntPtr hwnd, int index, IntPtr value);

[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll")]
public static extern bool DestroyWindow(IntPtr hwnd);

[DllImport("user32.dll")]
public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam);

public static IntPtr GetProcessWindowHandle(string ProcName) => Process.GetProcessesByName(Path.GetFileNameWithoutExtension(ProcName), ".")[0].MainWindowHandle;

public class InvokePresence

0 comments on commit 44dc80d

Please sign in to comment.