HWND hOptionsDialog;
BOOL bOptionsDialog = FALSE;
+BOOL bRecreateOffscreenDC = TRUE;
+LONG sourceWidth = 0;
+LONG sourceHeight = 0;
+HDC hdcOffscreen = NULL;
+HANDLE hbmpOld;
+HBITMAP hbmpOffscreen = NULL;
+
/* Current magnified area */
POINT cp;
POINT pMouse;
POINT pCaret;
POINT pFocus;
+HWND pCaretWnd;
+HWND pFocusWnd;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
}
}
+
+ SelectObject(hdcOffscreen, hbmpOld);
+ DeleteObject (hbmpOffscreen);
+ DeleteDC(hdcOffscreen);
+
return (int) msg.wParam;
}
void Draw(HDC aDc)
{
HDC desktopHdc = NULL;
- HDC HdcStretch;
- HANDLE hOld;
- HBITMAP HbmpStrech;
RECT sourceRect, intersectedRect;
RECT targetRect, appRect;
ICONINFO iinfo;
int AppWidth, AppHeight;
- LONG blitAreaWidth, blitAreaHeight;
if (bInvertColors)
rop = NOTSRCCOPY;
desktopHdc = GetDC(0);
GetClientRect(hMainWnd, &appRect);
- GetWindowRect(hDesktopWindow, &sourceRect);
+ AppWidth = (appRect.right - appRect.left);
+ AppHeight = (appRect.bottom - appRect.top);
ZeroMemory(&cinfo, sizeof(cinfo));
ZeroMemory(&iinfo, sizeof(iinfo));
ClientToScreen(hMainWnd, (POINT*)&targetRect.left);
ClientToScreen(hMainWnd, (POINT*)&targetRect.right);
- AppWidth = (appRect.right - appRect.left);
- AppHeight = (appRect.bottom - appRect.top);
+ if (bRecreateOffscreenDC || !hdcOffscreen)
+ {
+ bRecreateOffscreenDC = FALSE;
- blitAreaWidth = AppWidth / iZoom;
- blitAreaHeight = AppHeight / iZoom;
+ if(hdcOffscreen)
+ {
+ SelectObject(hdcOffscreen, hbmpOld);
+ DeleteObject (hbmpOffscreen);
+ DeleteDC(hdcOffscreen);
+ }
- sourceRect.left = (cp.x) - (blitAreaWidth /2);
- sourceRect.top = (cp.y) - (blitAreaHeight /2);
- sourceRect.right = sourceRect.left + blitAreaWidth;
- sourceRect.bottom = sourceRect.top + blitAreaHeight;
+ sourceWidth = AppWidth / iZoom;
+ sourceHeight = AppHeight / iZoom;
- GetBestOverlapWithMonitors(&sourceRect);
+ /* Create a memory DC compatible with client area DC */
+ hdcOffscreen = CreateCompatibleDC(desktopHdc);
- /* Create a memory DC compatible with client area DC */
- HdcStretch = CreateCompatibleDC(desktopHdc);
+ /* Create a bitmap compatible with the client area DC */
+ hbmpOffscreen = CreateCompatibleBitmap(
+ desktopHdc,
+ sourceWidth,
+ sourceHeight);
- /* Create a bitmap compatible with the client area DC */
- HbmpStrech = CreateCompatibleBitmap(
- desktopHdc,
- blitAreaWidth,
- blitAreaHeight);
+ /* Select our bitmap in memory DC and save the old one */
+ hbmpOld = SelectObject(hdcOffscreen , hbmpOffscreen);
+ }
+
+ GetWindowRect(hDesktopWindow, &sourceRect);
+ sourceRect.left = (cp.x) - (sourceWidth /2);
+ sourceRect.top = (cp.y) - (sourceHeight /2);
+ sourceRect.right = sourceRect.left + sourceWidth;
+ sourceRect.bottom = sourceRect.top + sourceHeight;
- /* Select our bitmap in memory DC and save the old one */
- hOld = SelectObject(HdcStretch , HbmpStrech);
+ GetBestOverlapWithMonitors(&sourceRect);
/* Paint the screen bitmap to our in memory DC */
BitBlt(
- HdcStretch,
+ hdcOffscreen,
0,
0,
- blitAreaWidth,
- blitAreaHeight,
+ sourceWidth,
+ sourceHeight,
desktopHdc,
sourceRect.left,
sourceRect.top,
if (IntersectRect(&intersectedRect, &sourceRect, &targetRect))
{
OffsetRect(&intersectedRect, -sourceRect.left, -sourceRect.top);
- FillRect(HdcStretch, &intersectedRect, GetStockObject(DC_BRUSH));
+ FillRect(hdcOffscreen, &intersectedRect, GetStockObject(DC_BRUSH));
}
/* Draw the mouse pointer in the right position */
DrawIcon(
- HdcStretch ,
+ hdcOffscreen ,
pMouse.x - iinfo.xHotspot - sourceRect.left, // - 10,
pMouse.y - iinfo.yHotspot - sourceRect.top, // - 10,
cinfo.hCursor);
0,
AppWidth,
AppHeight,
- HdcStretch,
+ hdcOffscreen,
0,
0,
- blitAreaWidth,
- blitAreaHeight,
+ sourceWidth,
+ sourceHeight,
SRCCOPY | NOMIRRORBITMAP);
/* Cleanup */
DeleteObject(iinfo.hbmMask);
if (iinfo.hbmColor)
DeleteObject(iinfo.hbmColor);
- SelectObject(HdcStretch, hOld);
- DeleteObject (HbmpStrech);
- DeleteDC(HdcStretch);
ReleaseDC(hDesktopWindow, desktopHdc);
}
case WM_TIMER:
{
BOOL hasMoved = FALSE;
+ HWND hwndForeground = GetForegroundWindow ();
+ DWORD threadId = GetWindowThreadProcessId(hwndForeground, NULL);
+ GUITHREADINFO guiInfo;
+ guiInfo.cbSize = sizeof(guiInfo);
+
+ GetGUIThreadInfo(threadId, &guiInfo);
if (bFollowMouse)
{
}
}
- if (bFollowCaret && !hasMoved)
+ if (bFollowCaret && hwndForeground && guiInfo.hwndCaret)
{
- POINT pNewCaret;
- HWND hwnd2;
-
- //Get caret position
- HWND hwnd1 = GetForegroundWindow ();
- DWORD a = GetWindowThreadProcessId(hwnd1, NULL);
- DWORD b = GetCurrentThreadId();
- AttachThreadInput (a, b, TRUE);
- hwnd2 = GetFocus();
-
- GetCaretPos( &pNewCaret);
- ClientToScreen (hwnd2, (LPPOINT) &pNewCaret);
- AttachThreadInput (a, b, FALSE);
+ POINT ptCaret;
+ ptCaret.x = (guiInfo.rcCaret.left + guiInfo.rcCaret.right) / 2;
+ ptCaret.y = (guiInfo.rcCaret.top + guiInfo.rcCaret.bottom) / 2;
- if (((pCaret.x != pNewCaret.x) || (pCaret.y != pNewCaret.y)))
+ if (guiInfo.hwndCaret && ((pCaretWnd != guiInfo.hwndCaret) || (pCaret.x != ptCaret.x) || (pCaret.y != ptCaret.y)))
{
//Update to new position
- pCaret = pNewCaret;
- cp = pNewCaret;
+ pCaret = ptCaret;
+ pCaretWnd = guiInfo.hwndCaret;
+ if(!hasMoved)
+ {
+ ClientToScreen (guiInfo.hwndCaret, (LPPOINT) &ptCaret);
+ cp = ptCaret;
+ }
hasMoved = TRUE;
}
}
- if (bFollowFocus && !hasMoved)
+ if (bFollowFocus && hwndForeground && guiInfo.hwndFocus)
{
- POINT pNewFocus;
- RECT controlRect;
+ POINT ptFocus;
+ RECT activeRect;
//Get current control focus
- HWND hwnd3 = GetFocus ();
- GetWindowRect (hwnd3 , &controlRect);
- pNewFocus.x = controlRect.left;
- pNewFocus.y = controlRect.top;
+ GetWindowRect (guiInfo.hwndFocus, &activeRect);
+ ptFocus.x = (activeRect.left + activeRect.right) / 2;
+ ptFocus.y = (activeRect.top + activeRect.bottom) / 2;
- if(((pFocus.x != pNewFocus.x) || (pFocus.y != pNewFocus.y)))
+ if(guiInfo.hwndFocus && ((guiInfo.hwndFocus != pFocusWnd) || (pFocus.x != ptFocus.x) || (pFocus.y != ptFocus.y)))
{
//Update to new position
- pFocus = pNewFocus;
- cp = pNewFocus;
+ pFocus = ptFocus;
+ pFocusWnd = guiInfo.hwndFocus;
+ if(!hasMoved)
+ cp = ptFocus;
hasMoved = TRUE;
}
}
break;
}
+ case WM_CONTEXTMENU:
+ TrackPopupMenu(notifyMenu, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0, hWnd, NULL);
+ break;
+
+ case WM_SIZE:
+ case WM_DISPLAYCHANGE:
+ bRecreateOffscreenDC = TRUE;
+ Refresh();
+ return DefWindowProc(hWnd, message, wParam, lParam);
+
case WM_ERASEBKGND:
// handle WM_ERASEBKGND by simply returning non-zero because we did all the drawing in WM_PAINT.
break;
break;
- case WM_CONTEXTMENU:
- {
- TrackPopupMenu(notifyMenu, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0, hWnd, NULL);
- break;
- }
-
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}