I want to override maximize button of window in WPF to resize width and height more than one monitor. How to do it? Thanks!
Check this: https://stackoverflow.com/a/52035623/9912441
You need to find total width and height of all monitor with the monitor info.
[DllImport("user32")]
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
[DllImport("User32")]
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class MONITORINFO
{
/// <summary>
/// </summary>
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
/// <summary>
/// </summary>
public RECT rcMonitor = new RECT();
/// <summary>
/// </summary>
public RECT rcWork = new RECT();
/// <summary>
/// </summary>
public int dwFlags = 0;
}
void Maximize(HWND hWnd, HMONITOR hMonitor)
{
// access monitor info
MONITORINFO monitorInfo = { sizeof(MONITORINFO) };
GetMonitorInfo(hMonitor, &monitorInfo);
// restore window to normal size if it is not yet
ShowWindow(hWnd, SW_RESTORE);
// move window to the monitor
SetWindowPos(hWnd, nullptr, monitorInfo.rcMonitor.left,
monitorInfo.rcMonitor.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
// maximize window
ShowWindow(hWnd, SW_MAXIMIZE);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.