Skip to content

Commit

Permalink
fix: coordinate errors due to DPI differences across different monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiahongHong committed May 12, 2024
1 parent 206467c commit 3828027
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ColorPicker/ColorPicker.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ColorPicker/ColorPicker.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +17,8 @@

#include <windows.h>
#include <strsafe.h>
#include <shellscalingapi.h>
#pragma comment(lib, "Shcore.lib")

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3828027

Please sign in to comment.