Skip to content

Commit 3828027

Browse files
committed
fix: coordinate errors due to DPI differences across different monitors
1 parent 206467c commit 3828027

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

ColorPicker/ColorPicker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2022 Chiahong Hong.
1+
// Copyright (C) 2024 Chiahong Hong.
22

33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
2020
_In_ PWSTR pCmdLine,
2121
_In_ int nCmdShow)
2222
{
23-
SetProcessDPIAware();
23+
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
2424

2525
// Register the window class.
2626
TCHAR CLASS_NAME[] = "MainWindow";
@@ -125,7 +125,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
125125

126126
HGDIOBJ hNewFont = CreateFont(70, 0, 0, 0, FW_DONTCARE, 0, 0, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
127127
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Consolas"));
128-
128+
129129
HGDIOBJ hOldFont = (HFONT)SelectObject(hdc, hNewFont);
130130

131131
// Draw text

ColorPicker/ColorPicker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2022 Chiahong Hong.
1+
// Copyright (C) 2024 Chiahong Hong.
22

33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -17,6 +17,8 @@
1717

1818
#include <windows.h>
1919
#include <strsafe.h>
20+
#include <shellscalingapi.h>
21+
#pragma comment(lib, "Shcore.lib")
2022

2123
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
2224

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Implement a Screen Color Picker using the Windows API.
99
- CMake 3.8
1010

1111
## License
12-
Copyright (C) 2022 Chiahong Hong.
12+
Copyright (C) 2024 Chiahong Hong.
1313

1414
This program is free software: you can redistribute it and/or modify
1515
it under the terms of the GNU General Public License as published by

0 commit comments

Comments
 (0)