Index: base/applications/magnify/appbar.c =================================================================== --- base/applications/magnify/appbar.c (revision 0) +++ base/applications/magnify/appbar.c (working copy) @@ -0,0 +1,447 @@ +/* + * ReactOS Magnify (appbar.c) + * + * Copyright 2013 Katayama Hirofumi MZ + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "magnifier.h" + +#ifdef LOGGING +#include +#define SHAppBarMessage SHAppBarMessageWrapper +#endif /* LOGGING */ + +static BOOL s_fAppRegistered = FALSE; + +UINT g_uSide = ABE_TOP; + +/* + * FUNCTION: AppBar_Size(HWND) + * + * PURPOSE: Handles updating the appbar's size and position. + * + * PARAMETERS: + * hwnd - handle of the appbar + * + * COMMENTS: + */ +void AppBar_Size(HWND hwnd) +{ + if (s_fAppRegistered) + { + APPBARDATA abd; + RECT rcWindow; + + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + + GetWindowRect(hwnd, &rcWindow); + AppBar_QuerySetPos(g_uSide, &rcWindow, &abd, TRUE); + } +} + +/* + * FUNCTION: AppBar_QueryPos + * + * PURPOSE: Asks the system if the AppBar can occupy the rectangle specified + * in lprc. The system will change the lprc rectangle to make + * it a valid rectangle on the desktop. + * + * PARAMETERS: + * hwnd - Handle to the AppBar window. + * lprc - Rectange that the AppBar is requesting to occupy. + */ +void AppBar_QueryPos(HWND hwnd, LPRECT lprc) +{ + APPBARDATA abd; + INT nWidth = 0, nHeight = 0; + + abd.hWnd = hwnd; + abd.cbSize = sizeof(APPBARDATA); + abd.rc = *lprc; + abd.uEdge = g_uSide; + + if (ABE_LEFT == abd.uEdge || ABE_RIGHT == abd.uEdge) + { + nWidth = abd.rc.right - abd.rc.left; + abd.rc.top = 0; + abd.rc.bottom = GetSystemMetrics(SM_CYSCREEN); + } + else if (ABE_TOP == abd.uEdge || ABE_BOTTOM == abd.uEdge) + { + nHeight = abd.rc.bottom - abd.rc.top; + abd.rc.left = 0; + abd.rc.right = GetSystemMetrics(SM_CXSCREEN); + } + + SHAppBarMessage(ABM_QUERYPOS, &abd); + + switch (abd.uEdge) + { + case ABE_LEFT: + abd.rc.right = abd.rc.left + nWidth; + break; + + case ABE_RIGHT: + abd.rc.left = abd.rc.right - nWidth; + break; + + case ABE_TOP: + abd.rc.bottom = abd.rc.top + nHeight; + break; + + case ABE_BOTTOM: + abd.rc.top = abd.rc.bottom - nHeight; + break; + } + + *lprc = abd.rc; +} + +/* + * FUNCTION: AppBar_QuerySetPos(UINT, LPRECT, PAPPBARDATA, BOOL) + * + * PURPOSE: Asks the system if the appbar can move itself to a particular + * side of the screen and then does move the appbar. + * + * PARAMETERS: + * uEdge - Side of the screen to move to. Can be ABE_TOP, ABE_BOTTOM, + * ABE_LEFT, or ABE_RIGHT. + * lprc - Screen rect the appbar wishes to occupy. This will be + * modified and will return the area the system will let the + * appbar occupy. + * pabd - Pointer to the APPBARDATA struct used in all appbar system + * calls. + * fMove - TRUE if the function should move the appbar, FALSE if the + * caller will move the AppBar. + */ +void AppBar_QuerySetPos(UINT uEdge, LPRECT lprc, PAPPBARDATA pabd, BOOL fMove) +{ + pabd->rc = *lprc; + pabd->uEdge = uEdge; + g_uSide = uEdge; + + AppBar_QueryPos(pabd->hWnd, &(pabd->rc)); + + SHAppBarMessage(ABM_SETPOS, pabd); + + if (fMove) + { + MoveWindow(pabd->hWnd, pabd->rc.left, pabd->rc.top, + pabd->rc.right - pabd->rc.left, + pabd->rc.bottom - pabd->rc.top, TRUE); + } +} + +/* + * FUNCTION: AppBar_PosChanged(PAPPBARDATA) + * + * PURPOSE: The system has changed our position for some reason. We need + * to recalculate the position on the screen we want to occupy + * by determining how wide or thick we are and the update the + * screen position. + * + * + * PARAMETERS: + * pabd - Pointer to the APPBARDATA structure used in all AppBar calls + * to the system. + */ +void AppBar_PosChanged(PAPPBARDATA pabd) +{ + RECT rc, rcWindow; + INT nHeight, nWidth; + + rc.top = 0; + rc.left = 0; + rc.right = GetSystemMetrics(SM_CXSCREEN); + rc.bottom = GetSystemMetrics(SM_CYSCREEN); + + GetWindowRect(pabd->hWnd, &rcWindow); + nHeight = rcWindow.bottom - rcWindow.top; + nWidth = rcWindow.right - rcWindow.left; + + switch (g_uSide) + { + case ABE_TOP: + rc.bottom = rc.top + nHeight; + break; + + case ABE_BOTTOM: + rc.top = rc.bottom - nHeight; + break; + + case ABE_LEFT: + rc.right = rc.left + nWidth; + break; + + case ABE_RIGHT: + rc.left = rc.right - nWidth; + break; + } + + AppBar_QuerySetPos(g_uSide, &rc, pabd, TRUE); +} + +LPCTSTR GetAppBarNotifyString(WPARAM wParam) +{ + static TCHAR sz[32]; + switch(wParam) + { + case ABN_STATECHANGE: return TEXT("ABN_STATECHANGE"); + case ABN_POSCHANGED: return TEXT("ABN_POSCHANGED"); + case ABN_FULLSCREENAPP: return TEXT("ABN_FULLSCREENAPP"); + case ABN_WINDOWARRANGE: return TEXT("ABN_WINDOWARRANGE"); + } + wsprintf(sz, TEXT("0x%08X"), wParam); + return sz; +} + + +/* + * FUNCTION: AppBar_Callback(HWND, UINT, WPARAM, LPARAM) + * + * PURPOSE: Handles notification messages sent from the system to our + * appbar. + * + * PARAMETERS: + * hwnd - Handle of the appbar window receiving the notification. + * uMsg - The appbar notification message that we registered. + * wParam - Contains the specific notification code. + * lParam - Extra information dependant on the notification code. + */ +void AppBar_Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ +#ifdef LOGGING + FILE *fp; + APPBARDATA abd; +#endif + + UNREFERENCED_PARAMETER(uMsg); + +#ifdef LOGGING + fp = fopen("magnify.log", "a"); + fprintf(fp, "%s: lParam = 0x%08X\n", + (char*)GetAppBarNotifyString(wParam), + (UINT)lParam); + fclose(fp); +#endif + + abd.cbSize = sizeof(abd); + abd.hWnd = hwnd; + + switch (wParam) + { + case ABN_STATECHANGE: + break; + + case ABN_FULLSCREENAPP: + if (lParam) + { + SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } + else + { + SetWindowPos(hwnd, HWND_TOPMOST, + 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } + break; + + case ABN_POSCHANGED: + AppBar_PosChanged(&abd); + break; + } +} + + +/* + * FUNCTION: AppBar_Register(HWND) + * + * PURPOSE: Registers the appbar with the system. + * + * PARAMETERS: + * hwnd - handle of the appbar to register. + * + * RETURN VALUE: + * Returns TRUE if successful, FALSE otherwise. + * + * COMMENTS: + * Sets the system wide s_fAppRegistered variable. + */ +BOOL AppBar_Register(HWND hwnd) +{ + APPBARDATA abd; + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + abd.uCallbackMessage = APPBAR_CALLBACK; + + s_fAppRegistered = (BOOL)SHAppBarMessage(ABM_NEW, &abd); + return s_fAppRegistered; +} + + +/* + * FUNCTION: AppBar_UnRegister(HWND) + * + * PARAMETERS: + * hwnd - handle of the appbar to register. + * + * RETURN VALUE: + * Returns TRUE if successful, FALSE otherwise. + * + * COMMENTS: + * Sets the system wide s_fAppRegistered variable. + */ +BOOL AppBar_UnRegister(HWND hwnd) +{ + APPBARDATA abd; + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + + s_fAppRegistered = !SHAppBarMessage(ABM_REMOVE, &abd); + + return !s_fAppRegistered; +} + + +/* + * FUNCTION: AppBar_SetSide(HWND, UINT) + * + * PURPOSE: Sets the side the AppBar is currently attached to. + * + * PARAMETERS: + * hwnd - Window handle of the appbar. + * uSide - Side of the screen to attach to. Can be ABE_TOP, ABE_BOTTOM, + * ABE_LEFT, or ABE_RIGHT. + * + * RETURN VALUE: + * TRUE if successful, FALSE otherwise. + */ +BOOL AppBar_SetSide(HWND hwnd, UINT uSide) +{ + APPBARDATA abd; + RECT rc; + + rc.top = 0; + rc.left = 0; + rc.right = GetSystemMetrics(SM_CXSCREEN); + rc.bottom = GetSystemMetrics(SM_CYSCREEN); + + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + + switch (uSide) + { + case ABE_TOP: + rc.bottom = rc.top + nWindowHeight; + break; + + case ABE_BOTTOM: + rc.top = rc.bottom - nWindowHeight; + break; + + case ABE_LEFT: + rc.right = rc.left + nWindowWidth; + break; + + case ABE_RIGHT: + rc.left = rc.right - nWindowWidth; + break; + } + + AppBar_QuerySetPos(uSide, &rc, &abd, TRUE); + + return TRUE; +} + +#ifdef LOGGING +LPCTSTR GetAppBarMessageString(DWORD dwMessage) +{ + static TCHAR sz[32]; + switch(dwMessage) + { + case ABM_NEW: return TEXT("ABM_NEW"); + case ABM_REMOVE: return TEXT("ABM_REMOVE"); + case ABM_QUERYPOS: return TEXT("ABM_QUERYPOS"); + case ABM_SETPOS: return TEXT("ABM_SETPOS"); + case ABM_GETSTATE: return TEXT("ABM_GETSTATE"); + case ABM_GETTASKBARPOS: return TEXT("ABM_GETTASKBARPOS"); + case ABM_ACTIVATE: return TEXT("ABM_ACTIVATE"); + case ABM_GETAUTOHIDEBAR: return TEXT("ABM_GETAUTOHIDEBAR"); + case ABM_SETAUTOHIDEBAR: return TEXT("ABM_SETAUTOHIDEBAR"); + case ABM_WINDOWPOSCHANGED: return TEXT("ABM_WINDOWPOSCHANGED"); + } + wsprintf(sz, TEXT("0x%08X"), dwMessage); + return sz; +} + +LPCTSTR GetAppBarEdgeString(UINT uEdge) +{ + static TCHAR sz[32]; + switch(uEdge) + { + case ABE_LEFT: return TEXT("ABE_LEFT"); + case ABE_TOP: return TEXT("ABE_TOP"); + case ABE_RIGHT: return TEXT("ABE_RIGHT"); + case ABE_BOTTOM: return TEXT("ABE_BOTTOM"); + } + wsprintf(sz, TEXT("0x%08X"), uEdge); + return sz; +} + +#undef SHAppBarMessage +UINT APIENTRY +SHAppBarMessageWrapper(DWORD dwMessage, PAPPBARDATA pData) +{ + RECT rcWorkArea, rcWindow; + UINT uResult; + FILE *fp; + + fp = fopen("magnify.log", "a"); + GetWindowRect(pData->hWnd, &rcWindow); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + fprintf(fp, "rcWindow = {%ld, %ld, %ld, %ld}, rcWorkArea = {%ld, %ld, %ld, %ld}\n", + rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom, + rcWorkArea.left, rcWorkArea.top, rcWorkArea.right, rcWorkArea.bottom); + fprintf(fp, "%s: hWnd = %08X, uEdge = %s, rc = {%ld, %ld, %ld, %ld}\n", + (char*)GetAppBarMessageString(dwMessage), + (UINT)pData->hWnd, + (char*)GetAppBarEdgeString(pData->uEdge), + pData->rc.left, + pData->rc.top, + pData->rc.right, + pData->rc.bottom); + uResult = SHAppBarMessage(dwMessage, pData); + fprintf(fp, "%s: hWnd = %08X, uEdge = %s, rc = {%ld, %ld, %ld, %ld}, result = %08X\n", + (char*)GetAppBarMessageString(dwMessage), + (UINT)pData->hWnd, + (char*)GetAppBarEdgeString(pData->uEdge), + pData->rc.left, + pData->rc.top, + pData->rc.right, + pData->rc.bottom, + uResult); + GetWindowRect(pData->hWnd, &rcWindow); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + fprintf(fp, "rcWindow = {%ld, %ld, %ld, %ld}, rcWorkArea = {%ld, %ld, %ld, %ld}\n", + rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom, + rcWorkArea.left, rcWorkArea.top, rcWorkArea.right, rcWorkArea.bottom); + fprintf(fp, "------------------------------\n"); + fclose(fp); + return uResult; +} +#endif /* LOGGING */ Index: base/applications/magnify/CMakeLists.txt =================================================================== --- base/applications/magnify/CMakeLists.txt (revision 58156) +++ base/applications/magnify/CMakeLists.txt (working copy) @@ -2,6 +2,7 @@ add_executable(magnify magnifier.c settings.c + appbar.c magnify.rc) add_pch(magnify magnifier.h) Index: base/applications/magnify/magnifier.c =================================================================== --- base/applications/magnify/magnifier.c (revision 58156) +++ base/applications/magnify/magnifier.c (working copy) @@ -4,45 +4,40 @@ * FILE: base/applications/magnify/magnifier.c * PURPOSE: Magnification of parts of the screen. * COPYRIGHT: Copyright 2007 Marc Piulachs - * + * Copyright 2013 Katayama Hirofumi MZ */ - -/* TODO: AppBar */ #include "magnifier.h" +#ifdef LOGGING +#define SHAppBarMessage SHAppBarMessageWrapper +#endif /* LOGGING */ + const TCHAR szWindowClass[] = TEXT("MAGNIFIER"); #define MAX_LOADSTRING 100 +#define REPAINT_SPEED 100 // Global Variables: -HINSTANCE hInst; // current instance +HINSTANCE hInst; // current instance HWND hMainWnd; +HWND hDesktopWindow; +TCHAR szTitle[MAX_LOADSTRING]; // The title bar text -TCHAR szTitle[MAX_LOADSTRING]; // The title bar text +static POINT cp; // Current magnified area +static POINT pMouse, pCaret, pFocus; // Last positions -#define REPAINT_SPEED 100 +static BOOL s_fMoving = FALSE; +static POINT s_ptHotSpot; -HWND hDesktopWindow = NULL; +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK OptionsProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK WarningProc(HWND, UINT, WPARAM, LPARAM); -//Current magnified area -POINT cp; - -//Last positions -POINT pMouse; -POINT pCaret; -POINT pFocus; - -// Forward declarations of functions included in this code module: -ATOM MyRegisterClass(HINSTANCE hInstance); -BOOL InitInstance(HINSTANCE, int); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK OptionsProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK WarningProc(HWND, UINT, WPARAM, LPARAM); - -int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - // TODO: Place code here. MSG msg; HACCEL hAccelTable; @@ -51,6 +46,7 @@ // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + MyRegisterClass(hInstance); // Perform application initialization: @@ -75,7 +71,6 @@ } - /* * FUNCTION: MyRegisterClass() * @@ -119,43 +114,45 @@ */ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { - RECT rcWorkArea; - hInst = hInstance; // Store instance handle in our global variable + hInst = hInstance; // Store instance handle in our global variable - SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + /* Load settings from registry */ + LoadSettings(); - /* Create the Window */ - hMainWnd = CreateWindowEx( - WS_EX_TOPMOST | WS_EX_PALETTEWINDOW, - szWindowClass, - szTitle, - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - (rcWorkArea.right - rcWorkArea.left) * 2 / 3, - 200, - NULL, - NULL, - hInstance, - NULL); + /* Create the Window */ + hMainWnd = CreateWindowEx( + WS_EX_TOPMOST | WS_EX_PALETTEWINDOW, + szWindowClass, szTitle, + WS_OVERLAPPEDWINDOW, + nWindowX, nWindowY, nWindowCX, nWindowCY, + NULL, + NULL, + hInstance, + NULL); - if (!hMainWnd) - { - return FALSE; - } + if (!hMainWnd) + { + return FALSE; + } - ShowWindow(hMainWnd, (bStartMinimized) ? SW_MINIMIZE : nCmdShow); - UpdateWindow(hMainWnd); + if (bDocked) + { + AppBar_Register(hMainWnd); + AppBar_SetSide(hMainWnd, nDockPosition); + } - if (bShowWarning) - { - DialogBox (hInstance, MAKEINTRESOURCE(IDD_WARNINGDIALOG), hMainWnd, (DLGPROC)WarningProc); - } + ShowWindow(hMainWnd, (bStartMinimized) ? SW_MINIMIZE : nCmdShow); + UpdateWindow(hMainWnd); - return TRUE; + if (bShowWarning) + { + DialogBox(hInstance, MAKEINTRESOURCE(IDD_WARNINGDIALOG), hMainWnd, WarningProc); + } + + return TRUE; } -void Refresh () +void Refresh(void) { if (!IsIconic(hMainWnd)) { @@ -180,7 +177,7 @@ int Width, Height, AppWidth, AppHeight; LONG blitAreaWidth, blitAreaHeight, blitAreaX, blitAreaY; - desktopHdc = GetWindowDC (hDesktopWindow); + desktopHdc = GetWindowDC(hDesktopWindow); GetClientRect(hMainWnd, &appRect); GetWindowRect(hDesktopWindow, &R); @@ -222,8 +219,8 @@ pMouse.y - iinfo.yHotspot, // - 10, cinfo.hCursor); - Width = (R.right - R.left); - Height = (R.bottom - R.top); + Width = R.right - R.left; + Height = R.bottom - R.top; AppWidth = (appRect.right - appRect.left); AppHeight = (appRect.bottom - appRect.top); @@ -278,100 +275,410 @@ DeleteObject(iinfo.hbmMask); if (iinfo.hbmColor) DeleteObject(iinfo.hbmColor); - SelectObject (HdcStrech, hOld); - DeleteObject (HbmpStrech); - DeleteDC (HdcStrech); + SelectObject(HdcStrech, hOld); + DeleteObject(HbmpStrech); + DeleteDC(HdcStrech); ReleaseDC(hDesktopWindow, desktopHdc); } -/* - * FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) - * - * PURPOSE: Processes messages for the main window. - * - * WM_COMMAND - process the application menu - * WM_PAINT - Paint the main window - * WM_DESTROY - post a quit message and return - * - */ -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +static void +OnActivate(HWND hwnd, UINT uState) { - int wmId; + UNREFERENCED_PARAMETER(uState); + if (bDocked) + { + APPBARDATA abd; + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + abd.lParam = 0; + SHAppBarMessage(ABM_ACTIVATE, &abd); + } +} - switch (message) +static void +OnWindowPosChanged(HWND hwnd, CONST WINDOWPOS *pwp) +{ + if (bDocked) { - case WM_TIMER: + APPBARDATA abd; + abd.cbSize = sizeof(APPBARDATA); + abd.hWnd = hwnd; + abd.lParam = 0; + SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd); + } +} + +static void +OnSize(HWND hwnd) +{ + RECT rcWindow; + + if (s_fMoving) + { + return; + } + + GetWindowRect(hwnd, &rcWindow); + if (bDocked) + { + AppBar_Size(hwnd); + + if (g_uSide == ABE_TOP || g_uSide == ABE_BOTTOM) { - POINT pNewMouse; - POINT pNewCaret; - POINT pNewFocus; - HWND hwnd1, hwnd2, hwnd3; - DWORD a, b; - RECT controlRect; + nWindowHeight = rcWindow.bottom - rcWindow.top; + } + else if (g_uSide == ABE_LEFT || g_uSide == ABE_RIGHT) + { + nWindowWidth = rcWindow.right - rcWindow.left; + } + } + else + { + nWindowCX = rcWindow.right - rcWindow.left; + nWindowCY = rcWindow.bottom - rcWindow.top; + } +} - //Get current mouse position - GetCursorPos (&pNewMouse); +static void +OnMove(HWND hwnd) +{ + RECT rcWindow; - //Get caret position - hwnd1 = GetForegroundWindow (); - a = GetWindowThreadProcessId(hwnd1, NULL); - b = GetCurrentThreadId(); - AttachThreadInput (a, b, TRUE); - hwnd2 = GetFocus(); + GetWindowRect(hwnd, &rcWindow); + if (bDocked) + { + if (s_fMoving) + { + return; + } + AppBar_Size(hwnd); + } + else + { + nWindowX = rcWindow.left; + nWindowY = rcWindow.top; + } +} - GetCaretPos( &pNewCaret); - ClientToScreen (hwnd2, (LPPOINT) &pNewCaret); - AttachThreadInput (a, b, FALSE); +static void +OnTimer(HWND hwnd, UINT uTimerID) +{ + POINT pNewMouse; + POINT pNewCaret; + POINT pNewFocus; + HWND hwnd1, hwnd2, hwnd3; + DWORD a, b; + RECT controlRect; - //Get current control focus - hwnd3 = GetFocus (); - GetWindowRect (hwnd3 , &controlRect); - pNewFocus.x = controlRect.left; - pNewFocus.y = controlRect.top; + if (uTimerID != IDT_REPAINT) + return; - //If mouse has moved .... - if (((pMouse.x != pNewMouse.x) || (pMouse.y != pNewMouse.y)) && bFollowMouse) + GetCursorPos(&pNewMouse); + + hwnd1 = GetForegroundWindow(); + a = GetWindowThreadProcessId(hwnd1, NULL); + b = GetCurrentThreadId(); + AttachThreadInput (a, b, TRUE); + hwnd2 = GetFocus(); + + GetCaretPos(&pNewCaret); + ClientToScreen(hwnd2, (LPPOINT) &pNewCaret); + AttachThreadInput(a, b, FALSE); + + hwnd3 = GetFocus(); + GetWindowRect (hwnd3 , &controlRect); + pNewFocus.x = controlRect.left; + pNewFocus.y = controlRect.top; + + if ((pMouse.x != pNewMouse.x || pMouse.y != pNewMouse.y) && bFollowMouse) + { + pMouse = pNewMouse; + cp = pNewMouse; + Refresh(); + } + else if ((pCaret.x != pNewCaret.x || pCaret.y != pNewCaret.y) && bFollowCaret) + { + pCaret = pNewCaret; + cp = pNewCaret; + Refresh(); + } + else if ((pFocus.x != pNewFocus.x || pFocus.y != pNewFocus.y) && bFollowFocus) + { + pFocus = pNewFocus; + cp = pNewFocus; + Refresh(); + } +} + +static LRESULT +OnNcHitTest(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + LRESULT lHitTest = DefWindowProc(hwnd, WM_NCHITTEST, wParam, lParam); + + if (bDocked) + { + if (lHitTest == HTBOTTOM && g_uSide == ABE_TOP) + return HTBOTTOM; + + if (lHitTest == HTTOP && g_uSide == ABE_BOTTOM) + return HTTOP; + + if (lHitTest == HTRIGHT && g_uSide == ABE_LEFT) + return HTRIGHT; + + if (lHitTest == HTLEFT && g_uSide == ABE_RIGHT) + return HTLEFT; + + switch (lHitTest) + { + case HTMENU: + case HTCLOSE: + return lHitTest; + + default: + return HTCLIENT; + } + } + else + { + if (lHitTest == HTCAPTION) + { + return HTCLIENT; + } + return lHitTest; + } +} + +static void +OnLButton(HWND hwnd, BOOL bDown) +{ + POINT pt; + RECT rc; + if (bDown) + { + s_fMoving = TRUE; + SetCapture(hwnd); + + GetCursorPos(&pt); + GetWindowRect(hwnd, &rc); + pt.x -= rc.left; + pt.y -= rc.top; + s_ptHotSpot = pt; + } + else + { + if (s_fMoving) + { + ReleaseCapture(); + s_fMoving = FALSE; + } + } +} + +static void +OnMouseMove(HWND hwnd, INT x, INT y) +{ + INT dx, dy; + RECT rcWindow, rcWorkArea, rcDrag; + SIZE sizWindow; + POINT ptCursor = {x, y}; + WORD horiz = ABE_NONE, vert = ABE_NONE; + + if (!s_fMoving) + { + return; + } + + ClientToScreen(hwnd, &ptCursor); + + GetWindowRect(hwnd, &rcWindow); + sizWindow.cx = rcWindow.right - rcWindow.left; + sizWindow.cy = rcWindow.bottom - rcWindow.top; + + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + if (bDocked) + { + switch (nDockPosition) + { + case ABE_LEFT: + rcWorkArea.left -= sizWindow.cx; + break; + + case ABE_RIGHT: + rcWorkArea.right += sizWindow.cx; + break; + + case ABE_TOP: + rcWorkArea.top -= sizWindow.cy; + break; + + case ABE_BOTTOM: + rcWorkArea.bottom += sizWindow.cy; + break; + } + } + +#define MARGIN 100 + if (ptCursor.x < rcWorkArea.left + MARGIN) + { + dx = ptCursor.x - rcWorkArea.left; + horiz = ABE_LEFT; + } + else if (ptCursor.x > rcWorkArea.right - MARGIN) + { + dx = rcWorkArea.right - ptCursor.x; + horiz = ABE_RIGHT; + } + else + { + dx = 0xFFFF; + } + + if (ptCursor.y < rcWorkArea.top + MARGIN) + { + dy = ptCursor.y - rcWorkArea.top; + vert = ABE_TOP; + } + else if (ptCursor.y > rcWorkArea.bottom - MARGIN) + { + dy = rcWorkArea.bottom - ptCursor.y; + vert = ABE_BOTTOM; + } + else + { + dy = 0xFFFF; + } + + if (dx < dy) + { + rcDrag.top = rcWorkArea.top; + rcDrag.bottom = rcWorkArea.bottom; + if (horiz == ABE_LEFT) + { + rcDrag.left = rcWorkArea.left; + rcDrag.right = rcDrag.left + nWindowWidth; + } + else if (horiz == ABE_RIGHT) + { + rcDrag.right = rcWorkArea.right; + rcDrag.left = rcDrag.right - nWindowWidth; + } + else + { + if (bDocked) { - //Update to new position - pMouse = pNewMouse; - cp = pNewMouse; - Refresh(); + s_ptHotSpot.x = nWindowCX / 2; + s_ptHotSpot.y = nWindowCY / 2; } - else if (((pCaret.x != pNewCaret.x) || (pCaret.y != pNewCaret.y)) && bFollowCaret) + rcDrag.left = ptCursor.x - s_ptHotSpot.x; + rcDrag.top = ptCursor.y - s_ptHotSpot.y; + rcDrag.right = rcDrag.left + nWindowCX; + rcDrag.bottom = rcDrag.top + nWindowCY; + } + g_uSide = horiz; + } + else + { + rcDrag.left = rcWorkArea.left; + rcDrag.right = rcWorkArea.right; + if (vert == ABE_TOP) + { + rcDrag.top = rcWorkArea.top; + rcDrag.bottom = rcDrag.top + nWindowHeight; + } + else if (vert == ABE_BOTTOM) + { + rcDrag.bottom = rcWorkArea.bottom; + rcDrag.top = rcDrag.bottom - nWindowHeight; + } + else + { + if (bDocked) { - //Update to new position - pCaret = pNewCaret; - cp = pNewCaret; - Refresh(); + s_ptHotSpot.x = nWindowCX / 2; + s_ptHotSpot.y = nWindowCY / 2; } - else if (((pFocus.x != pNewFocus.x) || (pFocus.y != pNewFocus.y)) && bFollowFocus) - { - //Update to new position - pFocus = pNewFocus; - cp = pNewFocus; - Refresh(); - } + rcDrag.left = ptCursor.x - s_ptHotSpot.x; + rcDrag.top = ptCursor.y - s_ptHotSpot.y; + rcDrag.right = rcDrag.left + nWindowCX; + rcDrag.bottom = rcDrag.top + nWindowCY; } + g_uSide = vert; + } + + if (g_uSide != ABE_NONE) + { + if (!bDocked) + { + bDocked = TRUE; + AppBar_Register(hwnd); + } + + AppBar_SetSide(hMainWnd, g_uSide); + nDockPosition = g_uSide; + + AppBar_QueryPos(hwnd, &rcDrag); + MoveWindow(hwnd, rcDrag.left, rcDrag.top, + rcDrag.right - rcDrag.left, + rcDrag.bottom - rcDrag.top, + TRUE); + } + else + { + if (bDocked) + { + bDocked = FALSE; + AppBar_UnRegister(hwnd); + } + MoveWindow(hwnd, rcDrag.left, rcDrag.top, + rcDrag.right - rcDrag.left, + rcDrag.bottom - rcDrag.top, + TRUE); + } +} + +/* + * FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) + * + * PURPOSE: Processes messages for the main window. + * + * WM_COMMAND - process the application menu + * WM_PAINT - Paint the main window + * WM_DESTROY - post a quit message and return + */ +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + int wmId; + + switch (message) + { + case WM_TIMER: + OnTimer(hWnd, (UINT)wParam); break; + case WM_COMMAND: wmId = LOWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_OPTIONS: - DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOGOPTIONS), hWnd, (DLGPROC)OptionsProc); + DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOGOPTIONS), hWnd, OptionsProc); break; + case IDM_ABOUT: - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)AboutProc); + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, AboutProc); break; + case IDM_EXIT: DestroyWindow(hWnd); break; + default: return DefWindowProc(hWnd, message, wParam, lParam); } break; - case WM_PAINT: + + case WM_PAINT: { PAINTSTRUCT PaintStruct; HDC dc; @@ -379,26 +686,66 @@ Draw(dc); EndPaint(hWnd, &PaintStruct); } - break; - case WM_ERASEBKGND: + break; + + case WM_ERASEBKGND: //handle WM_ERASEBKGND by simply returning non-zero because we did all the drawing in WM_PAINT. - break; + break; + case WM_DESTROY: //Save settings to registry - SaveSettings (); - KillTimer (hWnd , 1); + if (bDocked) + { + AppBar_UnRegister(hWnd); + } + SaveSettings(); + KillTimer(hWnd, IDT_REPAINT); PostQuitMessage(0); break; + case WM_CREATE: - //Load settings from registry - LoadSettings (); + //Get the desktop window + hDesktopWindow = GetDesktopWindow(); - //Get the desktop window - hDesktopWindow = GetDesktopWindow(); + //Set the timer + SetTimer(hWnd, IDT_REPAINT, REPAINT_SPEED, NULL); + break; - //Set the timer - SetTimer (hWnd , 1, REPAINT_SPEED , NULL); - break; + case WM_ACTIVATE: + OnActivate(hWnd, LOWORD(wParam)); + break; + + case WM_WINDOWPOSCHANGED: + OnWindowPosChanged(hWnd, (LPWINDOWPOS)lParam); + return DefWindowProc(hWnd, message, wParam, lParam); + + case WM_SIZE: + OnSize(hWnd); + break; + + case WM_MOVE: + OnMove(hWnd); + break; + + case WM_NCHITTEST: + return OnNcHitTest(hWnd, wParam, lParam); + + case WM_LBUTTONDOWN: + OnLButton(hWnd, TRUE); + break; + + case WM_LBUTTONUP: + OnLButton(hWnd, FALSE); + break; + + case WM_MOUSEMOVE: + OnMouseMove(hWnd, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam)); + break; + + case APPBAR_CALLBACK: + AppBar_Callback(hWnd, message, wParam, lParam); + break; + default: return DefWindowProc(hWnd, message, wParam, lParam); } @@ -478,45 +825,55 @@ /* unimplemented */ MessageBox(hDlg , TEXT("Magnifier help not available yet!") , TEXT("Help") , MB_OK); break; + case IDC_ZOOM: if(HIWORD(wParam) == CBN_SELCHANGE) { HWND hCombo = GetDlgItem(hDlg,IDC_ZOOM); /* Get index of current selection and the text of that selection. */ - iZoom = SendMessage( hCombo, CB_GETCURSEL, (WPARAM) wParam, (LPARAM) lParam ) + 1; + iZoom = SendMessage(hCombo, CB_GETCURSEL, (WPARAM) wParam, (LPARAM) lParam ) + 1; //Update the magnigier UI - Refresh (); + Refresh(); } break; + case IDC_INVERTCOLORSCHECK: - bInvertColors = IsDlgButtonChecked (hDlg, IDC_INVERTCOLORSCHECK); - Refresh (); + bInvertColors = IsDlgButtonChecked(hDlg, IDC_INVERTCOLORSCHECK); + Refresh(); break; + case IDC_FOLLOWMOUSECHECK: - bFollowMouse = IsDlgButtonChecked (hDlg, IDC_FOLLOWMOUSECHECK); + bFollowMouse = IsDlgButtonChecked(hDlg, IDC_FOLLOWMOUSECHECK); break; + case IDC_FOLLOWKEYBOARDCHECK: - bFollowFocus = IsDlgButtonChecked (hDlg, IDC_FOLLOWKEYBOARDCHECK); + bFollowFocus = IsDlgButtonChecked(hDlg, IDC_FOLLOWKEYBOARDCHECK); break; + case IDC_FOLLOWTEXTEDITINGCHECK: - bFollowCaret = IsDlgButtonChecked (hDlg, IDC_FOLLOWTEXTEDITINGCHECK); + bFollowCaret = IsDlgButtonChecked(hDlg, IDC_FOLLOWTEXTEDITINGCHECK); break; + case IDC_STARTMINIMIZEDCHECK: - bStartMinimized = IsDlgButtonChecked (hDlg, IDC_STARTMINIMIZEDCHECK); + bStartMinimized = IsDlgButtonChecked(hDlg, IDC_STARTMINIMIZEDCHECK); break; + case IDC_SHOWMAGNIFIER: - bShowMagnifier = IsDlgButtonChecked (hDlg, IDC_SHOWMAGNIFIERCHECK); - if (bShowMagnifier){ - ShowWindow (hMainWnd , SW_SHOW); - }else{ - ShowWindow (hMainWnd , SW_HIDE); + bShowMagnifier = IsDlgButtonChecked(hDlg, IDC_SHOWMAGNIFIERCHECK); + if (bShowMagnifier) + { + ShowWindow(hMainWnd , SW_SHOW); } + else + { + ShowWindow(hMainWnd , SW_HIDE); + } break; } } - return (INT_PTR)FALSE; + return FALSE; } // Message handler for warning box. @@ -527,20 +884,21 @@ switch (message) { case WM_INITDIALOG: - return (INT_PTR)TRUE; + return TRUE; + case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_SHOWWARNINGCHECK: - bShowWarning = !IsDlgButtonChecked (hDlg, IDC_SHOWWARNINGCHECK); + bShowWarning = !IsDlgButtonChecked(hDlg, IDC_SHOWWARNINGCHECK); break; } if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; + return TRUE; } break; } - return (INT_PTR)FALSE; + return FALSE; } Index: base/applications/magnify/magnifier.h =================================================================== --- base/applications/magnify/magnifier.h (revision 58156) +++ base/applications/magnify/magnifier.h (working copy) @@ -1,7 +1,8 @@ /* - * WineCalc (magnifier.h) + * ReactOS Magnify (magnifier.h) * * Copyright 2007 Marc Piulachs + * Copyright 2013 Katayama Hirofumi MZ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,9 +18,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - -////////////////////////////////////////////////////////////////// - #include #include #include @@ -38,5 +36,40 @@ extern BOOL bStartMinimized; extern BOOL bShowMagnifier; +extern BOOL bDocked; + +#define ABE_NONE 0xFFFF +extern INT nDockPosition; + +/* undocked position and size */ +extern INT nWindowX, nWindowY; +extern INT nWindowCX, nWindowCY; + +/* docked size */ +extern INT nWindowWidth, nWindowHeight; + void LoadSettings(void); void SaveSettings(void); + +#define APPBAR_CALLBACK (WM_USER + 1010) + +/* Timer IDs */ +#define IDT_REPAINT 1 + +/* AppBar */ +extern UINT g_uSide; +void AppBar_Size(HWND); +void AppBar_QueryPos(HWND, LPRECT); +void AppBar_QuerySetPos(UINT, LPRECT, PAPPBARDATA, BOOL); +void AppBar_Callback(HWND, UINT, WPARAM, LPARAM); +void AppBar_PosChanged(PAPPBARDATA); +BOOL AppBar_UnRegister(HWND hwnd); +BOOL AppBar_Register(HWND hwnd); +BOOL AppBar_SetSide(HWND hwnd, UINT uSide); + +#define LOGGING 1 + +#ifdef LOGGING +UINT APIENTRY +SHAppBarMessageWrapper(DWORD dwMessage, PAPPBARDATA pData); +#endif /* LOGGING */ Index: base/applications/magnify/settings.c =================================================================== --- base/applications/magnify/settings.c (revision 58156) +++ base/applications/magnify/settings.c (working copy) @@ -1,7 +1,25 @@ - +/* + * ReactOS Magnify (settings.c) + * + * Copyright 2013 Katayama Hirofumi MZ + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "magnifier.h" -int iZoom = 3; +int iZoom = 2; /* default is 200% */ BOOL bShowWarning = TRUE; @@ -13,76 +31,203 @@ BOOL bStartMinimized = FALSE; BOOL bShowMagnifier = TRUE; +BOOL bDocked = FALSE; +INT nDockPosition = ABE_TOP; + +/* undocked position and size */ +INT nWindowX = CW_USEDEFAULT, nWindowY = CW_USEDEFAULT; +INT nWindowCX = 600, nWindowCY = 200; + +/* docked size */ +INT nWindowWidth = 150, nWindowHeight = 150; + +static const TCHAR + szMagnifyKey[] = _T("Software\\Microsoft\\Magnify"), + szScreenMagnifierKey[] = _T("Software\\Microsoft\\ScreenMagnifier"); + +static const TCHAR + szStationaryMagLevel[] = _T("StationaryMagLevel"), + szShowWarning[] = _T("ShowWarning"), + szStationaryInvertColors[] = _T("StationaryInvertColors"), + szStationaryStartMinimized[] = _T("StationaryStartMinimized"), + szStationaryTrackCursor[] = _T("StationaryTrackCursor"), + szStationaryTrackFocus[] = _T("StationaryTrackFocus"), + szStationaryTrackSecondaryFocus[] = _T("StationaryTrackSecondaryFocus"), + szStationaryTrackText[] = _T("StationaryTrackText"); + +static const TCHAR + szClassicDocked[] = _T("ClassicDocked"), + szClassicDockPosition[] = _T("ClassicDockPosition"), + szClassicWindowCX[] = _T("ClassicWindowCX"), + szClassicWindowCY[] = _T("ClassicWindowCY"), + szClassicWindowHeight[] = _T("ClassicWindowHeight"), + szClassicWindowWidth[] = _T("ClassicWindowWidth"), + szClassicWindowX[] = _T("ClassicWindowX"), + szClassicWindowY[] = _T("ClassicWindowY"); + +static BOOL +QueryValue(HKEY key, LPCTSTR name, LONG *value) +{ + DWORD len; + LONG result; + result = RegQueryValueEx(key, name, 0, 0, (BYTE *)value, &len); + return ERROR_SUCCESS == result; +} + +static BOOL +SetValue(HKEY key, LPCTSTR name, LONG *value) +{ + LONG result; + result = RegSetValueEx(key, name, 0, REG_DWORD, (BYTE *)value, sizeof(LONG)); + return ERROR_SUCCESS == result; +} + +static BOOL +CreateKey(HKEY key, LPCTSTR subkey, HKEY *newkey) +{ + LONG result; + result = RegCreateKeyEx(key, subkey, 0, _T(""), 0, KEY_WRITE, NULL, newkey, NULL); + return ERROR_SUCCESS == result; +} + void LoadSettings() { - HKEY hkey; - LONG value; - ULONG len; + HKEY hkey; + LONG value; - RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Magnify"), 0, - _T(""), 0, KEY_READ, NULL, &hkey, NULL); + /* + * Magnify key + */ + RegOpenKeyEx(HKEY_CURRENT_USER, szMagnifyKey, 0, KEY_READ, &hkey); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryMagLevel"), 0, 0, (BYTE *)&value, &len)) - { - if(value >= 0 && value <= 9) - iZoom = value; - } + if (QueryValue(hkey, szStationaryMagLevel, &value)) + { + if (value >= 0 && value <= 9) + iZoom = value; + } - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("ShowWarning"), 0, 0, (BYTE *)&value, &len)) - bShowWarning = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szShowWarning, &value)) + bShowWarning = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryInvertColors"), 0, 0, (BYTE *)&value, &len)) - bInvertColors = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryInvertColors, &value)) + bInvertColors = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryStartMinimized"), 0, 0, (BYTE *)&value, &len)) - bStartMinimized = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryStartMinimized, &value)) + bStartMinimized = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryTrackCursor"), 0, 0, (BYTE *)&value, &len)) - bFollowMouse = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryTrackCursor, &value)) + bFollowMouse = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryTrackFocus"), 0, 0, (BYTE *)&value, &len)) - bFollowFocus = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryTrackFocus, &value)) + bFollowFocus = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, 0, (BYTE *)&value, &len)) - bFollowFocus = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryTrackSecondaryFocus, &value)) + bFollowFocus = (value == 0 ? FALSE : TRUE); - if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("StationaryTrackText"), 0, 0, (BYTE *)&value, &len)) - bFollowCaret = (value == 0 ? FALSE : TRUE); + if (QueryValue(hkey, szStationaryTrackText, &value)) + bFollowCaret = (value == 0 ? FALSE : TRUE); - RegCloseKey(hkey); + RegCloseKey(hkey); + + /* + * ScreenMagnifier key + */ + RegOpenKeyEx(HKEY_CURRENT_USER, szScreenMagnifierKey, 0, KEY_READ, &hkey); + + if (QueryValue(hkey, szClassicDocked, &value)) + bDocked = (value == 0 ? FALSE : TRUE); + + if (QueryValue(hkey, szClassicDockPosition, &value)) + { + if (value >= 0 && value <= 3) + nDockPosition = value; + } + + if (QueryValue(hkey, szClassicWindowCX, &value)) + nWindowCX = value; + + if (QueryValue(hkey, szClassicWindowCY, &value)) + nWindowCY = value; + + if (QueryValue(hkey, szClassicWindowHeight, &value)) + nWindowHeight = value; + + if (QueryValue(hkey, szClassicWindowWidth, &value)) + nWindowWidth = value; + + if (QueryValue(hkey, szClassicWindowX, &value)) + nWindowX = value; + + if (QueryValue(hkey, szClassicWindowY, &value)) + nWindowY = value; + + RegCloseKey(hkey); } void SaveSettings() { - HKEY hkey; - LONG value; + HKEY hkey; + LONG value; - RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Magnify"), 0, - _T(""), 0, KEY_WRITE, NULL, &hkey, NULL); + /* + * Magnify key + */ + CreateKey(HKEY_CURRENT_USER, szMagnifyKey, &hkey); - value = iZoom; - RegSetValueEx(hkey, _T("StationaryMagLevel"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = iZoom; + SetValue(hkey, szStationaryMagLevel, &value); - value = bShowWarning; - RegSetValueEx(hkey, _T("ShowWarning"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bShowWarning; + SetValue(hkey, szShowWarning, &value); - value = bInvertColors; - RegSetValueEx(hkey, _T("StationaryInvertColors"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bInvertColors; + SetValue(hkey, szStationaryInvertColors, &value); - value = bStartMinimized; - RegSetValueEx(hkey, _T("StationaryStartMinimized"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bStartMinimized; + SetValue(hkey, szStationaryStartMinimized, &value); - value = bFollowMouse; - RegSetValueEx(hkey, _T("StationaryTrackCursor"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bFollowMouse; + SetValue(hkey, szStationaryTrackCursor, &value); - value = bFollowFocus; - RegSetValueEx(hkey, _T("StationaryTrackFocus"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bFollowFocus; + SetValue(hkey, szStationaryTrackFocus, &value); - value = bFollowFocus; - RegSetValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bFollowFocus; + SetValue(hkey, szStationaryTrackSecondaryFocus, &value); - value = bFollowCaret; - RegSetValueEx(hkey, _T("StationaryTrackText"), 0, REG_DWORD, (BYTE *)&value, sizeof value); + value = bFollowCaret; + SetValue(hkey, szStationaryTrackText, &value); - RegCloseKey(hkey); + RegCloseKey(hkey); + + /* + * ScreenMagnifier key + */ + CreateKey(HKEY_CURRENT_USER, szScreenMagnifierKey, &hkey); + + value = bDocked; + SetValue(hkey, szClassicDocked, &value); + + value = nDockPosition; + SetValue(hkey, szClassicDockPosition, &value); + + value = nWindowCX; + SetValue(hkey, szClassicWindowCX, &value); + + value = nWindowCY; + SetValue(hkey, szClassicWindowCY, &value); + + value = nWindowHeight; + SetValue(hkey, szClassicWindowHeight, &value); + + value = nWindowWidth; + SetValue(hkey, szClassicWindowWidth, &value); + + value = nWindowX; + SetValue(hkey, szClassicWindowX, &value); + + value = nWindowY; + SetValue(hkey, szClassicWindowY, &value); + + RegCloseKey(hkey); }