Merge pull request #4434 from RaiKoHoff/Dev_Master

Fix and refactoring window positioning respecting monitor DPI
This commit is contained in:
Pairi Daiza 2022-12-31 16:56:09 +01:00 committed by GitHub
commit c4141e2d12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 194 additions and 165 deletions

View File

@ -316,7 +316,7 @@ Optionen:\r\n\
/b\tÖffne ein neues 'Paste Board' um die Einträge\r\n\tder Zwischenablage zu sammeln.\r\n\
/n\tÖffne immer ein neues Fenster (/ns single file instance).\r\n\
/r\tBenutze geöffnetes Fenster erneut (/rs single file instance).\r\n\
/p\tSetze Fenster: Position und Größe (/p0, /ps, /pf,l,t,r,b,m)\r\n\
/p\tSetze Fenster: Position und Größe (/p0,/ps,/pd,f,l,t,r,b,m)\r\n\
\toder /p <links>,<oben>,<breite>,<höhe>[,<dpi>,<max>] [ganzzahlig].\r\n\
/t\tSetze Fenster-Titel.\r\n\
/i\tStarte als 'Tray-Icon'.\r\n\

View File

@ -316,7 +316,7 @@ Options:\r\n\
/b\tOpen new paste board to collect clipboard entries.\r\n\
/n\tAlways open a new window (/ns single file instance).\r\n\
/r\tReuse window (/rs single file instance).\r\n\
/p\tSet window position and size (/p0, /ps, /pf,l,t,r,b,m)\r\n\
/p\tSet window position and size (/p0,/ps,/pd,f,l,t,r,b,m)\r\n\
\tor /p <left>,<top>,<width>,<height>[,<dpi>,<max>] [all integers].\r\n\
/t\tSet window title.\r\n\
/i\tStart as tray icon.\r\n\

View File

@ -1138,7 +1138,6 @@ extern "C" bool CreateIniFile(const HPATHL hini_pth, DWORD* pdwFileSize_out)
//
// LoadSettings()
//
//
void LoadSettings()
{
CFG_VERSION const _ver = Path_IsEmpty(Paths.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE;
@ -1735,46 +1734,9 @@ void LoadSettings()
IniSectionGetString(IniSecSettings2, Constants.DefaultWindowPosition, L"",
Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition));
bool const bExplicitDefaultWinPos = StrIsNotEmpty(Settings2.DefaultWindowPosition);
// 1st set default window position
g_DefWinInfo = GetFactoryDefaultWndPos(2); // std. default position
if (bExplicitDefaultWinPos) {
int bMaxi = 0;
int const itok = swscanf_s(Settings2.DefaultWindowPosition, WINDOWPOS_STRGFORMAT,
&g_DefWinInfo.x, &g_DefWinInfo.y, &g_DefWinInfo.cx, &g_DefWinInfo.cy, &g_DefWinInfo.dpi, &bMaxi);
if (itok == 4 || itok == 5 || itok == 6) { // scan successful
if (itok == 4) {
g_DefWinInfo.dpi = USER_DEFAULT_SCREEN_DPI;
g_DefWinInfo.max = false;
} else if (itok == 5) { // maybe DPI or Maxi (old)
if (g_DefWinInfo.dpi < (USER_DEFAULT_SCREEN_DPI >> 2)) {
g_DefWinInfo.max = g_DefWinInfo.dpi ? true : false;
g_DefWinInfo.dpi = USER_DEFAULT_SCREEN_DPI;
}
else {
g_DefWinInfo.max = false;
}
} else {
g_DefWinInfo.max = bMaxi ? true : false;
}
} else {
g_DefWinInfo = GetFactoryDefaultWndPos(2);
// overwrite bad defined default position
StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition),
WINDOWPOS_STRGFORMAT, g_DefWinInfo.x, g_DefWinInfo.y, g_DefWinInfo.cx, g_DefWinInfo.cy, g_DefWinInfo.dpi, g_DefWinInfo.max);
IniSectionSetString(IniSecSettings2, Constants.DefaultWindowPosition, Settings2.DefaultWindowPosition);
bDirtyFlag = true;
}
}
// 2nd set initial window position
if (!Globals.CmdLnFlag_PosParam /*|| g_bStickyWinPos*/) {
WININFO winInfo = g_IniWinInfo;
WININFO winInfo = INIT_WININFO;
WCHAR tchPosX[64], tchPosY[64], tchSizeX[64], tchSizeY[64], tchMaximized[64], tchZoom[64], tchDPI[64];
StringCchPrintf(tchPosX, COUNTOF(tchPosX), L"%ix%i PosX", ResX, ResY);
StringCchPrintf(tchPosY, COUNTOF(tchPosY), L"%ix%i PosY", ResX, ResY);
@ -1784,17 +1746,17 @@ void LoadSettings()
StringCchPrintf(tchZoom, COUNTOF(tchZoom), L"%ix%i Zoom", ResX, ResY);
StringCchPrintf(tchDPI, COUNTOF(tchDPI), L"%ix%i DPI", ResX, ResY);
winInfo.x = IniSectionGetInt(IniSecWindow, tchPosX, g_IniWinInfo.x);
winInfo.y = IniSectionGetInt(IniSecWindow, tchPosY, g_IniWinInfo.y);
winInfo.cx = IniSectionGetInt(IniSecWindow, tchSizeX, g_IniWinInfo.cx);
winInfo.cy = IniSectionGetInt(IniSecWindow, tchSizeY, g_IniWinInfo.cy);
winInfo.x = IniSectionGetInt(IniSecWindow, tchPosX, CW_USEDEFAULT);
winInfo.y = IniSectionGetInt(IniSecWindow, tchPosY, CW_USEDEFAULT);
winInfo.cx = IniSectionGetInt(IniSecWindow, tchSizeX, CW_USEDEFAULT);
winInfo.cy = IniSectionGetInt(IniSecWindow, tchSizeY, CW_USEDEFAULT);
winInfo.max = IniSectionGetBool(IniSecWindow, tchMaximized, false);
winInfo.zoom = IniSectionGetInt(IniSecWindow, tchZoom, (Globals.iCfgVersionRead < CFG_VER_0001) ? 0 : 100);
if (Globals.iCfgVersionRead < CFG_VER_0001) {
winInfo.zoom = (winInfo.zoom + 10) * 10;
}
winInfo.zoom = clampi(winInfo.zoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL);
winInfo.dpi = IniSectionGetInt(IniSecWindow, tchDPI, g_IniWinInfo.dpi);
winInfo.dpi = IniSectionGetInt(IniSecWindow, tchDPI, USER_DEFAULT_SCREEN_DPI);
int const offset = Settings2.LaunchInstanceWndPosOffset;
int const instCnt = CountRunningInstances();
@ -1803,7 +1765,6 @@ void LoadSettings()
if ((winInfo.x == CW_USEDEFAULT) || (winInfo.y == CW_USEDEFAULT) ||
(winInfo.cx == CW_USEDEFAULT) || (winInfo.cy == CW_USEDEFAULT)) {
g_IniWinInfo = g_DefWinInfo;
Globals.CmdLnFlag_WindowPos = 2; // std. default position (CmdLn: /pd)
} else {
g_IniWinInfo = winInfo;

View File

@ -4362,6 +4362,7 @@ bool AutoSaveBackupSettingsDlg(HWND hwnd)
// RelAdjustRectForDPI()
//
void RelAdjustRectForDPI(LPRECT rc, const UINT oldDPI, const UINT newDPI) {
if (oldDPI == newDPI) { return; }
float const scale = (float)newDPI / (float)(oldDPI != 0 ? oldDPI : 1);
LONG const oldWidth = (rc->right - rc->left);
LONG const oldHeight = (rc->bottom - rc->top);
@ -4378,7 +4379,7 @@ void RelAdjustRectForDPI(LPRECT rc, const UINT oldDPI, const UINT newDPI) {
//
// MapRectClientToWndCoords()
//
void MapRectClientToWndCoords(HWND hwnd, RECT* rc)
void MapRectClientToWndCoords(HWND hwnd, LPRECT rc)
{
// map to screen (left-top as point)
MapWindowPoints(hwnd, NULL, (POINT*)rc, 2);
@ -4634,12 +4635,97 @@ WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* pWinInfo, SCRE
return wndpl;
}
//=============================================================================
//
// SnapToWinInfoPos()
// Aligns Notepad3 to the given window position on the screen
//
static bool s_bPrevFullScreenFlag = false;
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode)
{
if (!hwnd) {
return;
}
static bool s_bPrevShowMenubar = true;
static bool s_bPrevShowToolbar = true;
static bool s_bPrevShowStatusbar = true;
static bool s_bPrevAlwaysOnTop = false;
static WINDOWPLACEMENT s_wndplPrev = { 0 };
s_wndplPrev.length = sizeof(WINDOWPLACEMENT);
DWORD const dwRmvFScrStyle = WS_OVERLAPPEDWINDOW | WS_BORDER;
DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
RECT rcCurrent;
GetWindowRect(hwnd, &rcCurrent);
if ((mode == SCR_NORMAL) || s_bPrevFullScreenFlag) {
SetWindowLong(hwnd, GWL_STYLE, dwStyle | dwRmvFScrStyle);
if (s_bPrevFullScreenFlag) {
SetWindowPlacement(hwnd, &s_wndplPrev); // 1st set correct screen (DPI Aware)
SetWindowPlacement(hwnd, &s_wndplPrev); // 2nd resize position to correct DPI settings
Settings.ShowMenubar = s_bPrevShowMenubar;
Settings.ShowToolbar = s_bPrevShowToolbar;
Settings.ShowStatusbar = s_bPrevShowStatusbar;
Settings.AlwaysOnTop = s_bPrevAlwaysOnTop;
}
else {
WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hwnd, &winInfo, mode);
if (GetDoAnimateMinimize()) {
DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition);
}
SetWindowPlacement(hwnd, &wndpl); // 1st set correct screen (DPI Aware)
RelAdjustRectForDPI(&wndpl.rcNormalPosition, winInfo.dpi, Scintilla_GetWindowDPI(hwnd));
SetWindowPlacement(hwnd, &wndpl); // 2nd resize position to correct DPI settings
}
SetWindowPos(hwnd, Settings.AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
s_bPrevFullScreenFlag = false;
}
else { // full screen mode
s_bPrevShowMenubar = Settings.ShowMenubar;
s_bPrevShowToolbar = Settings.ShowToolbar;
s_bPrevShowStatusbar = Settings.ShowStatusbar;
s_bPrevAlwaysOnTop = Settings.AlwaysOnTop;
GetWindowPlacement(hwnd, &s_wndplPrev);
MONITORINFO mi = { sizeof(mi) };
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &mi);
SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~dwRmvFScrStyle);
WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hwnd, NULL, mode);
if (GetDoAnimateMinimize()) {
DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition);
}
SetWindowPlacement(hwnd, &wndpl);
SetWindowPos(hwnd, HWND_TOPMOST, mi.rcMonitor.left, mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
Settings.ShowMenubar = Settings.ShowToolbar = Settings.ShowStatusbar = false;
Settings.AlwaysOnTop = true;
s_bPrevFullScreenFlag = true;
}
SendWMSize(hwnd, NULL);
UpdateToolbar();
}
//=============================================================================
//
// RestorePrevScreenPos()
//
void RestorePrevScreenPos(HWND hwnd)
{
if (hwnd == Globals.hwndMain) {
if (s_bPrevFullScreenFlag) {
SendWMCommand(hwnd, CMD_FULLSCRWINPOS);
}
}
}
//=============================================================================
//
// DialogNewWindow()
//
//
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, const HPATHL hFilePath, WININFO* wi)
{
if (bSaveOnRunTools && !FileSave(FSF_Ask)) {

View File

@ -69,6 +69,8 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo, const
bool GetWindowRectEx(HWND hwnd, LPRECT pRect);
void FitIntoMonitorGeometry(LPRECT pRect, WININFO* pWinInfo, SCREEN_MODE mode, bool bTopLeft);
WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* pWinInfo, SCREEN_MODE mode);
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode);
void RestorePrevScreenPos(HWND hwnd);
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, const HPATHL hFilePath, WININFO* wi);
void DialogFileBrowse(HWND hwnd);
@ -156,7 +158,7 @@ void ResizeDlg_GetMinMaxInfo(HWND hwnd, LPARAM lParam);
void ResizeDlg_SetAttr(HWND hwnd, int index, int value);
int ResizeDlg_GetAttr(HWND hwnd, int index);
void ResizeDlg_InitY2Ex(HWND hwnd, int cxFrame, int cyFrame, int nIdGrip, RSZ_DLG_DIR iDirection, int nCtlId1, int nCtlId2);
void ResizeDlg_InitY2Ex(HWND hwnd, int cxFrame, int cyFrame, int nIdGrip, int iDirection, int nCtlId1, int nCtlId2);
inline void ResizeDlg_InitY2(HWND hwnd, int cxFrame, int cyFrame, int nIdGrip, int nCtlId1, int nCtlId2)
{
ResizeDlg_InitY2Ex(hwnd, cxFrame, cyFrame, nIdGrip, RSZ_BOTH, nCtlId1, nCtlId2);

View File

@ -165,7 +165,6 @@ static int s_cyReBarFrame;
static int s_cxEditFrame;
static int s_cyEditFrame;
static bool s_bUndoRedoScroll = false;
static bool s_bPrevFullScreenFlag = false;
// for tiny expression calculation
static double s_dExpression = 0.0;
@ -814,8 +813,6 @@ static void _InitGlobals()
// --- unstructured globals ---
g_IniWinInfo = GetFactoryDefaultWndPos(2);
g_tchToolbarBitmap = Path_Allocate(NULL);
g_tchToolbarBitmapHot = Path_Allocate(NULL);
g_tchToolbarBitmapDisabled = Path_Allocate(NULL);
@ -1319,37 +1316,94 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
// GetFactoryDefaultWndPos()
//
//
WININFO GetFactoryDefaultWndPos(const int flagsPos)
WININFO GetFactoryDefaultWndPos(HWND hwnd, const int flagsPos)
{
HWND const hwnd = GetDesktopWindow();
RECT rc;
hwnd = hwnd ? hwnd : GetDesktopWindow();
unsigned int const dpi = Scintilla_GetWindowDPI(hwnd);
RECT rc = { 0 };
GetWindowRect(hwnd, &rc);
MONITORINFO mi;
GetMonitorInfoFromRect(&rc, &mi);
rc = mi.rcWork;
//~RelAdjustRectForDPI(&rc, USER_DEFAULT_SCREEN_DPI, dpi);
WININFO winfo = INIT_WININFO;
winfo.y = mi.rcMonitor.top;
winfo.cy = mi.rcWork.bottom - mi.rcWork.top;
winfo.cx = (mi.rcWork.right - mi.rcWork.left) / 2;
winfo.x = (flagsPos == 3) ? mi.rcMonitor.left : winfo.cx;
winfo.y = rc.top;
winfo.cy = rc.bottom - rc.top;
winfo.cx = (rc.right - rc.left) / 2;
winfo.x = (flagsPos == 3) ? rc.left : winfo.cx;
winfo.max = 0;
winfo.zoom = 100;
winfo.dpi = Scintilla_GetWindowDPI(hwnd);
winfo.dpi = dpi;
return winfo;
}
// ----------------------------------------------------------------------------
//=============================================================================
//
// _GetDefaultWinInfoByStrg()
//
static WININFO _GetDefaultWinInfoByStrg(HWND hwnd, LPCWSTR strDefaultWinPos)
{
hwnd = hwnd ? hwnd : GetDesktopWindow();
WININFO const wiDef = GetFactoryDefaultWndPos(hwnd, 2); // std. default position
if (StrIsEmpty(strDefaultWinPos)) {
return wiDef;
}
WININFO wi = wiDef;
int bMaxi = 0;
int const itok = swscanf_s(Settings2.DefaultWindowPosition, WINDOWPOS_STRGFORMAT,
&wi.x, &wi.y, &wi.cx, &wi.cy, &wi.dpi, &bMaxi);
if (itok == 4 || itok == 5 || itok == 6) { // scan successful
if (itok == 4) {
wi.dpi = USER_DEFAULT_SCREEN_DPI;
wi.max = false;
}
else if (itok == 5) { // maybe DPI or Maxi (old)
if (wi.dpi < (USER_DEFAULT_SCREEN_DPI >> 2)) {
wi.max = wi.dpi ? true : false;
wi.dpi = USER_DEFAULT_SCREEN_DPI;
}
else {
wi.max = false;
}
}
else {
wi.max = bMaxi ? true : false;
}
}
else {
wi = wiDef;
// overwrite bad defined default position
StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition),
WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, wi.max);
IniSectionSetString(Constants.Settings2_Section, Constants.DefaultWindowPosition, Settings2.DefaultWindowPosition);
}
return wi;
}
//=============================================================================
//
// GetWinInfoByFlag()
//
//
WININFO GetWinInfoByFlag(const int flagsPos)
WININFO GetWinInfoByFlag(HWND hwnd, const int flagsPos)
{
hwnd = hwnd ? hwnd : GetDesktopWindow();
if ((g_DefWinInfo.x == CW_USEDEFAULT) || (g_DefWinInfo.y == CW_USEDEFAULT)) {
g_DefWinInfo = _GetDefaultWinInfoByStrg(hwnd, Settings2.DefaultWindowPosition);
}
WININFO winfo = INIT_WININFO;
if (flagsPos < 0) {
winfo = GetMyWindowPlacement(Globals.hwndMain, NULL, 0); // current window position
winfo = GetMyWindowPlacement(hwnd, NULL, 0); // current window position
} else if (flagsPos == 0) {
winfo = g_IniWinInfo; // initial window position
} else if (flagsPos == 1) {
@ -1359,21 +1413,21 @@ WININFO GetWinInfoByFlag(const int flagsPos)
} else if (flagsPos == 2) {
winfo = g_DefWinInfo; // NP3 default window position
} else if (flagsPos == 3) {
winfo = GetFactoryDefaultWndPos(flagsPos);
winfo = GetFactoryDefaultWndPos(hwnd, flagsPos);
} else if ((flagsPos >= 4) && (flagsPos < 256)) {
HWND const hwnd = GetDesktopWindow();
RECT rc;
RECT rc = { 0 };
GetWindowRect(hwnd, &rc);
MONITORINFO mi;
GetMonitorInfoFromRect(&rc, &mi);
rc = mi.rcWork;
int const width = (mi.rcWork.right - mi.rcWork.left);
int const height = (mi.rcWork.bottom - mi.rcWork.top);
int const width = (rc.right - rc.left);
int const height = (rc.bottom - rc.top);
if (flagsPos & 8) {
winfo.x = mi.rcMonitor.left + (width >> 1);
winfo.x = rc.left + (width >> 1);
} else {
winfo.x = mi.rcMonitor.left;
winfo.x = rc.left;
}
if (flagsPos & (4 | 8)) {
@ -1383,9 +1437,9 @@ WININFO GetWinInfoByFlag(const int flagsPos)
}
if (flagsPos & 32) {
winfo.y = mi.rcMonitor.top + (height >> 1);
winfo.y = rc.top + (height >> 1);
} else {
winfo.y = mi.rcMonitor.top;
winfo.y = rc.top;
}
if (flagsPos & (16 | 32)) {
@ -1395,8 +1449,8 @@ WININFO GetWinInfoByFlag(const int flagsPos)
}
if (flagsPos & 64) {
winfo.x = mi.rcMonitor.left;
winfo.y = mi.rcMonitor.top;
winfo.x = rc.left;
winfo.y = rc.top;
winfo.cx = width;
winfo.cy = height;
}
@ -1413,9 +1467,10 @@ WININFO GetWinInfoByFlag(const int flagsPos)
RectFromWinInfo(&winfo, &rc);
MONITORINFO mi;
GetMonitorInfoFromRect(&rc, &mi);
rc = mi.rcWork;
WININFO wi = winfo;
wi.cx = wi.cy = 16; // really small
FitIntoMonitorGeometry(&(mi.rcWork), &wi, SCR_NORMAL, false);
FitIntoMonitorGeometry(&rc, &wi, SCR_NORMAL, false);
winfo.x = wi.x;
winfo.y = wi.y;
}
@ -1697,8 +1752,8 @@ HWND InitInstance(const HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(pszCmdLine);
g_IniWinInfo = GetWinInfoByFlag(Globals.CmdLnFlag_WindowPos);
s_WinCurrentWidth = g_IniWinInfo.cx;
// init w/o hwnd
g_IniWinInfo = GetWinInfoByFlag(NULL, Globals.CmdLnFlag_WindowPos);
// get monitor coordinates from g_IniWinInfo
WININFO srcninfo = g_IniWinInfo;
@ -1720,9 +1775,12 @@ HWND InitInstance(const HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow)
hInstance,
NULL);
g_IniWinInfo.dpi = Scintilla_GetWindowDPI(hwndMain); // correct dpi
SnapToWinInfoPos(hwndMain, g_IniWinInfo, SCR_NORMAL);
// correct infos based on hwnd
g_DefWinInfo = _GetDefaultWinInfoByStrg(hwndMain, Settings2.DefaultWindowPosition);
g_IniWinInfo = GetWinInfoByFlag(hwndMain, Globals.CmdLnFlag_WindowPos);
s_WinCurrentWidth = g_IniWinInfo.cx;
SnapToWinInfoPos(hwndMain, g_IniWinInfo, SCR_NORMAL);
if (g_IniWinInfo.max) {
nCmdShow = SW_SHOWMAXIMIZED;
}
@ -3173,9 +3231,7 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
if (!bShutdownOK) {
if (s_bPrevFullScreenFlag) {
SendWMCommand(hwnd, CMD_FULLSCRWINPOS);
}
RestorePrevScreenPos(hwnd);
// Terminate AutoSave
AutoSaveStop();
@ -7023,7 +7079,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
break;
case CMD_FULLSCRWINPOS: {
WININFO wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
WININFO wi = GetMyWindowPlacement(hwnd, NULL, 0);
SnapToWinInfoPos(hwnd, wi, SCR_FULL_SCREEN);
}
break;
@ -7033,18 +7089,18 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
break;
case CMD_SAVEASDEFWINPOS: {
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
WININFO const wi = GetMyWindowPlacement(hwnd, NULL, 0);
WCHAR tchDefWinPos[80];
StringCchPrintf(tchDefWinPos, COUNTOF(tchDefWinPos), WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, (int)wi.max);
if (Globals.bCanSaveIniFile) {
IniFileSetString(Paths.IniFile, Constants.Settings2_Section, Constants.DefaultWindowPosition, tchDefWinPos);
}
g_DefWinInfo = wi; //GetWinInfoByFlag(-1); // use current win pos as new default
g_DefWinInfo = wi; //~GetWinInfoByFlag(-1); // use current win pos as new default
}
break;
case CMD_CLEARSAVEDWINPOS:
g_DefWinInfo = GetFactoryDefaultWndPos(2);
g_DefWinInfo = GetFactoryDefaultWndPos(hwnd, 2);
IniFileDelete(Paths.IniFile, Constants.Settings2_Section, Constants.DefaultWindowPosition, false);
break;
@ -12097,81 +12153,6 @@ bool RelaunchElevated(LPCWSTR lpNewCmdLnArgs)
}
//=============================================================================
//
// SnapToWinInfoPos()
// Aligns Notepad3 to the default window position on the current screen
//
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode)
{
static bool s_bPrevShowMenubar = true;
static bool s_bPrevShowToolbar = true;
static bool s_bPrevShowStatusbar = true;
static bool s_bPrevAlwaysOnTop = false;
static WINDOWPLACEMENT s_wndplPrev = { 0 };
s_wndplPrev.length = sizeof(WINDOWPLACEMENT);
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); // 1st set correct screen (DPI Aware)
SetWindowPlacement(hWindow, &s_wndplPrev); // 2nd resize position to correct DPI settings
Settings.ShowMenubar = s_bPrevShowMenubar;
Settings.ShowToolbar = s_bPrevShowToolbar;
Settings.ShowStatusbar = s_bPrevShowStatusbar;
Settings.AlwaysOnTop = s_bPrevAlwaysOnTop;
} else {
WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hWindow, &winInfo, mode);
if (GetDoAnimateMinimize()) {
DrawAnimatedRects(hWindow, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition);
}
SetWindowPlacement(hWindow, &wndpl); // 1st set correct screen (DPI Aware)
if (hwnd) {
UINT const dpi = Scintilla_GetWindowDPI(hwnd);
if (dpi != winInfo.dpi) {
RelAdjustRectForDPI(&wndpl.rcNormalPosition, winInfo.dpi, dpi);
}
}
SetWindowPlacement(hWindow, &wndpl); // 2nd resize position to correct DPI settings
}
if (hwnd) {
SetWindowPos(hwnd, Settings.AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
s_bPrevFullScreenFlag = false;
} else { // full screen mode
s_bPrevShowMenubar = Settings.ShowMenubar;
s_bPrevShowToolbar = Settings.ShowToolbar;
s_bPrevShowStatusbar = Settings.ShowStatusbar;
s_bPrevAlwaysOnTop = Settings.AlwaysOnTop;
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,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
Settings.ShowMenubar = Settings.ShowToolbar = Settings.ShowStatusbar = false;
Settings.AlwaysOnTop = true;
s_bPrevFullScreenFlag = true;
}
SendWMSize(hWindow, NULL);
UpdateToolbar();
}
//=============================================================================
//
// ShowNotifyIcon()

View File

@ -109,15 +109,14 @@ bool InitApplication(const HINSTANCE hInstance);
//~bool InitToolbarWndClass(const HINSTANCE hInstance);
HWND InitInstance(const HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow);
void CreateBars(HWND hwnd, HINSTANCE hInstance);
WININFO GetFactoryDefaultWndPos(const int flagsPos);
WININFO GetWinInfoByFlag(const int flagsPos);
WININFO GetFactoryDefaultWndPos(HWND hwnd, const int flagsPos);
WININFO GetWinInfoByFlag(HWND hwnd, const int flagsPos);
int CountRunningInstances();
bool ActivatePrevInst();
bool LaunchNewInstance(HWND hwnd, LPCWSTR lpszParameter, LPCWSTR lpszFilePath);
bool RelaunchMultiInst();
bool RelaunchElevated(LPCWSTR lpNewCmdLnArgs);
bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus, bool bAutoSaveOnRelaunch);
void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode);
void ShowNotifyIcon(HWND hwnd, bool bAdd);
void SetNotifyIconTitle(HWND hwnd);
void SetSaveDone();