diff --git a/windows-snapshot-tool/bin/freeze.exe b/windows-snapshot-tool/bin/freeze.exe index 8ea7bbc..c3347ba 100755 Binary files a/windows-snapshot-tool/bin/freeze.exe and b/windows-snapshot-tool/bin/freeze.exe differ diff --git a/windows-snapshot-tool/src/ShellScalingApi.h b/windows-snapshot-tool/src/ShellScalingApi.h new file mode 100644 index 0000000..797c460 --- /dev/null +++ b/windows-snapshot-tool/src/ShellScalingApi.h @@ -0,0 +1,80 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#ifndef _SHELLSCALINGAPI_H_ +#define _SHELLSCALINGAPI_H_ + +#include +#include + +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#ifndef SCALING_ENUMS_DECLARED +typedef enum { + SCF_VALUE_NONE = 0x00, + SCF_SCALE = 0x01, + SCF_PHYSICAL = 0x02 +} SCALE_CHANGE_FLAGS; +DEFINE_ENUM_FLAG_OPERATORS(SCALE_CHANGE_FLAGS); + +typedef enum { + DEVICE_PRIMARY = 0, + DEVICE_IMMERSIVE = 1 +} DISPLAY_DEVICE_TYPE; + +#define SCALING_ENUMS_DECLARED +#endif /* SCALING_ENUMS_DECLARED */ + +#if NTDDI_VERSION >= NTDDI_WIN8 +STDAPI_(DEVICE_SCALE_FACTOR) GetScaleFactorForDevice(DISPLAY_DEVICE_TYPE deviceType); +STDAPI RegisterScaleChangeNotifications(DISPLAY_DEVICE_TYPE displayDevice, HWND hwndNotify, UINT uMsgNotify, + DWORD *pdwCookie); +STDAPI RevokeScaleChangeNotifications(DISPLAY_DEVICE_TYPE displayDevice, DWORD dwCookie); +#endif /* NTDDI_VERSION >= NTDDI_WIN8 */ + +#ifndef DPI_ENUMS_DECLARED +typedef enum MONITOR_DPI_TYPE { + MDT_EFFECTIVE_DPI = 0, + MDT_ANGULAR_DPI = 1, + MDT_RAW_DPI = 2, + MDT_DEFAULT = MDT_EFFECTIVE_DPI +} MONITOR_DPI_TYPE; + +typedef enum PROCESS_DPI_AWARENESS { + PROCESS_DPI_UNAWARE = 0, + PROCESS_SYSTEM_DPI_AWARE = 1, + PROCESS_PER_MONITOR_DPI_AWARE = 2 +} PROCESS_DPI_AWARENESS; + +#define DPI_ENUMS_DECLARED +#endif /* DPI_ENUMS_DECLARED */ + +#if NTDDI_VERSION >= NTDDI_WINBLUE +STDAPI GetScaleFactorForMonitor(HMONITOR hMon, DEVICE_SCALE_FACTOR *pScale); +STDAPI RegisterScaleChangeEvent(HANDLE hEvent, DWORD_PTR *pdwCookie); +STDAPI UnregisterScaleChangeEvent(DWORD_PTR dwCookie); + +STDAPI GetDpiForMonitor(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY); +STDAPI GetProcessDpiAwareness(HANDLE hprocess, PROCESS_DPI_AWARENESS *value); +STDAPI SetProcessDpiAwareness(PROCESS_DPI_AWARENESS value); +#endif /* NTDDI_VERSION >= NTDDI_WINBLUE */ + +#if NTDDI_VERSION >= NTDDI_WINTHRESHOLD +#ifndef SHELL_UI_COMPONENT_ENUMS_DECLARED +typedef enum { + SHELL_UI_COMPONENT_TASKBARS = 0, + SHELL_UI_COMPONENT_NOTIFICATIONAREA = 1, + SHELL_UI_COMPONENT_DESKBAND = 2 +} SHELL_UI_COMPONENT; + +#define SHELL_UI_COMPONENT_ENUMS_DECLARED +#endif /* SHELL_UI_COMPONENT_ENUMS_DECLARED */ + +UINT WINAPI GetDpiForShellUIComponent(SHELL_UI_COMPONENT component); +#endif /* NTDDI_VERSION >= NTDDI_WINTHRESHOLD */ + +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ +#endif /* _SHELLSCALINGAPI_H_ */ diff --git a/windows-snapshot-tool/src/main.cpp b/windows-snapshot-tool/src/main.cpp index cac1fc5..92ec8b8 100644 --- a/windows-snapshot-tool/src/main.cpp +++ b/windows-snapshot-tool/src/main.cpp @@ -1,4 +1,7 @@ +//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +//#include #include "resource.h" +//#include #include //#include "LimitSingleInstance.h" @@ -30,6 +33,9 @@ int WINAPI WinMain (HINSTANCE hThisInstance, LPSTR lpszArgument, int nCmdShow) { +// SetProcessDPIAware(); +// SetProcessDPIAwareness(); + // kill other already running instances HWND existingApp = FindWindow(0, szClassName); if (existingApp) @@ -38,6 +44,12 @@ int WINAPI WinMain (HINSTANCE hThisInstance, Sleep(2000); // give the other App some time to clean up and close } + HDC screen = GetDC(0); + FLOAT dpiX, dpiY; + dpiX = static_cast(GetDeviceCaps(screen, LOGPIXELSX)); + dpiY = static_cast(GetDeviceCaps(screen, LOGPIXELSY)); + ReleaseDC(NULL,screen); + /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ @@ -69,8 +81,8 @@ int WINAPI WinMain (HINSTANCE hThisInstance, WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ - 544, /* The programs width */ - 375, /* and height in pixels */ + static_cast(dpiX * 544.f / 96.f), /* The programs width */ + static_cast(dpiY * 375.f / 96.f), /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ @@ -348,6 +360,8 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { HBITMAP hbmScreen = NULL; BITMAP bmpScreen; + SetProcessDPIAware(); + // Retrieve the handle to a display device context for the client // area of the window. hdcScreen = GetDC(NULL); @@ -402,10 +416,18 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { return -1; } - int width = GetDeviceCaps(hdcScreen, HORZRES); - int height = GetDeviceCaps(hdcScreen, VERTRES); + //int width = GetDeviceCaps(hdcScreen, HORZRES); + //int height = GetDeviceCaps(hdcScreen, VERTRES); + //int width_factor = GetDeviceCaps(hdcScreen, SCALINGFACTORX); + //int height_factor = GetDeviceCaps(hdcScreen, SCALINGFACTORY); + int desktop_width = GetDeviceCaps(hdcScreen, DESKTOPHORZRES); + int desktop_height = GetDeviceCaps(hdcScreen, DESKTOPVERTRES); + + //wchar_t res_info[200]; + //swprintf (res_info, 200-1, L"HORZRES: %d\nVERTRES: %d\nSCALINGFACTORX: %d\nSCALINGFACTORY: %d\nDESKTOPHORZRES: %d\nDESKTOPVERTZRES: %d\n", width, height, width_factor, height_factor, desktop_width, desktop_height); + //MessageBox(hWnd, res_info,L"Resolution info", MB_OK); - HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, width, height); + HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, desktop_width, desktop_height); // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC,hBmp); @@ -413,7 +435,7 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { // Bit block transfer into our compatible memory DC. if(!BitBlt(hdcMemDC, 0,0, - width, height, + desktop_width, desktop_height, hdcScreen, 0,0, SRCCOPY))