|
3 | 3 | #include <stdlib.h> /* malloc() */
|
4 | 4 |
|
5 | 5 | MMRect getScaledRect(MMRect input, HDC imageSource) {
|
| 6 | + // Configure DPI awareness to fetch unscaled display size |
| 7 | + DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); |
| 8 | + size_t scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN); |
| 9 | + size_t scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN); |
| 10 | + // Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect |
| 11 | + SetThreadDpiAwarenessContext(initialDpiAwareness); |
6 | 12 | size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
|
7 | 13 | size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
|
8 | 14 |
|
9 |
| - double scaleX = (double)(desktopWidth / (double)input.size.width); |
10 |
| - double scaleY = (double)(desktopHeight / (double)input.size.height); |
| 15 | + double scaleX = (double)(desktopWidth / (double)scaledDesktopWidth); |
| 16 | + double scaleY = (double)(desktopHeight / (double)scaledDesktopHeight); |
11 | 17 |
|
12 | 18 | return MMRectMake(input.origin.x, input.origin.y, input.size.width * scaleX, input.size.height * scaleY);
|
13 | 19 | }
|
14 | 20 |
|
15 | 21 | MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
|
16 | 22 | {
|
17 |
| - // Configure DPI awareness to fetch unscaled display size |
18 |
| - DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); |
19 | 23 | MMBitmapRef bitmap;
|
20 | 24 | void *data;
|
21 | 25 | HDC screen = NULL, screenMem = NULL;
|
@@ -80,8 +84,6 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
|
80 | 84 | ReleaseDC(NULL, screen);
|
81 | 85 | DeleteObject(dib);
|
82 | 86 | DeleteDC(screenMem);
|
83 |
| - // Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect |
84 |
| - SetThreadDpiAwarenessContext(initialDpiAwareness); |
85 | 87 |
|
86 | 88 | return bitmap;
|
87 | 89 | }
|
0 commit comments