From 3828027912eeefcfa9f437e42ab0c04f319dc824 Mon Sep 17 00:00:00 2001 From: Chiahong Hong Date: Sun, 12 May 2024 18:09:33 +0800 Subject: [PATCH] fix: coordinate errors due to DPI differences across different monitors --- ColorPicker/ColorPicker.cpp | 6 +++--- ColorPicker/ColorPicker.h | 4 +++- README.md | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ColorPicker/ColorPicker.cpp b/ColorPicker/ColorPicker.cpp index 0924332..84bc227 100644 --- a/ColorPicker/ColorPicker.cpp +++ b/ColorPicker/ColorPicker.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Chiahong Hong. +// Copyright (C) 2024 Chiahong Hong. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_ PWSTR pCmdLine, _In_ int nCmdShow) { - SetProcessDPIAware(); + SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); // Register the window class. TCHAR CLASS_NAME[] = "MainWindow"; @@ -125,7 +125,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) HGDIOBJ hNewFont = CreateFont(70, 0, 0, 0, FW_DONTCARE, 0, 0, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Consolas")); - + HGDIOBJ hOldFont = (HFONT)SelectObject(hdc, hNewFont); // Draw text diff --git a/ColorPicker/ColorPicker.h b/ColorPicker/ColorPicker.h index 949069d..921a1c0 100644 --- a/ColorPicker/ColorPicker.h +++ b/ColorPicker/ColorPicker.h @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Chiahong Hong. +// Copyright (C) 2024 Chiahong Hong. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,6 +17,8 @@ #include #include +#include +#pragma comment(lib, "Shcore.lib") LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/README.md b/README.md index 1fe1eed..128e6c0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Implement a Screen Color Picker using the Windows API. - CMake 3.8 ## License -Copyright (C) 2022 Chiahong Hong. +Copyright (C) 2024 Chiahong Hong. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by