mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 20:23:34 +00:00
[NOTEPAD] Handle serialized maximized state (#5806)
Fixes a bug where if you close Notepad while it is maximized, the next time Notepad is started it will start with its window placed as if maximized but it is still in the SW_RESTORE state and the "real normal placement" is lost. SetWindowPlacement also takes care of making sure the window is placed correctly on the monitor workarea.
This commit is contained in:
parent
07abea90d9
commit
814f3a15f9
3 changed files with 54 additions and 40 deletions
|
@ -557,10 +557,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
|
||||||
MSG msg;
|
MSG msg;
|
||||||
HACCEL hAccel;
|
HACCEL hAccel;
|
||||||
WNDCLASSEX wndclass;
|
WNDCLASSEX wndclass;
|
||||||
HMONITOR monitor;
|
WINDOWPLACEMENT wp;
|
||||||
MONITORINFO info;
|
|
||||||
INT x, y;
|
|
||||||
RECT rcIntersect;
|
|
||||||
static const TCHAR className[] = _T("Notepad");
|
static const TCHAR className[] = _T("Notepad");
|
||||||
static const TCHAR winName[] = _T("Notepad");
|
static const TCHAR winName[] = _T("Notepad");
|
||||||
|
|
||||||
|
@ -579,7 +576,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
|
||||||
aFINDMSGSTRING = (ATOM)RegisterWindowMessage(FINDMSGSTRING);
|
aFINDMSGSTRING = (ATOM)RegisterWindowMessage(FINDMSGSTRING);
|
||||||
|
|
||||||
NOTEPAD_InitData(hInstance);
|
NOTEPAD_InitData(hInstance);
|
||||||
NOTEPAD_LoadSettingsFromRegistry();
|
NOTEPAD_LoadSettingsFromRegistry(&wp);
|
||||||
|
|
||||||
ZeroMemory(&wndclass, sizeof(wndclass));
|
ZeroMemory(&wndclass, sizeof(wndclass));
|
||||||
wndclass.cbSize = sizeof(wndclass);
|
wndclass.cbSize = sizeof(wndclass);
|
||||||
|
@ -602,25 +599,14 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup windows */
|
|
||||||
|
|
||||||
monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY);
|
|
||||||
info.cbSize = sizeof(info);
|
|
||||||
GetMonitorInfoW(monitor, &info);
|
|
||||||
|
|
||||||
x = Globals.main_rect.left;
|
|
||||||
y = Globals.main_rect.top;
|
|
||||||
if (!IntersectRect(&rcIntersect, &Globals.main_rect, &info.rcWork))
|
|
||||||
x = y = CW_USEDEFAULT;
|
|
||||||
|
|
||||||
/* Globals.hMainWnd will be set in WM_CREATE handling */
|
/* Globals.hMainWnd will be set in WM_CREATE handling */
|
||||||
CreateWindow(className,
|
CreateWindow(className,
|
||||||
winName,
|
winName,
|
||||||
WS_OVERLAPPEDWINDOW,
|
WS_OVERLAPPEDWINDOW,
|
||||||
x,
|
CW_USEDEFAULT,
|
||||||
y,
|
CW_USEDEFAULT,
|
||||||
Globals.main_rect.right - Globals.main_rect.left,
|
CW_USEDEFAULT,
|
||||||
Globals.main_rect.bottom - Globals.main_rect.top,
|
CW_USEDEFAULT,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
Globals.hInstance,
|
Globals.hInstance,
|
||||||
|
@ -631,7 +617,17 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowWindow(Globals.hMainWnd, show);
|
/* Use the result of CW_USEDEFAULT if the data in the registry is not valid */
|
||||||
|
if (wp.rcNormalPosition.right == wp.rcNormalPosition.left)
|
||||||
|
{
|
||||||
|
GetWindowPlacement(Globals.hMainWnd, &wp);
|
||||||
|
}
|
||||||
|
/* Does the parent process want to force a show action? */
|
||||||
|
if (show != SW_SHOWDEFAULT)
|
||||||
|
{
|
||||||
|
wp.showCmd = show;
|
||||||
|
}
|
||||||
|
SetWindowPlacement(Globals.hMainWnd, &wp);
|
||||||
UpdateWindow(Globals.hMainWnd);
|
UpdateWindow(Globals.hMainWnd);
|
||||||
|
|
||||||
if (!HandleCommandLine(cmdline))
|
if (!HandleCommandLine(cmdline))
|
||||||
|
|
|
@ -84,7 +84,6 @@ typedef struct
|
||||||
|
|
||||||
FINDREPLACE find;
|
FINDREPLACE find;
|
||||||
WNDPROC EditProc;
|
WNDPROC EditProc;
|
||||||
RECT main_rect;
|
|
||||||
BOOL bWasModified;
|
BOOL bWasModified;
|
||||||
} NOTEPAD_GLOBALS;
|
} NOTEPAD_GLOBALS;
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@ extern NOTEPAD_GLOBALS Globals;
|
||||||
BOOL ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN *piEoln);
|
BOOL ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN *piEoln);
|
||||||
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, EOLN iEoln);
|
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, EOLN iEoln);
|
||||||
|
|
||||||
void NOTEPAD_LoadSettingsFromRegistry(void);
|
void NOTEPAD_LoadSettingsFromRegistry(PWINDOWPLACEMENT pWP);
|
||||||
void NOTEPAD_SaveSettingsToRegistry(void);
|
void NOTEPAD_SaveSettingsToRegistry(void);
|
||||||
|
|
||||||
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert);
|
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert);
|
||||||
|
|
|
@ -102,12 +102,12 @@ static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD
|
||||||
*
|
*
|
||||||
* Load settings from registry HKCU\Software\Microsoft\Notepad.
|
* Load settings from registry HKCU\Software\Microsoft\Notepad.
|
||||||
*/
|
*/
|
||||||
void NOTEPAD_LoadSettingsFromRegistry(void)
|
void NOTEPAD_LoadSettingsFromRegistry(PWINDOWPLACEMENT pWP)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
HFONT hFont;
|
HFONT hFont;
|
||||||
DWORD dwPointSize, cx, cy;
|
DWORD dwPointSize;
|
||||||
DWORD cxScreen = GetSystemMetrics(SM_CXSCREEN), cyScreen = GetSystemMetrics(SM_CYSCREEN);
|
DWORD x = CW_USEDEFAULT, y = CW_USEDEFAULT, cx = 0, cy = 0;
|
||||||
|
|
||||||
/* Set the default values */
|
/* Set the default values */
|
||||||
Globals.bShowStatusBar = TRUE;
|
Globals.bShowStatusBar = TRUE;
|
||||||
|
@ -118,10 +118,6 @@ void NOTEPAD_LoadSettingsFromRegistry(void)
|
||||||
dwPointSize = 100;
|
dwPointSize = 100;
|
||||||
Globals.lfFont.lfWeight = FW_NORMAL;
|
Globals.lfFont.lfWeight = FW_NORMAL;
|
||||||
Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
|
Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
|
||||||
Globals.main_rect.left = CW_USEDEFAULT;
|
|
||||||
Globals.main_rect.top = CW_USEDEFAULT;
|
|
||||||
cx = min((cxScreen * 3) / 4, 640);
|
|
||||||
cy = min((cyScreen * 3) / 4, 480);
|
|
||||||
|
|
||||||
/* FIXME: Globals.fSaveWindowPositions = FALSE; */
|
/* FIXME: Globals.fSaveWindowPositions = FALSE; */
|
||||||
/* FIXME: Globals.fMLE_is_broken = FALSE; */
|
/* FIXME: Globals.fMLE_is_broken = FALSE; */
|
||||||
|
@ -154,8 +150,8 @@ void NOTEPAD_LoadSettingsFromRegistry(void)
|
||||||
QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
|
QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
|
||||||
QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
|
QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
|
||||||
|
|
||||||
QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
|
QueryDword(hKey, _T("iWindowPosX"), &x);
|
||||||
QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
|
QueryDword(hKey, _T("iWindowPosY"), &y);
|
||||||
QueryDword(hKey, _T("iWindowPosDX"), &cx);
|
QueryDword(hKey, _T("iWindowPosDX"), &cx);
|
||||||
QueryDword(hKey, _T("iWindowPosDY"), &cy);
|
QueryDword(hKey, _T("iWindowPosDY"), &cy);
|
||||||
|
|
||||||
|
@ -163,10 +159,23 @@ void NOTEPAD_LoadSettingsFromRegistry(void)
|
||||||
QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
|
QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
|
pWP->length = sizeof(*pWP);
|
||||||
Globals.main_rect.right = Globals.main_rect.left + cx;
|
pWP->flags = 0;
|
||||||
Globals.main_rect.bottom = Globals.main_rect.top + cy;
|
pWP->showCmd = SW_SHOWDEFAULT;
|
||||||
|
if (cy & 0x80000000)
|
||||||
|
{
|
||||||
|
cy &= ~0x80000000;
|
||||||
|
pWP->flags |= WPF_RESTORETOMAXIMIZED;
|
||||||
|
pWP->showCmd = SW_SHOWMAXIMIZED;
|
||||||
|
}
|
||||||
|
pWP->rcNormalPosition.left = x;
|
||||||
|
pWP->rcNormalPosition.right = x + cx;
|
||||||
|
pWP->rcNormalPosition.top = y;
|
||||||
|
pWP->rcNormalPosition.bottom = y + cy;
|
||||||
|
pWP->ptMaxPosition.x = x;
|
||||||
|
pWP->ptMaxPosition.y = y;
|
||||||
|
|
||||||
|
Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
|
||||||
if (!hKey || !QueryString(hKey, _T("lfFaceName"),
|
if (!hKey || !QueryString(hKey, _T("lfFaceName"),
|
||||||
Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
|
Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
|
||||||
{
|
{
|
||||||
|
@ -228,8 +237,18 @@ void NOTEPAD_SaveSettingsToRegistry(void)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD dwDisposition;
|
DWORD dwDisposition;
|
||||||
|
WINDOWPLACEMENT wp;
|
||||||
|
UINT x, y, cx, cy;
|
||||||
|
|
||||||
|
wp.length = sizeof(wp);
|
||||||
|
GetWindowPlacement(Globals.hMainWnd, &wp);
|
||||||
|
x = wp.rcNormalPosition.left;
|
||||||
|
y = wp.rcNormalPosition.top;
|
||||||
|
cx = wp.rcNormalPosition.right - x;
|
||||||
|
cy = wp.rcNormalPosition.bottom - y;
|
||||||
|
if (wp.flags & WPF_RESTORETOMAXIMIZED)
|
||||||
|
cy |= 0x80000000;
|
||||||
|
|
||||||
GetWindowRect(Globals.hMainWnd, &Globals.main_rect);
|
|
||||||
|
|
||||||
if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey,
|
if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey,
|
||||||
0, NULL, 0, KEY_SET_VALUE, NULL,
|
0, NULL, 0, KEY_SET_VALUE, NULL,
|
||||||
|
@ -256,10 +275,10 @@ void NOTEPAD_SaveSettingsToRegistry(void)
|
||||||
SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
|
SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
|
||||||
SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
|
SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
|
||||||
SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
|
SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
|
||||||
SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
|
SaveDword(hKey, _T("iWindowPosX"), x);
|
||||||
SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
|
SaveDword(hKey, _T("iWindowPosY"), y);
|
||||||
SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);
|
SaveDword(hKey, _T("iWindowPosDX"), cx);
|
||||||
SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top);
|
SaveDword(hKey, _T("iWindowPosDY"), cy);
|
||||||
SaveString(hKey, _T("searchString"), Globals.szFindText);
|
SaveString(hKey, _T("searchString"), Globals.szFindText);
|
||||||
SaveString(hKey, _T("replaceString"), Globals.szReplaceText);
|
SaveString(hKey, _T("replaceString"), Globals.szReplaceText);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue