src/Notepad3.c
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode)
{
  static WINDOWPLACEMENT s_wndplPrev;
  static bool s_bPrevShowMenubar = true;
  static bool s_bPrevShowToolbar = true;
  static bool s_bPrevShowStatusbar = true;

  static UINT const fFScrFlags = SWP_NOOWNERZORDER | SWP_FRAMECHANGED;
  static UINT const fPrevFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED;
  static DWORD const dwRmvFScrStyle = WS_OVERLAPPEDWINDOW | WS_BORDER;

  HWND const hWindow = hwnd ? hwnd : GetDesktopWindow();

  DWORD dwStyle = GetWindowLong(hWindow, GWL_STYLE);
  RECT rcCurrent; GetWindowRect(hWindow, &rcCurrent);

  if ((mode == SCR_NORMAL) || s_bPrevFullScreenFlag) 
  { 
    SetWindowLong(hWindow, GWL_STYLE, dwStyle | dwRmvFScrStyle);
    if (s_bPrevFullScreenFlag) {
      SetWindowPlacement(hWindow, &s_wndplPrev);
      Settings.ShowMenubar = s_bPrevShowMenubar;
      Settings.ShowToolbar = s_bPrevShowToolbar;
      Settings.ShowStatusbar = s_bPrevShowStatusbar;
    }
    else {
      WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hWindow, &winInfo, mode);
      if (GetDoAnimateMinimize()) { DrawAnimatedRects(hWindow, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition); }
      SetWindowPlacement(hWindow, &wndpl);
    }
    SetWindowPos(hWindow, NULL, 0, 0, 0, 0, fPrevFlags);
    SetWindowPos(hWindow, (Settings.AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    s_bPrevFullScreenFlag = false;
  }
  else { // full screen mode
    GetWindowPlacement(hWindow, &s_wndplPrev);
    MONITORINFO mi = { sizeof(mi) };
    GetMonitorInfo(MonitorFromWindow(hWindow, MONITOR_DEFAULTTOPRIMARY), &mi);
    SetWindowLong(hWindow, GWL_STYLE, dwStyle & ~dwRmvFScrStyle);
    WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hWindow, NULL, mode);
    if (GetDoAnimateMinimize()) { DrawAnimatedRects(hWindow, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition); }
    SetWindowPlacement(hWindow, &wndpl);
    SetWindowPos(hWindow, HWND_TOPMOST, mi.rcMonitor.left, mi.rcMonitor.top,
      mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, fFScrFlags);
    s_bPrevShowMenubar = Settings.ShowMenubar;
    s_bPrevShowToolbar = Settings.ShowToolbar;
    s_bPrevShowStatusbar = Settings.ShowStatusbar;
    Settings.ShowMenubar = Settings.ShowToolbar = Settings.ShowStatusbar = false;
    s_bPrevFullScreenFlag = true;
  }

  DrawMenuBar(Globals.hwndMain);
  MsgThemeChanged(hWindow, (WPARAM)NULL, (LPARAM)NULL);
}
//=============================================================================
//
//  SnapToWinInfoPos()
//  Aligns Notepad3 to the default window position on the current screen
//

SnapToWinInfoPos()
Aligns Notepad3 to the default window position on the current screen
SnapToWinInfoPos () Aligns Notepad3 to the default window position on the current screen
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode)
{
  static WINDOWPLACEMENT s_wndplPrev;
  static bool s_bPrevShowMenubar = true;
  static bool s_bPrevShowToolbar = true;
  static bool s_bPrevShowStatusbar = true;
  static UINT const fFScrFlags = SWP_NOOWNERZORDER | SWP_FRAMECHANGED;
  static UINT const fPrevFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED;
  static DWORD const dwRmvFScrStyle = WS_OVERLAPPEDWINDOW | WS_BORDER;
  HWND const hWindow = hwnd ? hwnd : GetDesktopWindow();
  DWORD dwStyle = GetWindowLong(hWindow, GWL_STYLE);
  RECT rcCurrent; GetWindowRect(hWindow, &rcCurrent);
  if ((mode == SCR_NORMAL) || s_bPrevFullScreenFlag) 
  { 
    SetWindowLong(hWindow, GWL_STYLE, dwStyle | dwRmvFScrStyle);
    if (s_bPrevFullScreenFlag) {
      SetWindowPlacement(hWindow, &s_wndplPrev);
      Settings.ShowMenubar = s_bPrevShowMenubar;
      Settings.ShowToolbar = s_bPrevShowToolbar;
      Settings.ShowStatusbar = s_bPrevShowStatusbar;
    }
    else {
      WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hWindow, &winInfo, mode);
      if (GetDoAnimateMinimize()) { DrawAnimatedRects(hWindow, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition); }
      SetWindowPlacement(hWindow, &wndpl);
    }
    SetWindowPos(hWindow, NULL, 0, 0, 0, 0, fPrevFlags);
    SetWindowPos(hWindow, (Settings.AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    s_bPrevFullScreenFlag = false;
  }
  else { 
    GetWindowPlacement(hWindow, &s_wndplPrev);
    MONITORINFO mi = { sizeof(mi) };
    GetMonitorInfo(MonitorFromWindow(hWindow, MONITOR_DEFAULTTOPRIMARY), &mi);
    SetWindowLong(hWindow, GWL_STYLE, dwStyle & ~dwRmvFScrStyle);
    WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hWindow, NULL, mode);
    if (GetDoAnimateMinimize()) { DrawAnimatedRects(hWindow, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition); }
    SetWindowPlacement(hWindow, &wndpl);
    SetWindowPos(hWindow, HWND_TOPMOST, mi.rcMonitor.left, mi.rcMonitor.top,
      mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, fFScrFlags);
    s_bPrevShowMenubar = Settings.ShowMenubar;
    s_bPrevShowToolbar = Settings.ShowToolbar;
    s_bPrevShowStatusbar = Settings.ShowStatusbar;
    Settings.ShowMenubar = Settings.ShowToolbar = Settings.ShowStatusbar = false;
    s_bPrevFullScreenFlag = true;
  }
  DrawMenuBar(Globals.hwndMain);
  MsgThemeChanged(hWindow, (WPARAM)NULL, (LPARAM)NULL);
}
void SnapToWinInfoPos ( HWND hwnd , const WININFO winInfo , SCREEN_MODE mode ) { static WINDOWPLACEMENT s_wndplPrev ; static bool s_bPrevShowMenubar = true ; static bool s_bPrevShowToolbar = true ; static bool s_bPrevShowStatusbar = true ; static UINT const fFScrFlags = SWP_NOOWNERZORDER | SWP_FRAMECHANGED ; static UINT const fPrevFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED ; static DWORD const dwRmvFScrStyle = WS_OVERLAPPEDWINDOW | WS_BORDER ; HWND const hWindow = hwnd ? hwnd : GetDesktopWindow ( ) ; DWORD dwStyle = GetWindowLong ( hWindow , GWL_STYLE ) ; RECT rcCurrent ; GetWindowRect ( hWindow , & rcCurrent ) ; if ( ( mode == SCR_NORMAL ) || s_bPrevFullScreenFlag ) { SetWindowLong ( hWindow , GWL_STYLE , dwStyle | dwRmvFScrStyle ) ; if ( s_bPrevFullScreenFlag ) { SetWindowPlacement ( hWindow , & s_wndplPrev ) ; Settings . ShowMenubar = s_bPrevShowMenubar ; Settings . ShowToolbar = s_bPrevShowToolbar ; Settings . ShowStatusbar = s_bPrevShowStatusbar ; } else { WINDOWPLACEMENT wndpl = WindowPlacementFromInfo ( hWindow , & winInfo , mode ) ; if ( GetDoAnimateMinimize ( ) ) { DrawAnimatedRects ( hWindow , IDANI_CAPTION , & rcCurrent , & wndpl . rcNormalPosition ) ; } SetWindowPlacement ( hWindow , & wndpl ) ; } SetWindowPos ( hWindow , NULL , 0 , 0 , 0 , 0 , fPrevFlags ) ; SetWindowPos ( hWindow , ( Settings . AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST ) , 0 , 0 , 0 , 0 , SWP_NOMOVE | SWP_NOSIZE ) ; s_bPrevFullScreenFlag = false ; } else { GetWindowPlacement ( hWindow , & s_wndplPrev ) ; MONITORINFO mi = { sizeof ( mi ) } ; GetMonitorInfo ( MonitorFromWindow ( hWindow , MONITOR_DEFAULTTOPRIMARY ) , & mi ) ; SetWindowLong ( hWindow , GWL_STYLE , dwStyle & ~ dwRmvFScrStyle ) ; WINDOWPLACEMENT wndpl = WindowPlacementFromInfo ( hWindow , NULL , mode ) ; if ( GetDoAnimateMinimize ( ) ) { DrawAnimatedRects ( hWindow , IDANI_CAPTION , & rcCurrent , & wndpl . rcNormalPosition ) ; } SetWindowPlacement ( hWindow , & wndpl ) ; SetWindowPos ( hWindow , HWND_TOPMOST , mi . rcMonitor . left , mi . rcMonitor . top , mi . rcMonitor . right - mi . rcMonitor . left , mi . rcMonitor . bottom - mi . rcMonitor . top , fFScrFlags ) ; s_bPrevShowMenubar = Settings . ShowMenubar ; s_bPrevShowToolbar = Settings . ShowToolbar ; s_bPrevShowStatusbar = Settings . ShowStatusbar ; Settings . ShowMenubar = Settings . ShowToolbar = Settings . ShowStatusbar = false ; s_bPrevFullScreenFlag = true ; } DrawMenuBar ( Globals . hwndMain ) ; MsgThemeChanged ( hWindow , ( WPARAM ) NULL , ( LPARAM ) NULL ) ; }
SnapToWinInfoPos()
Aligns Notepad3 to the default window position on the current screen
SnapToWinInfoPos () Aligns Notepad3 to the default window position on the current screen
// full screen mode
