#pragma once #include #if __cplusplus >= 201703L #include #else #include namespace std { struct nullopt_t { // no-value state indicator struct _Tag { }; constexpr explicit nullopt_t(_Tag) {} }; inline constexpr nullopt_t nullopt{ nullopt_t::_Tag{} }; template class optional { public: optional() : has_value_(false) {} optional(const T& value) : has_value_(true), value_(value) {} optional(T&& value) : has_value_(true), value_(std::move(value)) {} optional(nullopt_t) : has_value_(false) {} bool has_value() const { return has_value_; } T& value() { if (!has_value_) { throw std::runtime_error("optional has no value"); } return value_; } const T& value() const { if (!has_value_) { throw std::runtime_error("optional has no value"); } return value_; } // 重载运算符 * 和 -> 使得使用更加方便 T& operator*() { return value(); } const T& operator*() const { return value(); } T* operator->() { return &value(); } const T* operator->() const { return &value(); } bool operator==(const optional& other) const { if (has_value_ && other.has_value_) { return value_ == other.value_; } return has_value_ == other.has_value_; } bool operator!=(const optional& other) const { return !(*this == other); } bool operator!() const { return !has_value(); } private: bool has_value_; T value_; }; } #endif #include "FramelessDelegate.h" class FramelessDelegateWin : public FramelessDelegate { Q_OBJECT public: FramelessDelegateWin(QWidget* parent); ~FramelessDelegateWin() override; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) bool nativeEvent(const QByteArray& eventType, void* message, long* result) override; #else bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override; #endif protected: void OnShow() override; void OnHide() override; void OnClose() override; void OnScreenChangeInternaal() override; void AddMoveBar(QWidget* moveWidget) override; private: double DpiScale(double value); double UnDpiScale(double value); void CheckMonitorChanged(); void ShowSystemMenu(const QPoint& pos); void SetNativeWindowLong(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) bool OnNCTitTest(MSG* msg, long* result); #else bool OnNCTitTest(MSG* msg, qintptr* result); #endif private: bool firstShow_{ true }; std::optional workRect_; HMONITOR monitor_{ nullptr }; WINDOWPLACEMENT wndPlaceMent_{ 0, 0, 0, {0, 0}, {0, 0}, {0, 0, 0, 0} }; };