mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-24 09:07:59 +08:00
78d65a87cd
* [MeasureTool] initial commit * [chore] clean up needless WindowsTargetPlatformVersion overrides from projects * [MeasureTool] initial implementation * Fix build errors * Update vsconfig for needed Windows 10 SDK versions * fix spellchecker * another spellcheck fix * more spellcheck errors * Fix measurement being off by 1 on both ends * UI fixes * Add feet to crosses * Remove anti-aliasing, as it's creating artifacts * Use pixel tolerance from settings * Tooltip updates * Restore antialiasing to draw the tooltip * remove comment for spell check * Updated icons * Icon updates * Improve measurement accuracy and display * Fix spellchecker * Add less precise drawing on continuous warning * Add setting for turning cross feet on * Swap LMB/RMB for interaction * Uncheck active tool's RadioButton when it exits * activation hotkey toggles UI instead of just launching it * track runner process and exit when it exits * add proj ref * toolbar is interactive during measurements * always open toolbar on the main display * refactor colors * refactor edge detection & overlay ui * refactor overlay ui even more * simplify state structs * multimonitor preparation: eliminate global state * prepare for merge * spelling * proper thread termination + minor fixes * multimonitor: launch tools on all monitors * multimonitor support: track cursor position * spell * fix powertoys! * ScreenSize -> Box * add shadow effect for textbox * spell * fix debug mode * dynamic text box size based on text layout metrics * add mouse wheel to adjust pixel tolerance + per channel detection algorithm setting * spelling * fix per channel distance calculations * update installer deps + spelling * tool activation telemetry * update assets and try to fix build * use × instead of x * allow multiple measurements with bounds tool with shift-click * move #define DEBUG_OVERLAY in an appropriate space * spell-checked * update issue template + refactor text box drawing * implement custom renderer and make × semiopaque * spelling * pass dpiScale to x renderer * add sse2neon license * update OOBE * move license to NOTICE * appropriate module preview image * localization for AutomationPeer * increase default pixel tolerance from 5 to 30 * add PowerToys.MeasureToolUI.exe to bugreport * explicitly set texture dims * clarify continuous capture description * fix a real spelling error! * cleanup * clean up x2 * debug texture * fix texture access * fix saveasbitmap * improve sum of all channel diffs method score calc * optimize * ContinuousCapture is enabled by default to avoid confusion * build fix * draw captured screen in a non continuous mode * cast a spell... * merge fix * disable stroboscopic effect * split global/perScreen measure state and minor improvements * spelling * fix comment * primary monitor debug also active for the bounds tool * dpi from rt for custom renderer * add comment * fix off by 1 * make backround convertion success for non continuous mode non-essential * fix spelling * overlay window covers taskbar * fix CI * revert taskbar covering * fix CI * fix ci again * fix 2 * fix ci * CI fix * fix arm ci * cleanup cursor convertion between coordinate spaces * fix spelling * Fix signing * Fix MeasureToolUI version * Fix core version * fix race condition in system internals which happens during concurrent d3d/d2d resource creation Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Niels Laute <niels.laute@live.nl>
79 lines
2.2 KiB
C++
79 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <Windows.h>
|
|
#include <dwmapi.h>
|
|
|
|
#include <array>
|
|
#include <optional>
|
|
|
|
// Initializes and runs windows message loop
|
|
inline int run_message_loop(const bool until_idle = false, const std::optional<uint32_t> timeout_ms = {})
|
|
{
|
|
MSG msg{};
|
|
bool stop = false;
|
|
UINT_PTR timerId = 0;
|
|
if (timeout_ms.has_value())
|
|
{
|
|
timerId = SetTimer(nullptr, 0, *timeout_ms, nullptr);
|
|
}
|
|
|
|
while (!stop && (until_idle ? PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE) : GetMessageW(&msg, nullptr, 0, 0)))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessageW(&msg);
|
|
stop = until_idle && !PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE);
|
|
stop = stop || (msg.message == WM_TIMER && msg.wParam == timerId);
|
|
}
|
|
if (timeout_ms.has_value())
|
|
{
|
|
KillTimer(nullptr, timerId);
|
|
}
|
|
return static_cast<int>(msg.wParam);
|
|
}
|
|
|
|
// Check if window is part of the shell or the taskbar.
|
|
inline bool is_system_window(HWND hwnd, const char* class_name)
|
|
{
|
|
// We compare the HWND against HWND of the desktop and shell windows,
|
|
// we also filter out some window class names know to belong to the taskbar.
|
|
constexpr std::array system_classes = { "SysListView32", "WorkerW", "Shell_TrayWnd", "Shell_SecondaryTrayWnd", "Progman" };
|
|
const std::array system_hwnds = { GetDesktopWindow(), GetShellWindow() };
|
|
for (auto system_hwnd : system_hwnds)
|
|
{
|
|
if (hwnd == system_hwnd)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
for (const auto system_class : system_classes)
|
|
{
|
|
if (!strcmp(system_class, class_name))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
template<typename T>
|
|
inline T GetWindowCreateParam(LPARAM lparam)
|
|
{
|
|
static_assert(sizeof(T) <= sizeof(void*));
|
|
T data{ (T)(reinterpret_cast<CREATESTRUCT*>(lparam)->lpCreateParams) };
|
|
return data;
|
|
}
|
|
|
|
template<typename T>
|
|
inline void StoreWindowParam(HWND window, T data)
|
|
{
|
|
static_assert(sizeof(T) <= sizeof(void*));
|
|
SetWindowLongPtrW(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(data));
|
|
}
|
|
|
|
template<typename T>
|
|
inline T GetWindowParam(HWND window)
|
|
{
|
|
return (T)GetWindowLongPtrW(window, GWLP_USERDATA);
|
|
}
|