save window position

svn path=/trunk/; revision=32049
This commit is contained in:
Christoph von Wittich 2008-01-30 09:25:54 +00:00
parent ee02b70f0e
commit 8994a89463
4 changed files with 48 additions and 8 deletions

View file

@ -355,8 +355,8 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
case WM_CLOSE: case WM_CLOSE:
if (DoCloseFile()) { if (DoCloseFile()) {
if (Globals.hFont) if (Globals.hFont)
DeleteObject(Globals.hFont); DeleteObject(Globals.hFont);
DestroyWindow(hWnd); DestroyWindow(hWnd);
} }
break; break;
@ -369,6 +369,7 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
case WM_DESTROY: case WM_DESTROY:
SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)Globals.EditProc); SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)Globals.EditProc);
SaveSettings();
PostQuitMessage(0); PostQuitMessage(0);
break; break;
@ -544,9 +545,13 @@ static void HandleCommandLine(LPTSTR cmdline)
*/ */
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show) int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show)
{ {
MSG msg; MSG msg;
HACCEL hAccel; HACCEL hAccel;
WNDCLASSEX wndclass; WNDCLASSEX wndclass;
HMONITOR monitor;
MONITORINFO info;
INT x, y;
static const TCHAR className[] = _T("NPClass"); static const TCHAR className[] = _T("NPClass");
static const TCHAR winName[] = _T("Notepad"); static const TCHAR winName[] = _T("Notepad");
@ -574,9 +579,22 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
/* Setup windows */ /* 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 = Globals.hMainWnd =
CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, 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); NULL, NULL, Globals.hInstance, NULL);
if (!Globals.hMainWnd) if (!Globals.hMainWnd)
{ {
@ -606,6 +624,5 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
SaveSettings();
return (int) msg.wParam; return (int) msg.wParam;
} }

View file

@ -68,6 +68,7 @@ typedef struct
FINDREPLACE find; FINDREPLACE find;
WNDPROC EditProc; WNDPROC EditProc;
RECT main_rect;
} NOTEPAD_GLOBALS; } NOTEPAD_GLOBALS;
extern NOTEPAD_GLOBALS Globals; extern NOTEPAD_GLOBALS Globals;

View file

@ -3,6 +3,7 @@
<module name="notepad" type="win32gui" installbase="system32" installname="notepad.exe" unicode="yes"> <module name="notepad" type="win32gui" installbase="system32" installname="notepad.exe" unicode="yes">
<include base="notepad">.</include> <include base="notepad">.</include>
<define name="_WIN32_IE">0x0501</define> <define name="_WIN32_IE">0x0501</define>
<define name="_WIN32_WINNT">0x501</define>
<library>kernel32</library> <library>kernel32</library>
<library>user32</library> <library>user32</library>
<library>gdi32</library> <library>gdi32</library>

View file

@ -107,6 +107,14 @@ void LoadSettings(void)
HKEY hKey = NULL; HKEY hKey = NULL;
HFONT hFont; HFONT hFont;
DWORD dwPointSize = 0; 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) 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("fWrap"), &Globals.bWrapLongLines);
QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); 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*/ Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/
if (dwPointSize != 0) if (dwPointSize != 0)
@ -158,6 +174,8 @@ void SaveSettings(void)
HKEY hKey; HKEY hKey;
DWORD dwDisposition; DWORD dwDisposition;
GetWindowRect(Globals.hMainWnd, &Globals.main_rect);
if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition)
== ERROR_SUCCESS) == ERROR_SUCCESS)
{ {
@ -176,7 +194,10 @@ void SaveSettings(void)
SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight)); SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0); SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 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); RegCloseKey(hKey);
} }