MSG msg;
HACCEL hAccel;
WNDCLASSEX wndclass;
- HMONITOR monitor;
- MONITORINFO info;
- INT x, y;
- RECT rcIntersect;
+ WINDOWPLACEMENT wp;
static const TCHAR className[] = _T("Notepad");
static const TCHAR winName[] = _T("Notepad");
aFINDMSGSTRING = (ATOM)RegisterWindowMessage(FINDMSGSTRING);
NOTEPAD_InitData(hInstance);
- NOTEPAD_LoadSettingsFromRegistry();
+ NOTEPAD_LoadSettingsFromRegistry(&wp);
ZeroMemory(&wndclass, sizeof(wndclass));
wndclass.cbSize = sizeof(wndclass);
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 */
CreateWindow(className,
winName,
WS_OVERLAPPEDWINDOW,
- x,
- y,
- Globals.main_rect.right - Globals.main_rect.left,
- Globals.main_rect.bottom - Globals.main_rect.top,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
NULL,
NULL,
Globals.hInstance,
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);
if (!HandleCommandLine(cmdline))
*
* Load settings from registry HKCU\Software\Microsoft\Notepad.
*/
-void NOTEPAD_LoadSettingsFromRegistry(void)
+void NOTEPAD_LoadSettingsFromRegistry(PWINDOWPLACEMENT pWP)
{
HKEY hKey;
HFONT hFont;
- DWORD dwPointSize, cx, cy;
- DWORD cxScreen = GetSystemMetrics(SM_CXSCREEN), cyScreen = GetSystemMetrics(SM_CYSCREEN);
+ DWORD dwPointSize;
+ DWORD x = CW_USEDEFAULT, y = CW_USEDEFAULT, cx = 0, cy = 0;
/* Set the default values */
Globals.bShowStatusBar = TRUE;
dwPointSize = 100;
Globals.lfFont.lfWeight = FW_NORMAL;
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.fMLE_is_broken = FALSE; */
QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
- QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
- QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
+ QueryDword(hKey, _T("iWindowPosX"), &x);
+ QueryDword(hKey, _T("iWindowPosY"), &y);
QueryDword(hKey, _T("iWindowPosDX"), &cx);
QueryDword(hKey, _T("iWindowPosDY"), &cy);
QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
}
- Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
- Globals.main_rect.right = Globals.main_rect.left + cx;
- Globals.main_rect.bottom = Globals.main_rect.top + cy;
+ pWP->length = sizeof(*pWP);
+ pWP->flags = 0;
+ 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"),
Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
{
{
HKEY hKey;
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,
0, NULL, 0, KEY_SET_VALUE, NULL,
SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
- SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
- SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
- SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);
- SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top);
+ SaveDword(hKey, _T("iWindowPosX"), x);
+ SaveDword(hKey, _T("iWindowPosY"), y);
+ SaveDword(hKey, _T("iWindowPosDX"), cx);
+ SaveDword(hKey, _T("iWindowPosDY"), cy);
SaveString(hKey, _T("searchString"), Globals.szFindText);
SaveString(hKey, _T("replaceString"), Globals.szReplaceText);