mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ fix: Win Positions: Monitor/Sreen vs. Work Area placements
This commit is contained in:
parent
6df6e74bbc
commit
eb156b6570
@ -2619,12 +2619,47 @@ bool SelectDefLineEndingDlg(HWND hwnd,int *iOption)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetMonitorInfoFromRect()
|
||||
//
|
||||
static void __fastcall GetMonitorInfoFromRect(const RECT* const rc, MONITORINFO* hMonitorInfo)
|
||||
{
|
||||
if (hMonitorInfo) {
|
||||
HMONITOR const hMonitor = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST);
|
||||
ZeroMemory(hMonitorInfo, sizeof(MONITORINFO));
|
||||
hMonitorInfo->cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(hMonitor, hMonitorInfo);
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// WinInfoToScreen()
|
||||
//
|
||||
void WinInfoToScreen(WININFO* pWinInfo)
|
||||
{
|
||||
if (pWinInfo) {
|
||||
MONITORINFO mi;
|
||||
RECT rc = RectFromWinInfo(pWinInfo);
|
||||
GetMonitorInfoFromRect(&rc, &mi);
|
||||
|
||||
WININFO winfo = *pWinInfo;
|
||||
winfo.x += (mi.rcWork.left - mi.rcMonitor.left);
|
||||
winfo.y += (mi.rcWork.top - mi.rcMonitor.top);
|
||||
|
||||
*pWinInfo = winfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetMyWindowPlacement()
|
||||
//
|
||||
//
|
||||
WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo)
|
||||
{
|
||||
WINDOWPLACEMENT wndpl;
|
||||
@ -2639,12 +2674,8 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo)
|
||||
wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED);
|
||||
wi.zoom = SciCall_GetZoom();
|
||||
|
||||
if (hMonitorInfo)
|
||||
{
|
||||
HMONITOR hMonitor = MonitorFromRect(&(wndpl.rcNormalPosition), MONITOR_DEFAULTTONEAREST);
|
||||
hMonitorInfo->cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(hMonitor, hMonitorInfo);
|
||||
}
|
||||
GetMonitorInfoFromRect(&(wndpl.rcNormalPosition), hMonitorInfo);
|
||||
|
||||
return wi;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -2655,13 +2686,10 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo)
|
||||
// FitIntoMonitorWorkArea()
|
||||
//
|
||||
//
|
||||
RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea)
|
||||
void FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea)
|
||||
{
|
||||
MONITORINFO mi;
|
||||
ZeroMemory(&mi, sizeof(MONITORINFO));
|
||||
mi.cbSize = sizeof(MONITORINFO);
|
||||
HMONITOR const hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST);
|
||||
GetMonitorInfo(hMonitor, &mi);
|
||||
GetMonitorInfoFromRect(pRect, &mi);
|
||||
|
||||
if (bFullWorkArea) {
|
||||
SetRect(pRect, mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
|
||||
@ -2673,9 +2701,7 @@ RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea)
|
||||
}
|
||||
else {
|
||||
WININFO wi = *pWinInfo;
|
||||
// work area coord -> monitor coord
|
||||
wi.x += (mi.rcWork.left - mi.rcMonitor.left);
|
||||
wi.y += (mi.rcWork.top - mi.rcMonitor.top);
|
||||
WinInfoToScreen(&wi);
|
||||
// fit into area
|
||||
if (wi.x < mi.rcWork.left) { wi.x = mi.rcWork.left; }
|
||||
if (wi.y < mi.rcWork.top) { wi.y = mi.rcWork.top; }
|
||||
@ -2696,8 +2722,6 @@ RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea)
|
||||
pWinInfo->cx = wi.cx;
|
||||
pWinInfo->cy = wi.cy;
|
||||
}
|
||||
|
||||
return mi.rcWork;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -37,8 +37,9 @@ bool SelectEncodingDlg(HWND,int *);
|
||||
bool RecodeDlg(HWND,int *);
|
||||
bool SelectDefLineEndingDlg(HWND,int *);
|
||||
|
||||
void WinInfoToScreen(WININFO*);
|
||||
WININFO GetMyWindowPlacement(HWND,MONITORINFO *);
|
||||
RECT FitIntoMonitorWorkArea(RECT*, WININFO*, bool);
|
||||
void FitIntoMonitorWorkArea(RECT*, WININFO*, bool);
|
||||
WINDOWPLACEMENT WindowPlacementFromInfo(HWND, const WININFO* const);
|
||||
|
||||
void DialogNewWindow(HWND,bool,bool);
|
||||
|
||||
@ -65,7 +65,6 @@ extern HMODULE g_hLngResContainer;
|
||||
extern HWND g_hwndMain;
|
||||
extern HWND g_hwndStatus;
|
||||
extern HWND g_hwndDlgFindReplace;
|
||||
extern WININFO g_WinInfo;
|
||||
extern HICON g_hDlgIcon;
|
||||
|
||||
//extern LPMALLOC g_lpMalloc;
|
||||
|
||||
@ -990,12 +990,14 @@ void EndWaitCursor()
|
||||
//
|
||||
static void __fastcall _InitWindowPosition()
|
||||
{
|
||||
RECT rc = RectFromWinInfo(&g_WinInfo);
|
||||
int const iBdrOff = IsWin10() ? 8 : 16;
|
||||
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
|
||||
WININFO winfo = INIT_WININFO;
|
||||
FitIntoMonitorWorkArea(&rc, &winfo, true); // get work area
|
||||
rc = RectFromWinInfo(&winfo);
|
||||
RECT rcMon = RectFromWinInfo(&g_WinInfo);
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMon, 0);
|
||||
|
||||
WININFO wiWorkArea = INIT_WININFO;
|
||||
FitIntoMonitorWorkArea(&rcMon, &wiWorkArea, true); // get Monitor and Work Area
|
||||
RECT const rc = RectFromWinInfo(&wiWorkArea); // use Work Area as RECT
|
||||
|
||||
if (g_flagDefaultPos == 1)
|
||||
{
|
||||
@ -1036,23 +1038,20 @@ static void __fastcall _InitWindowPosition()
|
||||
}
|
||||
else if (g_flagDefaultPos == 2 || g_flagDefaultPos == 3) // NP3 default window position
|
||||
{
|
||||
g_WinInfo.y = rc.top + 16;
|
||||
g_WinInfo.cy = rc.bottom - rc.top - 32;
|
||||
g_WinInfo.cx = (rc.right - rc.left)/2; //min(rc.right - rc.left - 32, g_WinInfo.cy);
|
||||
g_WinInfo.y = rc.top + iBdrOff;
|
||||
g_WinInfo.cy = rc.bottom - rc.top - (iBdrOff * 2);
|
||||
g_WinInfo.cx = (rc.right - rc.left) / 2; //min(rc.right - rc.left - 32, g_WinInfo.cy);
|
||||
g_WinInfo.x = (g_flagDefaultPos == 3) ? rc.left + 16 : rc.right - g_WinInfo.cx - 16;
|
||||
}
|
||||
else { // fit window into working area of current monitor
|
||||
else { // restore window, move upper left corner to Work Area
|
||||
|
||||
FitIntoMonitorWorkArea(&rc, &g_WinInfo, false);
|
||||
//rc = RectFromWinInfo(&g_WinInfo);
|
||||
//RECT rc2;
|
||||
//if (!IntersectRect(&rc2, &rc, &rcWork)) {
|
||||
// g_WinInfo.y = rcWork.top + 16;
|
||||
// g_WinInfo.cy = rcWork.bottom - rcWork.top - 32;
|
||||
// g_WinInfo.cx = min(rcWork.right - rcWork.left - 32, g_WinInfo.cy);
|
||||
// g_WinInfo.x = rcWork.right - g_WinInfo.cx - 16;
|
||||
//}
|
||||
WININFO wiWin = g_WinInfo; wiWin.cx = wiWin.cy = iBdrOff * 2; // really small
|
||||
FitIntoMonitorWorkArea(&rcMon, &wiWin, false);
|
||||
g_WinInfo.x = wiWin.x;
|
||||
g_WinInfo.y = wiWin.y;
|
||||
|
||||
}
|
||||
|
||||
g_WinCurrentWidth = g_WinInfo.cx;
|
||||
}
|
||||
|
||||
@ -1065,21 +1064,22 @@ static void __fastcall _InitWindowPosition()
|
||||
HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow)
|
||||
{
|
||||
UNUSED(pszCmdLine);
|
||||
|
||||
_InitWindowPosition();
|
||||
|
||||
|
||||
// get monitor coordinates from g_WinInfo
|
||||
RECT rc = RectFromWinInfo(&g_WinInfo);
|
||||
FitIntoMonitorWorkArea(&rc, &g_WinInfo, false);
|
||||
WININFO srcninfo = g_WinInfo;
|
||||
WinInfoToScreen(&srcninfo);
|
||||
|
||||
g_hwndMain = CreateWindowEx(
|
||||
0,
|
||||
wchWndClass,
|
||||
L"" APPNAME,
|
||||
TEXT(APPNAME),
|
||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
||||
rc.left,
|
||||
rc.top,
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top,
|
||||
srcninfo.x,
|
||||
srcninfo.y,
|
||||
srcninfo.cx,
|
||||
srcninfo.cy,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user