diff --git a/reactos/base/applications/notepad/main.c b/reactos/base/applications/notepad/main.c index 2fdc8b84f0b..aabcf30495b 100644 --- a/reactos/base/applications/notepad/main.c +++ b/reactos/base/applications/notepad/main.c @@ -355,8 +355,8 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, case WM_CLOSE: if (DoCloseFile()) { - if (Globals.hFont) - DeleteObject(Globals.hFont); + if (Globals.hFont) + DeleteObject(Globals.hFont); DestroyWindow(hWnd); } break; @@ -369,6 +369,7 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, case WM_DESTROY: SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)Globals.EditProc); + SaveSettings(); PostQuitMessage(0); break; @@ -544,9 +545,13 @@ static void HandleCommandLine(LPTSTR cmdline) */ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show) { - MSG msg; - HACCEL hAccel; - WNDCLASSEX wndclass; + MSG msg; + HACCEL hAccel; + WNDCLASSEX wndclass; + HMONITOR monitor; + MONITORINFO info; + INT x, y; + static const TCHAR className[] = _T("NPClass"); static const TCHAR winName[] = _T("Notepad"); @@ -574,9 +579,22 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh /* 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 (Globals.main_rect.left >= info.rcWork.right || + Globals.main_rect.top >= info.rcWork.bottom || + Globals.main_rect.right < info.rcWork.left || + Globals.main_rect.bottom < info.rcWork.top) + x = y = CW_USEDEFAULT; + Globals.hMainWnd = CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, + x, y, Globals.main_rect.right - Globals.main_rect.left, + Globals.main_rect.bottom - Globals.main_rect.top, NULL, NULL, Globals.hInstance, NULL); if (!Globals.hMainWnd) { @@ -606,6 +624,5 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh DispatchMessage(&msg); } } - SaveSettings(); return (int) msg.wParam; } diff --git a/reactos/base/applications/notepad/main.h b/reactos/base/applications/notepad/main.h index 05f85270294..35a1a9cc37b 100644 --- a/reactos/base/applications/notepad/main.h +++ b/reactos/base/applications/notepad/main.h @@ -68,6 +68,7 @@ typedef struct FINDREPLACE find; WNDPROC EditProc; + RECT main_rect; } NOTEPAD_GLOBALS; extern NOTEPAD_GLOBALS Globals; diff --git a/reactos/base/applications/notepad/notepad.rbuild b/reactos/base/applications/notepad/notepad.rbuild index cd8f010d08e..394b3120418 100644 --- a/reactos/base/applications/notepad/notepad.rbuild +++ b/reactos/base/applications/notepad/notepad.rbuild @@ -3,6 +3,7 @@ . 0x0501 + 0x501 kernel32 user32 gdi32 diff --git a/reactos/base/applications/notepad/settings.c b/reactos/base/applications/notepad/settings.c index 1e6ee80fd3a..12e415939f3 100644 --- a/reactos/base/applications/notepad/settings.c +++ b/reactos/base/applications/notepad/settings.c @@ -107,6 +107,14 @@ void LoadSettings(void) HKEY hKey = NULL; HFONT hFont; DWORD dwPointSize = 0; + INT base_length, dx, dy; + + base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))? + GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); + + dx = base_length * .95; + dy = dx * 3 / 4; + SetRect( &Globals.main_rect, 0, 0, dx, dy ); if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) { @@ -126,6 +134,14 @@ void LoadSettings(void) QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines); QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); + QueryByte(hKey, _T("iWindowPosX"), (LPBYTE)&Globals.main_rect.left); + QueryByte(hKey, _T("iWindowPosX"), (LPBYTE)&Globals.main_rect.top); + QueryByte(hKey, _T("iWindowPosDX"), (LPBYTE)&dx); + QueryByte(hKey, _T("iWindowPosDY"), (LPBYTE)&dy); + + Globals.main_rect.right = Globals.main_rect.left + dx; + Globals.main_rect.bottom = Globals.main_rect.top + dy; + Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/ if (dwPointSize != 0) @@ -158,6 +174,8 @@ void SaveSettings(void) HKEY hKey; DWORD dwDisposition; + GetWindowRect(Globals.hMainWnd, &Globals.main_rect); + if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) { @@ -176,7 +194,10 @@ void SaveSettings(void) SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight)); SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0); SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0); - + 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); RegCloseKey(hKey); }