2019-09-05 00:26:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
2019-12-17 01:36:52 +08:00
|
|
|
#include <string>
|
2019-09-05 00:26:26 +08:00
|
|
|
#include <Windows.h>
|
2019-12-10 06:57:09 +08:00
|
|
|
#include <string>
|
2020-01-25 05:36:01 +08:00
|
|
|
#include <memory>
|
2020-03-16 20:25:30 +08:00
|
|
|
#include <vector>
|
2019-09-05 00:26:26 +08:00
|
|
|
|
|
|
|
// Returns RECT with positions of the minmize/maximize buttons of the given window.
|
|
|
|
// Does not always work, since some apps draw custom toolbars.
|
|
|
|
std::optional<RECT> get_button_pos(HWND hwnd);
|
|
|
|
// Gets position of given window.
|
|
|
|
std::optional<RECT> get_window_pos(HWND hwnd);
|
|
|
|
// Gets mouse postion.
|
|
|
|
std::optional<POINT> get_mouse_pos();
|
2020-02-07 01:04:10 +08:00
|
|
|
|
2020-02-07 22:53:57 +08:00
|
|
|
// Test if window can be zoned by FancyZones
|
2020-03-05 18:07:06 +08:00
|
|
|
struct FancyZonesFilter
|
|
|
|
{
|
|
|
|
bool zonable = false; // If the window is zonable by FancyZones by default - true when both standard_window and no_visible_owner are also true
|
|
|
|
bool standard_window = false; // True if from the styles the window looks like a standard window
|
|
|
|
bool no_visible_owner = false; // True if the window is a top-level window that does not have a visible owner
|
|
|
|
std::wstring process_path; // Path to the executable owning the window
|
2019-11-18 17:29:56 +08:00
|
|
|
};
|
2020-02-07 22:53:57 +08:00
|
|
|
FancyZonesFilter get_fancyzones_filtered_window(HWND window);
|
2020-02-07 01:04:10 +08:00
|
|
|
|
2020-02-07 22:53:57 +08:00
|
|
|
// Gets active foreground window, filtering out all "non standard" windows like the taskbar, etc.
|
2020-03-05 18:07:06 +08:00
|
|
|
struct ShortcutGuideFilter
|
|
|
|
{
|
|
|
|
HWND hwnd = nullptr; // Handle to the top-level foreground window or nullptr if there is no such window
|
|
|
|
bool snappable = false; // True, if the window can react to Windows Snap keys
|
2020-02-07 22:53:57 +08:00
|
|
|
};
|
|
|
|
ShortcutGuideFilter get_shortcutguide_filtered_window();
|
2019-09-17 19:45:49 +08:00
|
|
|
|
2019-09-05 00:26:26 +08:00
|
|
|
// Calculate sizes
|
|
|
|
int width(const RECT& rect);
|
|
|
|
int height(const RECT& rect);
|
|
|
|
// Compare rects
|
|
|
|
bool operator<(const RECT& lhs, const RECT& rhs);
|
|
|
|
// Moves and/or resizes small_rect to fit inside big_rect.
|
|
|
|
RECT keep_rect_inside_rect(const RECT& small_rect, const RECT& big_rect);
|
|
|
|
// Initializes and runs windows message loop
|
|
|
|
int run_message_loop();
|
|
|
|
|
2020-02-18 23:11:01 +08:00
|
|
|
std::optional<std::wstring> get_last_error_message(const DWORD dw);
|
2019-09-05 00:26:26 +08:00
|
|
|
void show_last_error_message(LPCWSTR lpszFunction, DWORD dw);
|
|
|
|
|
2020-03-05 18:07:06 +08:00
|
|
|
enum WindowState
|
|
|
|
{
|
|
|
|
UNKNONW,
|
|
|
|
MINIMIZED,
|
|
|
|
MAXIMIZED,
|
|
|
|
SNAPED_TOP_LEFT,
|
|
|
|
SNAPED_LEFT,
|
|
|
|
SNAPED_BOTTOM_LEFT,
|
|
|
|
SNAPED_TOP_RIGHT,
|
|
|
|
SNAPED_RIGHT,
|
|
|
|
SNAPED_BOTTOM_RIGHT,
|
|
|
|
RESTORED
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
WindowState get_window_state(HWND hwnd);
|
2019-10-04 00:42:18 +08:00
|
|
|
|
|
|
|
// Returns true if the current process is running with elevated privileges
|
|
|
|
bool is_process_elevated();
|
|
|
|
|
|
|
|
// Drops the elevated privilages if present
|
|
|
|
bool drop_elevated_privileges();
|
2019-10-07 17:12:44 +08:00
|
|
|
|
2019-12-17 01:36:52 +08:00
|
|
|
// Run command as elevated user, returns true if succeeded
|
|
|
|
bool run_elevated(const std::wstring& file, const std::wstring& params);
|
|
|
|
|
|
|
|
// Run command as non-elevated user, returns true if succeeded
|
|
|
|
bool run_non_elevated(const std::wstring& file, const std::wstring& params);
|
|
|
|
|
2020-01-10 01:17:42 +08:00
|
|
|
// Run command with the same elevation, returns true if succedded
|
|
|
|
bool run_same_elevation(const std::wstring& file, const std::wstring& params);
|
|
|
|
|
2020-02-19 03:56:34 +08:00
|
|
|
// Returns true if the current process is running from administrator account
|
|
|
|
bool check_user_is_admin();
|
|
|
|
|
2020-03-16 20:25:30 +08:00
|
|
|
//Returns true when one or more strings from vector found in string
|
|
|
|
bool find_app_name_in_path(const std::wstring& where, const std::vector<std::wstring>& what);
|
|
|
|
|
2019-10-07 17:12:44 +08:00
|
|
|
// Get the executable path or module name for modern apps
|
|
|
|
std::wstring get_process_path(DWORD pid) noexcept;
|
|
|
|
// Get the executable path or module name for modern apps
|
|
|
|
std::wstring get_process_path(HWND hwnd) noexcept;
|
2019-10-15 01:22:14 +08:00
|
|
|
|
|
|
|
std::wstring get_product_version();
|
2019-12-11 23:32:40 +08:00
|
|
|
|
|
|
|
std::wstring get_module_filename(HMODULE mod = nullptr);
|
|
|
|
std::wstring get_module_folderpath(HMODULE mod = nullptr);
|
2019-12-17 01:36:52 +08:00
|
|
|
|
|
|
|
// Get a string from the resource file
|
|
|
|
std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wchar_t* fallback);
|
|
|
|
// Wrapper for getting a string from the resource file. Returns the resource id text when fails.
|
|
|
|
// Requires that
|
|
|
|
// extern "C" IMAGE_DOS_HEADER __ImageBase;
|
|
|
|
// is added to the .cpp file.
|
2020-01-15 07:00:05 +08:00
|
|
|
#define GET_RESOURCE_STRING(resource_id) get_resource_string(resource_id, reinterpret_cast<HINSTANCE>(&__ImageBase), L#resource_id)
|
2020-01-25 05:36:01 +08:00
|
|
|
|
|
|
|
// Helper class for various COM-related APIs, e.g working with security descriptors
|
|
|
|
template<typename T>
|
|
|
|
struct typed_storage
|
|
|
|
{
|
|
|
|
std::unique_ptr<char[]> _buffer;
|
|
|
|
inline explicit typed_storage(const DWORD size) :
|
|
|
|
_buffer{ std::make_unique<char[]>(size) }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
inline operator T*()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(_buffer.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Callable>
|
|
|
|
struct on_scope_exit
|
|
|
|
{
|
|
|
|
Callable _f;
|
|
|
|
on_scope_exit(Callable f) :
|
|
|
|
_f{ std::move(f) } {}
|
|
|
|
|
|
|
|
~on_scope_exit()
|
|
|
|
{
|
|
|
|
_f();
|
|
|
|
}
|
2020-01-24 23:26:44 +08:00
|
|
|
};
|
2020-02-26 04:04:19 +08:00
|
|
|
|
|
|
|
template<class... Ts>
|
|
|
|
struct overloaded : Ts...
|
|
|
|
{
|
|
|
|
using Ts::operator()...;
|
|
|
|
};
|
|
|
|
template<class... Ts>
|
|
|
|
overloaded(Ts...)->overloaded<Ts...>;
|