From 90f6bfe42e35a333f3c202b03055ab68d9a8b6b4 Mon Sep 17 00:00:00 2001 From: pit-ray Date: Fri, 23 Feb 2024 21:45:41 +0900 Subject: [PATCH] Move a simple assignment to the constructor --- demo/demo.cpp | 5 +- ...sfluent__tray_1_1_fluent_tray-members.html | 4 +- docs/classfluent__tray_1_1_fluent_tray.html | 76 +- docs/fluent__tray_8hpp_source.html | 1623 ++++++++--------- docs/functions.html | 4 +- docs/functions_func.html | 4 +- docs/index.html | 4 +- docs/search/all_2.js | 2 +- docs/search/all_5.js | 2 +- docs/search/functions_2.js | 2 +- docs/search/functions_5.js | 2 +- include/fluent_tray.hpp | 39 +- 12 files changed, 878 insertions(+), 889 deletions(-) diff --git a/demo/demo.cpp b/demo/demo.cpp index d40dd8d..4f99a81 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -6,10 +6,9 @@ int main() { using namespace fluent_tray ; - FluentTray tray{} ; + FluentTray tray(5, 5, 10, 5) ; if(!tray.create_tray( - "demo", "demo/assets/icon.ico", - 5, 5, 10, 5, 240, true)) { + "demo", "demo/assets/icon.ico", 240, true)) { return 1 ; } diff --git a/docs/classfluent__tray_1_1_fluent_tray-members.html b/docs/classfluent__tray_1_1_fluent_tray-members.html index 7f9098f..b59787b 100644 --- a/docs/classfluent__tray_1_1_fluent_tray-members.html +++ b/docs/classfluent__tray_1_1_fluent_tray-members.html @@ -93,9 +93,9 @@ cend() const noexceptfluent_tray::FluentTrayinline change_icon(const std::string &icon_path)fluent_tray::FluentTrayinline count_menus() const noexceptfluent_tray::FluentTrayinline - create_tray(const std::string &app_name, const std::string &icon_path="", LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char opacity=255, bool round_corner=true)fluent_tray::FluentTrayinline + create_tray(const std::string &app_name, const std::string &icon_path="", unsigned char opacity=255, bool round_corner=true)fluent_tray::FluentTrayinline end() noexceptfluent_tray::FluentTrayinline - FluentTray(int message_id_offset=25, int autocolorpick_offset=5, unsigned char autofadedborder_from_backcolor=10)fluent_tray::FluentTrayinlineexplicit + FluentTray(LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, int message_id_offset=25)fluent_tray::FluentTrayinlineexplicit FluentTray(const FluentTray &)=deletefluent_tray::FluentTray FluentTray(FluentTray &&)=defaultfluent_tray::FluentTray front()fluent_tray::FluentTrayinline diff --git a/docs/classfluent__tray_1_1_fluent_tray.html b/docs/classfluent__tray_1_1_fluent_tray.html index e1c58a3..0dfa59c 100644 --- a/docs/classfluent__tray_1_1_fluent_tray.html +++ b/docs/classfluent__tray_1_1_fluent_tray.html @@ -92,9 +92,9 @@ - - - + + + @@ -105,9 +105,9 @@ - - - + + + @@ -178,8 +178,8 @@

Detailed Description

Class with information on the entire tray.

Constructor & Destructor Documentation

- -

◆ FluentTray() [1/3]

+ +

◆ FluentTray() [1/3]

- + + + + + + + + + + + + + + + + + + + + + @@ -200,7 +220,7 @@

- +

Public Member Functions

 FluentTray (int message_id_offset=25, int autocolorpick_offset=5, unsigned char autofadedborder_from_backcolor=10)
 Create tray object.
 
 FluentTray (LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, int message_id_offset=25)
 Create tray object.
 
 FluentTray (const FluentTray &)=delete
 
FluentTrayoperator= (const FluentTray &)=delete
 
virtual ~FluentTray () noexcept
 
bool create_tray (const std::string &app_name, const std::string &icon_path="", LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char opacity=255, bool round_corner=true)
 Initialize tray and create icon on tray.
 
bool create_tray (const std::string &app_name, const std::string &icon_path="", unsigned char opacity=255, bool round_corner=true)
 Initialize tray and create icon on tray.
 
bool add_menu (const std::string &label_text="", const std::string &icon_path="", bool toggleable=false, const std::string &checkmark="✓", const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})
 Add a menu in order from the top.
 
(int message_id_offset = 25, LONG menu_x_margin = 5,
LONG menu_y_margin = 5,
LONG menu_x_pad = 10,
LONG menu_y_pad = 5,
unsigned char autofadedborder_from_backcolor = 10,
unsigned char autofadedborder_from_backcolor = 10 )int message_id_offset = 25 )
@@ -213,9 +233,13 @@

Parameters
- - + + + + + +
[in]message_id_offsetUnique message identifier.
[in]autocolorpick_offsetPixel offset to determine the background color.
[in]menu_x_marginHorizontal margins outside menus.
[in]menu_y_marginVertical margins outside menus.
[in]menu_x_padHorizontal paddings inside menus.
[in]menu_y_padVertical paddings inside menus.
[in]autofadedborder_from_backcolorDecay value from the background color to determine the background color of the currently selected menu and the color of the separator line.
[in]autocolorpick_offsetPixel offset to determine the background color.
[in]message_id_offsetUnique message identifier.
@@ -584,8 +608,8 @@

-

◆ create_tray()

+ +

◆ create_tray()

@@ -603,26 +627,6 @@

const std::string & icon_path = "", - - - - LONG menu_x_margin = 5, - - - - - LONG menu_y_margin = 5, - - - - - LONG menu_x_pad = 10, - - - - - LONG menu_y_pad = 5, - @@ -646,10 +650,6 @@

[in]app_nameThe application name to be displayed as tooltip text. [in]icon_pathA UTF-8 encoded path to the icon to be displayed in the system tray. - [in]menu_x_marginHorizontal margins outside menus. - [in]menu_y_marginVertical margins outside menus. - [in]menu_x_padHorizontal paddings inside menus. - [in]menu_y_padVertical paddings inside menus. [in]opacityMenu opacity from 0 to 255. [in]round_cornerOption to round the corners of the menu window (Windows 11 only) diff --git a/docs/fluent__tray_8hpp_source.html b/docs/fluent__tray_8hpp_source.html index dbe8fc9..7d11e9d 100644 --- a/docs/fluent__tray_8hpp_source.html +++ b/docs/fluent__tray_8hpp_source.html @@ -684,860 +684,855 @@
704 static unsigned int message_id_ ;
705
706 public:
-
-
713 explicit FluentTray(
-
714 int message_id_offset=25,
-
715 int autocolorpick_offset=5,
-
716 unsigned char autofadedborder_from_backcolor=10)
-
717 : menus_(),
-
718 mouse_is_over_(),
-
719 app_name_(),
-
720 hinstance_(GetModuleHandle(NULL)),
-
721 hwnd_(NULL),
-
722 visible_(false),
-
723 icon_data_(),
-
724 status_(TrayStatus::STOPPED),
-
725 next_menu_id_(1),
-
726 menu_x_margin_(5),
-
727 menu_y_margin_(5),
-
728 menu_x_pad_(5),
-
729 menu_y_pad_(5),
-
730 text_color_(CLR_INVALID),
-
731 back_color_(CLR_INVALID),
-
732 border_color_(CLR_INVALID),
-
733 color_decay_(autofadedborder_from_backcolor),
-
734 back_brush_(NULL),
-
735 autocolorpick_offset_(autocolorpick_offset),
-
736 menu_font_size_(0),
-
737 font_(NULL)
-
738 {
-
739 message_id_ = WM_APP + message_id_offset ;
-
740 }
+
+
717 explicit FluentTray(
+
718 LONG menu_x_margin=5,
+
719 LONG menu_y_margin=5,
+
720 LONG menu_x_pad=10,
+
721 LONG menu_y_pad=5,
+
722 unsigned char autofadedborder_from_backcolor=10,
+
723 int autocolorpick_offset=5,
+
724 int message_id_offset=25)
+
725 : menus_(),
+
726 mouse_is_over_(),
+
727 app_name_(),
+
728 hinstance_(GetModuleHandle(NULL)),
+
729 hwnd_(NULL),
+
730 visible_(false),
+
731 icon_data_(),
+
732 status_(TrayStatus::STOPPED),
+
733 next_menu_id_(1),
+
734 menu_x_margin_(menu_x_margin),
+
735 menu_y_margin_(menu_y_margin),
+
736 menu_x_pad_(menu_x_pad),
+
737 menu_y_pad_(menu_y_pad),
+
738 text_color_(CLR_INVALID),
+
739 back_color_(CLR_INVALID),
+
740 border_color_(CLR_INVALID),
+
741 color_decay_(autofadedborder_from_backcolor),
+
742 back_brush_(NULL),
+
743 autocolorpick_offset_(autocolorpick_offset),
+
744 menu_font_size_(0),
+
745 font_(NULL)
+
746 {
+
747 message_id_ = WM_APP + message_id_offset ;
+
748 }
-
741
-
742 // Copy
-
743 FluentTray(const FluentTray&) = delete ;
-
744 FluentTray& operator=(const FluentTray&) = delete ;
-
745
-
746 // Move
-
747 FluentTray(FluentTray&&) = default ;
-
749
-
-
750 virtual ~FluentTray() noexcept {
-
751 if(font_ != NULL) {
-
752 DeleteObject(font_) ;
-
753 }
-
754 if(back_brush_ != NULL) {
-
755 DeleteObject(back_brush_) ;
-
756 }
-
757 }
+
750 // Copy
+
751 FluentTray(const FluentTray&) = delete ;
+
752 FluentTray& operator=(const FluentTray&) = delete ;
+
753
+
754 // Move
+
755 FluentTray(FluentTray&&) = default ;
+ +
757
+
+
758 virtual ~FluentTray() noexcept {
+
759 if(font_ != NULL) {
+
760 DeleteObject(font_) ;
+
761 }
+
762 if(back_brush_ != NULL) {
+
763 DeleteObject(back_brush_) ;
+
764 }
+
765 }
-
758
-
- -
772 const std::string& app_name,
-
773 const std::string& icon_path="",
-
774 LONG menu_x_margin=5,
-
775 LONG menu_y_margin=5,
-
776 LONG menu_x_pad=10,
-
777 LONG menu_y_pad=5,
-
778 unsigned char opacity=255,
+
766
+
+ +
776 const std::string& app_name,
+
777 const std::string& icon_path="",
+
778 unsigned char opacity=255,
779 bool round_corner=true) {
780 if(!util::string2wstring(app_name, app_name_)) {
781 return false ;
782 }
783
-
784 menu_x_margin_ = menu_x_margin ;
-
785 menu_y_margin_ = menu_y_margin ;
-
786 menu_x_pad_ = menu_x_pad ;
-
787 menu_y_pad_ = menu_y_pad ;
-
788
-
789 WNDCLASSW winc ;
-
790 winc.style = CS_HREDRAW | CS_VREDRAW ;
-
791 winc.lpfnWndProc = &FluentTray::callback ;
-
792 winc.cbClsExtra = 0 ;
-
793 winc.cbWndExtra = sizeof(LONG) * 2 ; // To store two-part address.
-
794 winc.hInstance = hinstance_ ;
-
795 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION) ;
-
796 winc.hCursor = LoadCursor(NULL, IDC_ARROW) ;
-
797 winc.hbrBackground = GetSysColorBrush(COLOR_WINDOW) ;
-
798 winc.lpszMenuName = NULL ;
-
799 winc.lpszClassName = app_name_.c_str() ;
-
800
-
801 if(!RegisterClassW(&winc)) {
-
802 return false ;
-
803 }
-
804
-
805 hwnd_ = CreateWindowExW(
-
806 WS_EX_TOOLWINDOW | WS_EX_LAYERED,
-
807 app_name_.c_str(),
-
808 app_name_.c_str(),
-
809 WS_POPUPWINDOW,
-
810 0, 0, 100, 100,
-
811 NULL, NULL,
-
812 hinstance_, NULL
-
813 ) ;
-
814 if(!hwnd_) {
-
815 return false ;
-
816 }
+
784 WNDCLASSW winc ;
+
785 winc.style = CS_HREDRAW | CS_VREDRAW ;
+
786 winc.lpfnWndProc = &FluentTray::callback ;
+
787 winc.cbClsExtra = 0 ;
+
788 winc.cbWndExtra = sizeof(LONG) * 2 ; // To store two-part address.
+
789 winc.hInstance = hinstance_ ;
+
790 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION) ;
+
791 winc.hCursor = LoadCursor(NULL, IDC_ARROW) ;
+
792 winc.hbrBackground = GetSysColorBrush(COLOR_WINDOW) ;
+
793 winc.lpszMenuName = NULL ;
+
794 winc.lpszClassName = app_name_.c_str() ;
+
795
+
796 if(!RegisterClassW(&winc)) {
+
797 return false ;
+
798 }
+
799
+
800 hwnd_ = CreateWindowExW(
+
801 WS_EX_TOOLWINDOW | WS_EX_LAYERED,
+
802 app_name_.c_str(),
+
803 app_name_.c_str(),
+
804 WS_POPUPWINDOW,
+
805 0, 0, 100, 100,
+
806 NULL, NULL,
+
807 hinstance_, NULL
+
808 ) ;
+
809 if(!hwnd_) {
+
810 return false ;
+
811 }
+
812
+
813 // To access the this pointer inside the callback function,
+
814 // the address divide into the two part address.
+
815 LONG upper_addr, lower_addr ;
+
816 util::split_bits(this, upper_addr, lower_addr) ;
817
-
818 // To access the this pointer inside the callback function,
-
819 // the address divide into the two part address.
-
820 LONG upper_addr, lower_addr ;
-
821 util::split_bits(this, upper_addr, lower_addr) ;
-
822
-
823 SetLastError(0) ;
-
824 if(!SetWindowLongW(hwnd_, 0, upper_addr) && GetLastError() != 0) {
-
825 return false ;
-
826 }
-
827 SetLastError(0) ;
-
828 if(!SetWindowLongW(hwnd_, sizeof(LONG), lower_addr) && GetLastError() != 0) {
-
829 return false ;
-
830 }
-
831
-
832 if(!SetLayeredWindowAttributes(hwnd_, 0, opacity, LWA_ALPHA)) {
-
833 return false ;
-
834 }
-
835
-
836 // Set rounded window for Windows 11 only.
-
837 if(round_corner) {
-
838#if defined(_MSC_VER) && _MSC_VER >= 1500
-
839 using RtlGetVersionType = NTSTATUS (WINAPI*)(PRTL_OSVERSIONINFOW) ;
-
840 const auto hmodule = LoadLibraryW(L"ntdll.dll") ;
-
841 if(!hmodule) {
-
842 return false ;
-
843 }
-
844
-
845 // cast to void* once to avoid warnings about type conversion.
-
846 const auto RtlGetVersion = reinterpret_cast<RtlGetVersionType>(
-
847 reinterpret_cast<void*>(GetProcAddress(hmodule, "RtlGetVersion"))) ;
-
848 if(!RtlGetVersion) {
-
849 FreeLibrary(hmodule) ;
-
850 return false ;
-
851 }
-
852
-
853 OSVERSIONINFOW vinfo ;
-
854 vinfo.dwOSVersionInfoSize = sizeof(decltype(vinfo)) ;
-
855 auto result = RtlGetVersion(&vinfo) ;
-
856 if(!FreeLibrary(hmodule)) {
-
857 return false ;
-
858 }
-
859
-
860 if(result != STATUS_SUCCESS) {
-
861 return false ;
-
862 }
-
863
-
864 // Check if the OS is Windows11
-
865 if(vinfo.dwBuildNumber >= 22000) {
-
866 auto pref = DWMWCP_ROUND ;
-
867 if(DwmSetWindowAttribute(
-
868 hwnd_,
-
869 DWMWA_WINDOW_CORNER_PREFERENCE,
-
870 &pref, sizeof(pref)) != S_OK) {
-
871 return false ;
-
872 }
-
873 }
-
874#endif // defined(_MSC_VER) && _MSC_VER >= 1500
-
875 }
-
876
-
877 if(!change_icon(icon_path)) {
-
878 return false ;
-
879 }
-
880
-
881 if(!set_font()) {
-
882 return false ;
-
883 }
+
818 SetLastError(0) ;
+
819 if(!SetWindowLongW(hwnd_, 0, upper_addr) && GetLastError() != 0) {
+
820 return false ;
+
821 }
+
822 SetLastError(0) ;
+
823 if(!SetWindowLongW(hwnd_, sizeof(LONG), lower_addr) && GetLastError() != 0) {
+
824 return false ;
+
825 }
+
826
+
827 if(!SetLayeredWindowAttributes(hwnd_, 0, opacity, LWA_ALPHA)) {
+
828 return false ;
+
829 }
+
830
+
831 // Set rounded window for Windows 11 only.
+
832 if(round_corner) {
+
833#if defined(_MSC_VER) && _MSC_VER >= 1500
+
834 using RtlGetVersionType = NTSTATUS (WINAPI*)(PRTL_OSVERSIONINFOW) ;
+
835 const auto hmodule = LoadLibraryW(L"ntdll.dll") ;
+
836 if(!hmodule) {
+
837 return false ;
+
838 }
+
839
+
840 // cast to void* once to avoid warnings about type conversion.
+
841 const auto RtlGetVersion = reinterpret_cast<RtlGetVersionType>(
+
842 reinterpret_cast<void*>(GetProcAddress(hmodule, "RtlGetVersion"))) ;
+
843 if(!RtlGetVersion) {
+
844 FreeLibrary(hmodule) ;
+
845 return false ;
+
846 }
+
847
+
848 OSVERSIONINFOW vinfo ;
+
849 vinfo.dwOSVersionInfoSize = sizeof(decltype(vinfo)) ;
+
850 auto result = RtlGetVersion(&vinfo) ;
+
851 if(!FreeLibrary(hmodule)) {
+
852 return false ;
+
853 }
+
854
+
855 if(result != STATUS_SUCCESS) {
+
856 return false ;
+
857 }
+
858
+
859 // Check if the OS is Windows11
+
860 if(vinfo.dwBuildNumber >= 22000) {
+
861 auto pref = DWMWCP_ROUND ;
+
862 if(DwmSetWindowAttribute(
+
863 hwnd_,
+
864 DWMWA_WINDOW_CORNER_PREFERENCE,
+
865 &pref, sizeof(pref)) != S_OK) {
+
866 return false ;
+
867 }
+
868 }
+
869#endif // defined(_MSC_VER) && _MSC_VER >= 1500
+
870 }
+
871
+
872 if(!change_icon(icon_path)) {
+
873 return false ;
+
874 }
+
875
+
876 if(!set_font()) {
+
877 return false ;
+
878 }
+
879
+
880 status_ = TrayStatus::RUNNING ;
+
881
+
882 return true ;
+
883 }
+
884
-
885 status_ = TrayStatus::RUNNING ;
-
886
-
887 return true ;
-
888 }
+
+ +
896 const std::string& label_text="",
+
897 const std::string& icon_path="",
+
898 bool toggleable=false,
+
899 const std::string& checkmark="✓",
+
900 const std::function<bool(void)>& callback=[] {return true ;},
+
901 const std::function<bool(void)>& unchecked_callback=[] {return true ;}) {
+
902 FluentMenu menu(toggleable, callback, unchecked_callback) ;
+
903 if(!menu.create_menu(
+
904 hinstance_, hwnd_, next_menu_id_,
+
905 label_text, icon_path, checkmark)) {
+
906 return false ;
+
907 }
+
908
+
909 menus_.push_back(std::move(menu)) ;
+
910 mouse_is_over_.push_back(false) ;
+
911 next_menu_id_ ++ ;
+
912 return true ;
+
913 }
-
889
-
- -
901 const std::string& label_text="",
-
902 const std::string& icon_path="",
-
903 bool toggleable=false,
-
904 const std::string& checkmark="✓",
-
905 const std::function<bool(void)>& callback=[] {return true ;},
-
906 const std::function<bool(void)>& unchecked_callback=[] {return true ;}) {
-
907 FluentMenu menu(toggleable, callback, unchecked_callback) ;
-
908 if(!menu.create_menu(
-
909 hinstance_, hwnd_, next_menu_id_,
-
910 label_text, icon_path, checkmark)) {
-
911 return false ;
-
912 }
-
913
-
914 menus_.push_back(std::move(menu)) ;
-
915 mouse_is_over_.push_back(false) ;
-
916 next_menu_id_ ++ ;
-
917 return true ;
-
918 }
+
914
+
+ +
919 if(!menus_.empty()) {
+
920 menus_.back().show_separator_line() ;
+
921 }
+
922 }
-
919
-
- -
924 if(!menus_.empty()) {
-
925 menus_.back().show_separator_line() ;
-
926 }
-
927 }
+
923
+
+
928 bool update() {
+
929 if(status_ == TrayStatus::FAILED) {
+
930 return false ;
+
931 }
+
932
+
933 MSG msg ;
+
934 get_message(msg) ;
+
935
+
936 if(GetForegroundWindow() != hwnd_ && visible_) {
+
937 if(!hide_menu_window()) {
+
938 fail() ;
+
939 return false ;
+
940 }
+
941 }
+
942
+
943 for(std::size_t i = 0 ; i < menus_.size() ; i ++) {
+
944 auto& menu = menus_[i] ;
+
945 if(menu.is_mouse_over()) {
+
946 if(!mouse_is_over_[i]) {
+
947 if(!change_menu_back_color(menu, border_color_)) {
+
948 fail() ;
+
949 return false ;
+
950 }
+
951 }
+
952 mouse_is_over_[i] = true ;
+
953 }
+
954 else {
+
955 if(mouse_is_over_[i]) {
+
956 if(!change_menu_back_color(menu, back_color_)) {
+
957 fail() ;
+
958 return false ;
+
959 }
+
960 }
+
961 mouse_is_over_[i] = false ;
+
962 }
+
963 }
+
964
+
965 return true ;
+
966 }
-
928
-
-
933 bool update() {
-
934 if(status_ == TrayStatus::FAILED) {
-
935 return false ;
-
936 }
-
937
-
938 MSG msg ;
-
939 get_message(msg) ;
-
940
-
941 if(GetForegroundWindow() != hwnd_ && visible_) {
-
942 if(!hide_menu_window()) {
-
943 fail() ;
-
944 return false ;
-
945 }
-
946 }
-
947
-
948 for(std::size_t i = 0 ; i < menus_.size() ; i ++) {
-
949 auto& menu = menus_[i] ;
-
950 if(menu.is_mouse_over()) {
-
951 if(!mouse_is_over_[i]) {
-
952 if(!change_menu_back_color(menu, border_color_)) {
-
953 fail() ;
-
954 return false ;
-
955 }
-
956 }
-
957 mouse_is_over_[i] = true ;
-
958 }
-
959 else {
-
960 if(mouse_is_over_[i]) {
-
961 if(!change_menu_back_color(menu, back_color_)) {
-
962 fail() ;
-
963 return false ;
-
964 }
-
965 }
-
966 mouse_is_over_[i] = false ;
-
967 }
-
968 }
-
969
-
970 return true ;
-
971 }
+
967
+
+ +
974 std::chrono::milliseconds sleep_time=std::chrono::milliseconds(1)) {
+
975
+
976 while(true) {
+
977 if(status_ == TrayStatus::SHOULD_STOP) {
+
978 status_ = TrayStatus::STOPPED ;
+
979 break ;
+
980 }
+
981
+
982 if(!update()) {
+
983 return false ;
+
984 }
+
985
+
986 Sleep(static_cast<int>(sleep_time.count())) ;
+
987 }
+
988 return true ;
+
989 }
-
972
-
- -
979 std::chrono::milliseconds sleep_time=std::chrono::milliseconds(1)) {
-
980
-
981 while(true) {
-
982 if(status_ == TrayStatus::SHOULD_STOP) {
-
983 status_ = TrayStatus::STOPPED ;
-
984 break ;
-
985 }
-
986
-
987 if(!update()) {
-
988 return false ;
-
989 }
990
-
991 Sleep(static_cast<int>(sleep_time.count())) ;
-
992 }
-
993 return true ;
-
994 }
-
-
995
-
-
1000 HWND window_handle() const noexcept {
-
1001 return hwnd_ ;
-
1002 }
+
+
995 HWND window_handle() const noexcept {
+
996 return hwnd_ ;
+
997 }
-
1003
-
- -
1009 // Initialize the color settings.
-
1010 if(back_color_ == CLR_INVALID) {
-
1011 // If the color is CLR_INVALID, it is determined from the theme.
-
1012 back_color_ = extract_taskbar_color() ;
-
1013 if(back_color_ == CLR_INVALID) {
-
1014 return false ;
-
1015 }
-
1016 if(!update_background_brush()) {
-
1017 return false ;
-
1018 }
-
1019 }
-
1020 if(text_color_ == CLR_INVALID) {
-
1021 // The text color is automatically determined from the background color.
-
1022 text_color_ = calculate_text_color_(back_color_) ;
-
1023 if(text_color_ == CLR_INVALID) {
-
1024 return false ;
-
1025 }
-
1026 }
-
1027 if(border_color_ == CLR_INVALID) {
-
1028 // The border color is automatically determined from the background color.
-
1029 border_color_ = calculate_faded_color_(back_color_, color_decay_) ;
-
1030 if(border_color_ == CLR_INVALID) {
-
1031 return false ;
-
1032 }
-
1033 }
-
1034
-
1035 LONG max_label_size = 0 ;
-
1036 for(auto& menu : menus_) {
-
1037 SIZE size ;
-
1038 if(!menu.calculate_required_dims(font_, size)) {
-
1039 return false ;
-
1040 }
-
1041 if(max_label_size < size.cx) {
-
1042 max_label_size = size.cx ;
-
1043 }
-
1044 }
-
1045
-
1046 // Update the sizes
-
1047 auto menu_width = max_label_size + 2 * menu_x_pad_ ;
-
1048 auto menu_height = menu_font_size_ + 2 * menu_y_pad_ ;
-
1049 auto popup_width = 2 * menu_x_margin_ + menu_width ;
-
1050 auto popup_height = static_cast<LONG>(
-
1051 menus_.size() * (menu_y_margin_ + menu_height) + menu_y_margin_) ;
+
998
+
+ +
1004 // Initialize the color settings.
+
1005 if(back_color_ == CLR_INVALID) {
+
1006 // If the color is CLR_INVALID, it is determined from the theme.
+
1007 back_color_ = extract_taskbar_color() ;
+
1008 if(back_color_ == CLR_INVALID) {
+
1009 return false ;
+
1010 }
+
1011 if(!update_background_brush()) {
+
1012 return false ;
+
1013 }
+
1014 }
+
1015 if(text_color_ == CLR_INVALID) {
+
1016 // The text color is automatically determined from the background color.
+
1017 text_color_ = calculate_text_color_(back_color_) ;
+
1018 if(text_color_ == CLR_INVALID) {
+
1019 return false ;
+
1020 }
+
1021 }
+
1022 if(border_color_ == CLR_INVALID) {
+
1023 // The border color is automatically determined from the background color.
+
1024 border_color_ = calculate_faded_color_(back_color_, color_decay_) ;
+
1025 if(border_color_ == CLR_INVALID) {
+
1026 return false ;
+
1027 }
+
1028 }
+
1029
+
1030 LONG max_label_size = 0 ;
+
1031 for(auto& menu : menus_) {
+
1032 SIZE size ;
+
1033 if(!menu.calculate_required_dims(font_, size)) {
+
1034 return false ;
+
1035 }
+
1036 if(max_label_size < size.cx) {
+
1037 max_label_size = size.cx ;
+
1038 }
+
1039 }
+
1040
+
1041 // Update the sizes
+
1042 auto menu_width = max_label_size + 2 * menu_x_pad_ ;
+
1043 auto menu_height = menu_font_size_ + 2 * menu_y_pad_ ;
+
1044 auto popup_width = 2 * menu_x_margin_ + menu_width ;
+
1045 auto popup_height = static_cast<LONG>(
+
1046 menus_.size() * (menu_y_margin_ + menu_height) + menu_y_margin_) ;
+
1047
+
1048 POINT cursor_pos ;
+
1049 if(!GetCursorPos(&cursor_pos)) {
+
1050 return false ;
+
1051 }
1052
-
1053 POINT cursor_pos ;
-
1054 if(!GetCursorPos(&cursor_pos)) {
-
1055 return false ;
-
1056 }
-
1057
-
1058 RECT work_rect ;
-
1059 if(!SystemParametersInfo(
-
1060 SPI_GETWORKAREA, 0, reinterpret_cast<PVOID>(&work_rect), 0)) {
-
1061 return false ;
-
1062 }
-
1063
-
1064 auto screen_width = GetSystemMetrics(SM_CXSCREEN) ;
-
1065 auto screen_height = GetSystemMetrics(SM_CYSCREEN) ;
-
1066
-
1067 auto work_width = work_rect.right - work_rect.left ;
-
1068 auto work_height = work_rect.bottom - work_rect.top ;
-
1069
-
1070 auto taskbar_width = screen_width - work_width ;
-
1071 auto taskbar_height = screen_height - work_height ;
-
1072
-
1073 auto pos = cursor_pos ;
-
1074 if(taskbar_width == 0) { // horizontal taskbar
-
1075 if(cursor_pos.y <= taskbar_height) {
-
1076 //top
-
1077 pos.y = taskbar_height ;
+
1053 RECT work_rect ;
+
1054 if(!SystemParametersInfo(
+
1055 SPI_GETWORKAREA, 0, reinterpret_cast<PVOID>(&work_rect), 0)) {
+
1056 return false ;
+
1057 }
+
1058
+
1059 auto screen_width = GetSystemMetrics(SM_CXSCREEN) ;
+
1060 auto screen_height = GetSystemMetrics(SM_CYSCREEN) ;
+
1061
+
1062 auto work_width = work_rect.right - work_rect.left ;
+
1063 auto work_height = work_rect.bottom - work_rect.top ;
+
1064
+
1065 auto taskbar_width = screen_width - work_width ;
+
1066 auto taskbar_height = screen_height - work_height ;
+
1067
+
1068 auto pos = cursor_pos ;
+
1069 if(taskbar_width == 0) { // horizontal taskbar
+
1070 if(cursor_pos.y <= taskbar_height) {
+
1071 //top
+
1072 pos.y = taskbar_height ;
+
1073 }
+
1074 else {
+
1075 //bottom
+
1076 // add 20% offset
+
1077 pos.y = screen_height - (popup_height + 12 * taskbar_height / 10) ;
1078 }
-
1079 else {
-
1080 //bottom
-
1081 // add 20% offset
-
1082 pos.y = screen_height - (popup_height + 12 * taskbar_height / 10) ;
-
1083 }
-
1084 pos.x = cursor_pos.x - popup_width / 2 ;
-
1085 }
-
1086 else { // vertical taskbar
-
1087 if(pos.x <= taskbar_width) {
-
1088 //left
-
1089 pos.x = taskbar_width ;
+
1079 pos.x = cursor_pos.x - popup_width / 2 ;
+
1080 }
+
1081 else { // vertical taskbar
+
1082 if(pos.x <= taskbar_width) {
+
1083 //left
+
1084 pos.x = taskbar_width ;
+
1085 }
+
1086 else {
+
1087 //right
+
1088 // add 20% offset
+
1089 pos.x = popup_width + 12 * taskbar_width / 10 ;
1090 }
-
1091 else {
-
1092 //right
-
1093 // add 20% offset
-
1094 pos.x = popup_width + 12 * taskbar_width / 10 ;
-
1095 }
-
1096
-
1097 pos.y = cursor_pos.y - popup_height / 2 ;
-
1098 }
-
1099
-
1100 if(!SetWindowPos(
-
1101 hwnd_, HWND_TOP,
-
1102 pos.x, pos.y, popup_width, popup_height,
-
1103 SWP_SHOWWINDOW)) {
-
1104 return false ;
-
1105 }
-
1106
-
1107 for(std::size_t i = 0 ; i < menus_.size() ; i ++) {
-
1108 auto& menu = menus_[i] ;
-
1109 auto y = \
-
1110 menu_y_margin_
-
1111 + static_cast<LONG>(i) * (menu_height + menu_y_margin_) ;
-
1112 if(!SetWindowPos(
-
1113 menu.window_handle(), HWND_TOP,
-
1114 menu_x_margin_, y,
-
1115 menu_width, menu_height,
-
1116 SWP_SHOWWINDOW)) {
-
1117 return false ;
-
1118 }
-
1119
-
1120 if(!menu.set_color(text_color_, back_color_, border_color_)) {
-
1121 return false ;
-
1122 }
+
1091
+
1092 pos.y = cursor_pos.y - popup_height / 2 ;
+
1093 }
+
1094
+
1095 if(!SetWindowPos(
+
1096 hwnd_, HWND_TOP,
+
1097 pos.x, pos.y, popup_width, popup_height,
+
1098 SWP_SHOWWINDOW)) {
+
1099 return false ;
+
1100 }
+
1101
+
1102 for(std::size_t i = 0 ; i < menus_.size() ; i ++) {
+
1103 auto& menu = menus_[i] ;
+
1104 auto y = \
+
1105 menu_y_margin_
+
1106 + static_cast<LONG>(i) * (menu_height + menu_y_margin_) ;
+
1107 if(!SetWindowPos(
+
1108 menu.window_handle(), HWND_TOP,
+
1109 menu_x_margin_, y,
+
1110 menu_width, menu_height,
+
1111 SWP_SHOWWINDOW)) {
+
1112 return false ;
+
1113 }
+
1114
+
1115 if(!menu.set_color(text_color_, back_color_, border_color_)) {
+
1116 return false ;
+
1117 }
+
1118 }
+
1119 std::fill(mouse_is_over_.begin(), mouse_is_over_.end(), false) ;
+
1120
+
1121 if(!SetForegroundWindow(hwnd_)) {
+
1122 return false ;
1123 }
-
1124 std::fill(mouse_is_over_.begin(), mouse_is_over_.end(), false) ;
-
1125
-
1126 if(!SetForegroundWindow(hwnd_)) {
-
1127 return false ;
-
1128 }
-
1129
-
1130 visible_ = true ;
-
1131
-
1132 return true ;
-
1133 }
+
1124
+
1125 visible_ = true ;
+
1126
+
1127 return true ;
+
1128 }
-
1134
-
- -
1140 ShowWindow(hwnd_, SW_HIDE) ;
-
1141 visible_ = false ;
-
1142 std::fill(mouse_is_over_.begin(), mouse_is_over_.end(), false) ;
-
1143 return true ;
-
1144 }
+
1129
+
+ +
1135 ShowWindow(hwnd_, SW_HIDE) ;
+
1136 visible_ = false ;
+
1137 std::fill(mouse_is_over_.begin(), mouse_is_over_.end(), false) ;
+
1138 return true ;
+
1139 }
-
1145
-
-
1153 bool show_balloon_tip(const std::string& title, const std::string& message) {
-
1154 NOTIFYICONDATAW notify_data = {} ;
-
1155 notify_data.cbSize = sizeof(notify_data) ;
-
1156 notify_data.hWnd = hwnd_ ;
-
1157 notify_data.uFlags = NIF_INFO ;
+
1140
+
+
1148 bool show_balloon_tip(const std::string& title, const std::string& message) {
+
1149 NOTIFYICONDATAW notify_data = {} ;
+
1150 notify_data.cbSize = sizeof(notify_data) ;
+
1151 notify_data.hWnd = hwnd_ ;
+
1152 notify_data.uFlags = NIF_INFO ;
+
1153
+
1154 std::wstring title_wide ;
+
1155 if(!util::string2wstring(title, title_wide)) {
+
1156 return false ;
+
1157 }
1158
-
1159 std::wstring title_wide ;
-
1160 if(!util::string2wstring(title, title_wide)) {
+
1159 std::wstring message_wide ;
+
1160 if(!util::string2wstring(message, message_wide)) {
1161 return false ;
1162 }
1163
-
1164 std::wstring message_wide ;
-
1165 if(!util::string2wstring(message, message_wide)) {
-
1166 return false ;
-
1167 }
+
1164 auto title_len = title_wide.length() > 47 ? 47 : title_wide.length() ;
+
1165 std::wmemcpy(
+
1166 notify_data.szInfoTitle, title_wide.c_str(), title_len) ;
+
1167 notify_data.szInfoTitle[title_len] = L'\0' ;
1168
-
1169 auto title_len = title_wide.length() > 47 ? 47 : title_wide.length() ;
+
1169 auto message_len = message_wide.length() > 199 ? 199 : message_wide.length() ;
1170 std::wmemcpy(
-
1171 notify_data.szInfoTitle, title_wide.c_str(), title_len) ;
-
1172 notify_data.szInfoTitle[title_len] = L'\0' ;
+
1171 notify_data.szInfo, message_wide.c_str(), message_len) ;
+
1172 notify_data.szInfo[message_len] = L'\0' ;
1173
-
1174 auto message_len = message_wide.length() > 199 ? 199 : message_wide.length() ;
-
1175 std::wmemcpy(
-
1176 notify_data.szInfo, message_wide.c_str(), message_len) ;
-
1177 notify_data.szInfo[message_len] = L'\0' ;
-
1178
-
1179 if(!Shell_NotifyIconW(NIM_MODIFY, &notify_data)) {
-
1180 return false ;
-
1181 }
-
1182 return true ;
-
1183 }
+
1174 if(!Shell_NotifyIconW(NIM_MODIFY, &notify_data)) {
+
1175 return false ;
+
1176 }
+
1177 return true ;
+
1178 }
-
1184
-
-
1189 TrayStatus status() const noexcept {
-
1190 return status_ ;
-
1191 }
+
1179
+
+
1184 TrayStatus status() const noexcept {
+
1185 return status_ ;
+
1186 }
-
1192
-
-
1196 void stop() noexcept {
-
1197 status_ = TrayStatus::SHOULD_STOP ;
-
1198 }
+
1187
+
+
1191 void stop() noexcept {
+
1192 status_ = TrayStatus::SHOULD_STOP ;
+
1193 }
-
1199
-
-
1204 std::vector<FluentMenu>::iterator begin() noexcept {
-
1205 return menus_.begin() ;
-
1206 }
+
1194
+
+
1199 std::vector<FluentMenu>::iterator begin() noexcept {
+
1200 return menus_.begin() ;
+
1201 }
-
1207
-
-
1212 std::vector<FluentMenu>::iterator end() noexcept {
-
1213 return menus_.end() ;
-
1214 }
+
1202
+
+
1207 std::vector<FluentMenu>::iterator end() noexcept {
+
1208 return menus_.end() ;
+
1209 }
-
1215
-
-
1220 std::vector<FluentMenu>::const_iterator cbegin() const noexcept {
-
1221 return menus_.cbegin() ;
-
1222 }
+
1210
+
+
1215 std::vector<FluentMenu>::const_iterator cbegin() const noexcept {
+
1216 return menus_.cbegin() ;
+
1217 }
-
1223
-
-
1228 std::vector<FluentMenu>::const_iterator cend() const noexcept {
-
1229 return menus_.cend() ;
-
1230 }
+
1218
+
+
1223 std::vector<FluentMenu>::const_iterator cend() const noexcept {
+
1224 return menus_.cend() ;
+
1225 }
-
1231
-
- -
1237 return menus_.front() ;
-
1238 }
+
1226
+
+ +
1232 return menus_.front() ;
+
1233 }
-
1239
-
-
1244 const FluentMenu& front() const {
-
1245 return menus_.front() ;
-
1246 }
+
1234
+
+
1239 const FluentMenu& front() const {
+
1240 return menus_.front() ;
+
1241 }
-
1247
-
- -
1253 return menus_.back() ;
-
1254 }
+
1242
+
+ +
1248 return menus_.back() ;
+
1249 }
-
1255
-
-
1260 const FluentMenu& back() const {
-
1261 return menus_.back() ;
-
1262 }
+
1250
+
+
1255 const FluentMenu& back() const {
+
1256 return menus_.back() ;
+
1257 }
-
1263
-
-
1268 std::size_t count_menus() const noexcept {
-
1269 return menus_.size() ;
-
1270 }
+
1258
+
+
1263 std::size_t count_menus() const noexcept {
+
1264 return menus_.size() ;
+
1265 }
-
1271
-
- -
1281 LONG font_size=0,
-
1282 LONG font_weight=0,
-
1283 const std::string& font_name="") {
-
1284 NONCLIENTMETRICSW metrics ;
-
1285 metrics.cbSize = sizeof(metrics) ;
-
1286
-
1287 if(!SystemParametersInfoW(
-
1288 SPI_GETNONCLIENTMETRICS,
-
1289 metrics.cbSize, &metrics, 0)) {
-
1290 return false ;
+
1266
+
+ +
1276 LONG font_size=0,
+
1277 LONG font_weight=0,
+
1278 const std::string& font_name="") {
+
1279 NONCLIENTMETRICSW metrics ;
+
1280 metrics.cbSize = sizeof(metrics) ;
+
1281
+
1282 if(!SystemParametersInfoW(
+
1283 SPI_GETNONCLIENTMETRICS,
+
1284 metrics.cbSize, &metrics, 0)) {
+
1285 return false ;
+
1286 }
+
1287
+
1288 auto& logfont = metrics.lfCaptionFont ;
+
1289 if(font_size != 0) {
+
1290 logfont.lfHeight = font_size ;
1291 }
-
1292
-
1293 auto& logfont = metrics.lfCaptionFont ;
-
1294 if(font_size != 0) {
-
1295 logfont.lfHeight = font_size ;
-
1296 }
-
1297 else {
-
1298 logfont.lfHeight = 20 ;
-
1299 }
-
1300 if(font_weight != 0) {
-
1301 logfont.lfWeight = font_weight ;
-
1302 }
-
1303 else {
-
1304 logfont.lfWeight = FW_MEDIUM ;
-
1305 }
-
1306
-
1307 if(!font_name.empty()) {
-
1308 std::wstring font_name_wide ;
-
1309 if(!util::string2wstring(font_name, font_name_wide)) {
-
1310 return false ;
-
1311 }
-
1312 auto& dst = logfont.lfFaceName ;
-
1313
-
1314 if(font_name_wide.size() < LF_FACESIZE) {
+
1292 else {
+
1293 logfont.lfHeight = 20 ;
+
1294 }
+
1295 if(font_weight != 0) {
+
1296 logfont.lfWeight = font_weight ;
+
1297 }
+
1298 else {
+
1299 logfont.lfWeight = FW_MEDIUM ;
+
1300 }
+
1301
+
1302 if(!font_name.empty()) {
+
1303 std::wstring font_name_wide ;
+
1304 if(!util::string2wstring(font_name, font_name_wide)) {
+
1305 return false ;
+
1306 }
+
1307 auto& dst = logfont.lfFaceName ;
+
1308
+
1309 if(font_name_wide.size() < LF_FACESIZE) {
+
1310 std::wmemcpy(
+
1311 dst, font_name_wide.c_str(), font_name_wide.length()) ;
+
1312 dst[font_name_wide.size()] = L'\0' ;
+
1313 }
+
1314 else {
1315 std::wmemcpy(
-
1316 dst, font_name_wide.c_str(), font_name_wide.length()) ;
-
1317 dst[font_name_wide.size()] = L'\0' ;
+
1316 dst, font_name_wide.c_str(), LF_FACESIZE - 1) ;
+
1317 dst[LF_FACESIZE - 1] = L'\0' ;
1318 }
-
1319 else {
-
1320 std::wmemcpy(
-
1321 dst, font_name_wide.c_str(), LF_FACESIZE - 1) ;
-
1322 dst[LF_FACESIZE - 1] = L'\0' ;
-
1323 }
+
1319 }
+
1320
+
1321 auto font = CreateFontIndirectW(&logfont) ;
+
1322 if(!font) {
+
1323 return false ;
1324 }
-
1325
-
1326 auto font = CreateFontIndirectW(&logfont) ;
-
1327 if(!font) {
-
1328 return false ;
-
1329 }
-
1330 font_ = font ;
-
1331 menu_font_size_ = std::abs(logfont.lfHeight) ;
-
1332
-
1333 return true;
-
1334 }
+
1325 font_ = font ;
+
1326 menu_font_size_ = std::abs(logfont.lfHeight) ;
+
1327
+
1328 return true;
+
1329 }
-
1335
-
- -
1344 COLORREF text_color=CLR_INVALID,
-
1345 COLORREF back_color=CLR_INVALID,
-
1346 COLORREF border_color=CLR_INVALID) {
-
1347 if(back_color != CLR_INVALID) {
-
1348 back_color_ = back_color ;
-
1349 if(!update_background_brush()) {
-
1350 return false ;
-
1351 }
-
1352 }
-
1353 if(text_color != CLR_INVALID) {
-
1354 text_color_ = text_color ;
-
1355 }
-
1356 if(border_color != CLR_INVALID) {
-
1357 border_color_ = border_color ;
-
1358 }
-
1359 return true ;
-
1360 }
+
1330
+
+ +
1339 COLORREF text_color=CLR_INVALID,
+
1340 COLORREF back_color=CLR_INVALID,
+
1341 COLORREF border_color=CLR_INVALID) {
+
1342 if(back_color != CLR_INVALID) {
+
1343 back_color_ = back_color ;
+
1344 if(!update_background_brush()) {
+
1345 return false ;
+
1346 }
+
1347 }
+
1348 if(text_color != CLR_INVALID) {
+
1349 text_color_ = text_color ;
+
1350 }
+
1351 if(border_color != CLR_INVALID) {
+
1352 border_color_ = border_color ;
+
1353 }
+
1354 return true ;
+
1355 }
-
1361
-
-
1366 bool change_icon(const std::string& icon_path) {
-
1367 if(icon_data_.cbSize > 0) {
-
1368 if(!Shell_NotifyIconW(NIM_DELETE, &icon_data_)) {
-
1369 return false ;
-
1370 }
-
1371 }
-
1372
-
1373 ZeroMemory(&icon_data_, sizeof(icon_data_)) ;
+
1356
+
+
1361 bool change_icon(const std::string& icon_path) {
+
1362 if(icon_data_.cbSize > 0) {
+
1363 if(!Shell_NotifyIconW(NIM_DELETE, &icon_data_)) {
+
1364 return false ;
+
1365 }
+
1366 }
+
1367
+
1368 ZeroMemory(&icon_data_, sizeof(icon_data_)) ;
+
1369
+
1370 if(icon_path.empty()) {
+
1371 icon_data_.cbSize = 0 ;
+
1372 return true ;
+
1373 }
1374
-
1375 if(icon_path.empty()) {
-
1376 icon_data_.cbSize = 0 ;
-
1377 return true ;
+
1375 std::wstring icon_path_wide ;
+
1376 if(!util::string2wstring(icon_path, icon_path_wide)) {
+
1377 return false ;
1378 }
1379
-
1380 std::wstring icon_path_wide ;
-
1381 if(!util::string2wstring(icon_path, icon_path_wide)) {
-
1382 return false ;
-
1383 }
-
1384
-
1385 if(!util::exists(icon_path_wide)) {
-
1386 return false ;
-
1387 }
-
1388
-
1389 icon_data_.cbSize = sizeof(icon_data_) ;
-
1390 icon_data_.hWnd = hwnd_ ;
-
1391 icon_data_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP ;
-
1392 icon_data_.uCallbackMessage = message_id_ ;
-
1393 icon_data_.hIcon = static_cast<HICON>(
-
1394 LoadImageW(
-
1395 NULL, icon_path_wide.c_str(),
-
1396 IMAGE_ICON, 0, 0, LR_LOADFROMFILE)) ;
-
1397 wcscpy_s(icon_data_.szTip, app_name_.c_str()) ;
-
1398 icon_data_.dwState = NIS_SHAREDICON ;
-
1399 icon_data_.dwStateMask = NIS_SHAREDICON ;
+
1380 if(!util::exists(icon_path_wide)) {
+
1381 return false ;
+
1382 }
+
1383
+
1384 icon_data_.cbSize = sizeof(icon_data_) ;
+
1385 icon_data_.hWnd = hwnd_ ;
+
1386 icon_data_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP ;
+
1387 icon_data_.uCallbackMessage = message_id_ ;
+
1388 icon_data_.hIcon = static_cast<HICON>(
+
1389 LoadImageW(
+
1390 NULL, icon_path_wide.c_str(),
+
1391 IMAGE_ICON, 0, 0, LR_LOADFROMFILE)) ;
+
1392 wcscpy_s(icon_data_.szTip, app_name_.c_str()) ;
+
1393 icon_data_.dwState = NIS_SHAREDICON ;
+
1394 icon_data_.dwStateMask = NIS_SHAREDICON ;
+
1395
+
1396 if(!Shell_NotifyIconW(NIM_ADD, &icon_data_)) {
+
1397 return false ;
+
1398 }
+
1400
-
1401 if(!Shell_NotifyIconW(NIM_ADD, &icon_data_)) {
-
1402 return false ;
-
1403 }
- -
1405
-
1406 return true ;
-
1407 }
+
1401 return true ;
+
1402 }
-
1408
-
1409 private:
-
1410 static LRESULT CALLBACK callback(
-
1411 HWND hwnd,
-
1412 UINT msg,
-
1413 WPARAM wparam,
-
1414 LPARAM lparam) {
-
1415 auto get_instance = [hwnd]() -> FluentTray* {
-
1416 auto upper_addr = GetWindowLongW(hwnd, 0) ;
-
1417 if(!upper_addr) {
+
1403
+
1404 private:
+
1405 static LRESULT CALLBACK callback(
+
1406 HWND hwnd,
+
1407 UINT msg,
+
1408 WPARAM wparam,
+
1409 LPARAM lparam) {
+
1410 auto get_instance = [hwnd]() -> FluentTray* {
+
1411 auto upper_addr = GetWindowLongW(hwnd, 0) ;
+
1412 if(!upper_addr) {
+
1413 return nullptr ;
+
1414 }
+
1415
+
1416 auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ;
+
1417 if(!lower_addr) {
1418 return nullptr ;
1419 }
1420
-
1421 auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ;
-
1422 if(!lower_addr) {
-
1423 return nullptr ;
-
1424 }
+
1421 FluentTray* self ;
+
1422 util::concatenate_bits(upper_addr, lower_addr, self) ;
+
1423 return self ;
+
1424 } ;
1425
-
1426 FluentTray* self ;
-
1427 util::concatenate_bits(upper_addr, lower_addr, self) ;
-
1428 return self ;
-
1429 } ;
-
1430
-
1431 if(msg == WM_DESTROY || msg == WM_QUIT || msg == WM_CLOSE) {
-
1432 if(auto self = get_instance()) {
-
1433 self->stop() ;
-
1434 return 0 ;
-
1435 }
-
1436 }
-
1437 else if(msg == WM_ACTIVATE && wparam == WA_INACTIVE) {
-
1438 if(auto self = get_instance()) {
-
1439 if(!self->hide_menu_window()) {
-
1440 self->fail() ;
-
1441 }
-
1442 return 0 ;
-
1443 }
-
1444 }
-
1445 else if(msg == WM_DRAWITEM) {
-
1446 if(auto self = get_instance()) {
-
1447 auto item = reinterpret_cast<LPDRAWITEMSTRUCT>(lparam) ;
-
1448 auto menu_idx = self->get_menu_index_from_window(item->hwndItem) ;
-
1449 if(menu_idx < 0) {
+
1426 if(msg == WM_DESTROY || msg == WM_QUIT || msg == WM_CLOSE) {
+
1427 if(auto self = get_instance()) {
+
1428 self->stop() ;
+
1429 return 0 ;
+
1430 }
+
1431 }
+
1432 else if(msg == WM_ACTIVATE && wparam == WA_INACTIVE) {
+
1433 if(auto self = get_instance()) {
+
1434 if(!self->hide_menu_window()) {
+
1435 self->fail() ;
+
1436 }
+
1437 return 0 ;
+
1438 }
+
1439 }
+
1440 else if(msg == WM_DRAWITEM) {
+
1441 if(auto self = get_instance()) {
+
1442 auto item = reinterpret_cast<LPDRAWITEMSTRUCT>(lparam) ;
+
1443 auto menu_idx = self->get_menu_index_from_window(item->hwndItem) ;
+
1444 if(menu_idx < 0) {
+
1445 return FALSE ;
+
1446 }
+
1447 auto& menu = self->menus_[menu_idx] ;
+
1448 if(!menu.draw_menu(item, self->font_)) {
+
1449 self->fail() ;
1450 return FALSE ;
1451 }
-
1452 auto& menu = self->menus_[menu_idx] ;
-
1453 if(!menu.draw_menu(item, self->font_)) {
-
1454 self->fail() ;
-
1455 return FALSE ;
-
1456 }
-
1457 return TRUE ;
-
1458 }
-
1459 }
-
1460 else if(msg == WM_CTLCOLORBTN) {
-
1461 if(auto self = get_instance()) {
-
1462 auto menu_idx = self->get_menu_index_from_window(reinterpret_cast<HWND>(lparam)) ;
-
1463 if(menu_idx < 0) {
-
1464 return DefWindowProc(hwnd, msg, wparam, lparam) ;
-
1465 }
-
1466 auto& menu = self->menus_[menu_idx] ;
-
1467 return reinterpret_cast<LRESULT>(menu.background_brush()) ;
-
1468 }
-
1469 }
-
1470 else if(msg == WM_COMMAND) {
-
1471 if(auto self = get_instance()) {
-
1472 auto menu_idx = self->get_menu_index_from_id(LOWORD(wparam)) ;
-
1473 if(menu_idx < 0) {
+
1452 return TRUE ;
+
1453 }
+
1454 }
+
1455 else if(msg == WM_CTLCOLORBTN) {
+
1456 if(auto self = get_instance()) {
+
1457 auto menu_idx = self->get_menu_index_from_window(reinterpret_cast<HWND>(lparam)) ;
+
1458 if(menu_idx < 0) {
+
1459 return DefWindowProc(hwnd, msg, wparam, lparam) ;
+
1460 }
+
1461 auto& menu = self->menus_[menu_idx] ;
+
1462 return reinterpret_cast<LRESULT>(menu.background_brush()) ;
+
1463 }
+
1464 }
+
1465 else if(msg == WM_COMMAND) {
+
1466 if(auto self = get_instance()) {
+
1467 auto menu_idx = self->get_menu_index_from_id(LOWORD(wparam)) ;
+
1468 if(menu_idx < 0) {
+
1469 return FALSE ;
+
1470 }
+
1471 auto& menu = self->menus_[menu_idx] ;
+
1472 if(!menu.process_click_event()) {
+
1473 self->stop() ;
1474 return FALSE ;
1475 }
-
1476 auto& menu = self->menus_[menu_idx] ;
-
1477 if(!menu.process_click_event()) {
-
1478 self->stop() ;
-
1479 return FALSE ;
-
1480 }
-
1481 if(menu.is_toggleable()) {
-
1482 // Update the toggle menu for checkmark
-
1483 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
+
1476 if(menu.is_toggleable()) {
+
1477 // Update the toggle menu for checkmark
+
1478 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
+
1479 return FALSE ;
+
1480 }
+
1481 }
+
1482 else {
+
1483 if(!self->hide_menu_window()) {
1484 return FALSE ;
1485 }
1486 }
-
1487 else {
-
1488 if(!self->hide_menu_window()) {
-
1489 return FALSE ;
-
1490 }
-
1491 }
-
1492 return TRUE ;
-
1493 }
-
1494 }
-
1495 else if(msg == message_id_) { //On NotifyIcon
-
1496 if(auto self = get_instance()) {
-
1497 if(lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
-
1498 self->show_menu_window() ;
-
1499 return 0 ;
-
1500 }
-
1501 }
-
1502 }
-
1503
-
1504 return DefWindowProc(hwnd, msg, wparam, lparam) ;
-
1505 }
-
1506
-
1507 int get_menu_index_from_window(HWND hwnd) {
-
1508 int i = 0 ;
-
1509 for(auto& m : menus_) {
-
1510 if(m.window_handle() == hwnd) {
-
1511 return i ;
-
1512 }
-
1513 i ++ ;
-
1514 }
-
1515 return -1 ;
-
1516 }
-
1517
-
1518 int get_menu_index_from_id(WORD id) {
-
1519 int i = 0 ;
-
1520 for(auto& m : menus_) {
-
1521 if(m.id() == static_cast<std::size_t>(id)) {
-
1522 return i ;
-
1523 }
-
1524 i ++ ;
-
1525 }
-
1526 return -1 ;
-
1527 }
-
1528
-
1529 void get_message(MSG& message) {
-
1530 if(PeekMessage(&message, hwnd_, 0, 0, PM_REMOVE)) {
-
1531 DispatchMessage(&message) ;
-
1532 }
-
1533 }
-
1534
-
1535 void fail() noexcept {
-
1536 status_ = TrayStatus::FAILED ;
-
1537 }
-
1538
-
1539 bool change_menu_back_color(FluentMenu& menu, COLORREF new_color) {
-
1540 if(!menu.set_color(
-
1541 text_color_, new_color, border_color_)) {
-
1542 return false ;
-
1543 }
-
1544 // Redraw
-
1545 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
-
1546 return false ;
-
1547 }
-
1548 return true ;
-
1549 }
-
1550
-
1551 COLORREF extract_taskbar_color() const {
-
1552 // Get Taskbar color
-
1553 APPBARDATA abd ;
-
1554 abd.cbSize = sizeof(abd) ;
-
1555 if(!SHAppBarMessage(ABM_GETTASKBARPOS, &abd)) {
-
1556 return CLR_INVALID ;
-
1557 }
-
1558
-
1559 COLORREF color = CLR_INVALID ;
-
1560 if(auto dc = GetDC(NULL)) {
-
1561 // Get Taskbar color
-
1562 color = GetPixel(
-
1563 dc,
-
1564 abd.rc.left + autocolorpick_offset_,
-
1565 abd.rc.top + autocolorpick_offset_) ;
-
1566 if(color == CLR_INVALID) {
-
1567 // if failed, use COLOR_WINDOW color.
-
1568 color = GetSysColor(COLOR_WINDOW) ;
-
1569 }
-
1570 if(!ReleaseDC(NULL, dc)) {
-
1571 return CLR_INVALID ;
-
1572 }
-
1573 }
-
1574 return color ;
-
1575 }
+
1487 return TRUE ;
+
1488 }
+
1489 }
+
1490 else if(msg == message_id_) { //On NotifyIcon
+
1491 if(auto self = get_instance()) {
+
1492 if(lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
+
1493 self->show_menu_window() ;
+
1494 return 0 ;
+
1495 }
+
1496 }
+
1497 }
+
1498
+
1499 return DefWindowProc(hwnd, msg, wparam, lparam) ;
+
1500 }
+
1501
+
1502 int get_menu_index_from_window(HWND hwnd) {
+
1503 int i = 0 ;
+
1504 for(auto& m : menus_) {
+
1505 if(m.window_handle() == hwnd) {
+
1506 return i ;
+
1507 }
+
1508 i ++ ;
+
1509 }
+
1510 return -1 ;
+
1511 }
+
1512
+
1513 int get_menu_index_from_id(WORD id) {
+
1514 int i = 0 ;
+
1515 for(auto& m : menus_) {
+
1516 if(m.id() == static_cast<std::size_t>(id)) {
+
1517 return i ;
+
1518 }
+
1519 i ++ ;
+
1520 }
+
1521 return -1 ;
+
1522 }
+
1523
+
1524 void get_message(MSG& message) {
+
1525 if(PeekMessage(&message, hwnd_, 0, 0, PM_REMOVE)) {
+
1526 DispatchMessage(&message) ;
+
1527 }
+
1528 }
+
1529
+
1530 void fail() noexcept {
+
1531 status_ = TrayStatus::FAILED ;
+
1532 }
+
1533
+
1534 bool change_menu_back_color(FluentMenu& menu, COLORREF new_color) {
+
1535 if(!menu.set_color(
+
1536 text_color_, new_color, border_color_)) {
+
1537 return false ;
+
1538 }
+
1539 // Redraw
+
1540 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
+
1541 return false ;
+
1542 }
+
1543 return true ;
+
1544 }
+
1545
+
1546 COLORREF extract_taskbar_color() const {
+
1547 // Get Taskbar color
+
1548 APPBARDATA abd ;
+
1549 abd.cbSize = sizeof(abd) ;
+
1550 if(!SHAppBarMessage(ABM_GETTASKBARPOS, &abd)) {
+
1551 return CLR_INVALID ;
+
1552 }
+
1553
+
1554 COLORREF color = CLR_INVALID ;
+
1555 if(auto dc = GetDC(NULL)) {
+
1556 // Get Taskbar color
+
1557 color = GetPixel(
+
1558 dc,
+
1559 abd.rc.left + autocolorpick_offset_,
+
1560 abd.rc.top + autocolorpick_offset_) ;
+
1561 if(color == CLR_INVALID) {
+
1562 // if failed, use COLOR_WINDOW color.
+
1563 color = GetSysColor(COLOR_WINDOW) ;
+
1564 }
+
1565 if(!ReleaseDC(NULL, dc)) {
+
1566 return CLR_INVALID ;
+
1567 }
+
1568 }
+
1569 return color ;
+
1570 }
+
1571
+
1572 static COLORREF calculate_faded_color_(
+
1573 COLORREF back_color,
+
1574 unsigned char color_decay=10) {
+
1575 auto back_gray_color = util::rgb2gray(back_color) ;
1576
-
1577 static COLORREF calculate_faded_color_(
-
1578 COLORREF back_color,
-
1579 unsigned char color_decay=10) {
-
1580 auto back_gray_color = util::rgb2gray(back_color) ;
-
1581
-
1582 unsigned char ash_value = back_gray_color ;
-
1583 if(back_gray_color < 128) {
-
1584 ash_value = static_cast<decltype(ash_value)>(
-
1585 (std::min)(ash_value + color_decay, 255)) ;
-
1586 }
-
1587 else {
-
1588 ash_value = static_cast<decltype(ash_value)>(
-
1589 (std::max)(ash_value - color_decay, 0)) ;
-
1590 }
-
1591 return RGB(ash_value, ash_value, ash_value) ;
-
1592 }
-
1593
-
1594 static COLORREF calculate_text_color_(COLORREF back_color) {
-
1595 auto back_gray_color = util::rgb2gray(back_color) ;
-
1596
-
1597 auto text_color = GetSysColor(COLOR_WINDOWTEXT) ;
-
1598 if(back_gray_color < 128) {
-
1599 // if dark background, use light text color.
-
1600 text_color = 0x00FFFFFF & ~text_color ;
-
1601 }
-
1602 return text_color ;
-
1603 }
-
1604
-
1605 bool update_background_brush() {
-
1606 if(back_brush_) {
-
1607 // Release old handle.
-
1608 if(!DeleteObject(back_brush_)) {
-
1609 return false ;
-
1610 }
-
1611 }
-
1612 back_brush_ = CreateSolidBrush(back_color_) ;
-
1613 if(back_brush_ == NULL) {
-
1614 return false ;
-
1615 }
-
1616
-
1617 if(!SetClassLongPtr(
-
1618 hwnd_, GCLP_HBRBACKGROUND,
-
1619 reinterpret_cast<LONG_PTR>(back_brush_))) {
-
1620 return false ;
-
1621 }
-
1622
-
1623 return true ;
-
1624 }
-
1625 } ;
+
1577 unsigned char ash_value = back_gray_color ;
+
1578 if(back_gray_color < 128) {
+
1579 ash_value = static_cast<decltype(ash_value)>(
+
1580 (std::min)(ash_value + color_decay, 255)) ;
+
1581 }
+
1582 else {
+
1583 ash_value = static_cast<decltype(ash_value)>(
+
1584 (std::max)(ash_value - color_decay, 0)) ;
+
1585 }
+
1586 return RGB(ash_value, ash_value, ash_value) ;
+
1587 }
+
1588
+
1589 static COLORREF calculate_text_color_(COLORREF back_color) {
+
1590 auto back_gray_color = util::rgb2gray(back_color) ;
+
1591
+
1592 auto text_color = GetSysColor(COLOR_WINDOWTEXT) ;
+
1593 if(back_gray_color < 128) {
+
1594 // if dark background, use light text color.
+
1595 text_color = 0x00FFFFFF & ~text_color ;
+
1596 }
+
1597 return text_color ;
+
1598 }
+
1599
+
1600 bool update_background_brush() {
+
1601 if(back_brush_) {
+
1602 // Release old handle.
+
1603 if(!DeleteObject(back_brush_)) {
+
1604 return false ;
+
1605 }
+
1606 }
+
1607 back_brush_ = CreateSolidBrush(back_color_) ;
+
1608 if(back_brush_ == NULL) {
+
1609 return false ;
+
1610 }
+
1611
+
1612 if(!SetClassLongPtr(
+
1613 hwnd_, GCLP_HBRBACKGROUND,
+
1614 reinterpret_cast<LONG_PTR>(back_brush_))) {
+
1615 return false ;
+
1616 }
+
1617
+
1618 return true ;
+
1619 }
+
1620 } ;
-
1626
-
1627 unsigned int FluentTray::message_id_ ;
-
1628}
-
1629
-
1630#endif
+
1621
+
1622 unsigned int FluentTray::message_id_ ;
+
1623}
+
1624
+
1625#endif
Class with information on each menu.
Definition fluent_tray.hpp:250
bool is_mouse_over() const
Checks whether the mouse cursor is over the menu or not.
Definition fluent_tray.hpp:395
bool set_color(const COLORREF &text_color=CLR_INVALID, const COLORREF &back_color=CLR_INVALID, const COLORREF &border_color=CLR_INVALID) noexcept
Set the menu color.
Definition fluent_tray.hpp:500
@@ -1563,35 +1558,35 @@
void check() noexcept
Checks the menu if it is toggleable.
Definition fluent_tray.hpp:411
FluentMenu(const FluentMenu &)=default
Class with information on the entire tray.
Definition fluent_tray.hpp:672
-
bool show_balloon_tip(const std::string &title, const std::string &message)
Shows a balloon tip that is placed in the notification area.
Definition fluent_tray.hpp:1153
-
virtual ~FluentTray() noexcept
Definition fluent_tray.hpp:750
-
bool set_color(COLORREF text_color=CLR_INVALID, COLORREF back_color=CLR_INVALID, COLORREF border_color=CLR_INVALID)
Set colors to draw menus.
Definition fluent_tray.hpp:1343
-
std::vector< FluentMenu >::iterator end() noexcept
Returns an iterator to the end of menus.
Definition fluent_tray.hpp:1212
+
bool show_balloon_tip(const std::string &title, const std::string &message)
Shows a balloon tip that is placed in the notification area.
Definition fluent_tray.hpp:1148
+
virtual ~FluentTray() noexcept
Definition fluent_tray.hpp:758
+
bool set_color(COLORREF text_color=CLR_INVALID, COLORREF back_color=CLR_INVALID, COLORREF border_color=CLR_INVALID)
Set colors to draw menus.
Definition fluent_tray.hpp:1338
+
std::vector< FluentMenu >::iterator end() noexcept
Returns an iterator to the end of menus.
Definition fluent_tray.hpp:1207
FluentTray & operator=(const FluentTray &)=delete
-
bool create_tray(const std::string &app_name, const std::string &icon_path="", LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char opacity=255, bool round_corner=true)
Initialize tray and create icon on tray.
Definition fluent_tray.hpp:771
-
bool show_menu_window()
Show the menu window above the tray icon.
Definition fluent_tray.hpp:1008
-
void stop() noexcept
Exit the tray successfully.
Definition fluent_tray.hpp:1196
+
bool show_menu_window()
Show the menu window above the tray icon.
Definition fluent_tray.hpp:1003
+
void stop() noexcept
Exit the tray successfully.
Definition fluent_tray.hpp:1191
FluentTray & operator=(FluentTray &&)=default
-
bool add_menu(const std::string &label_text="", const std::string &icon_path="", bool toggleable=false, const std::string &checkmark="✓", const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})
Add a menu in order from the top.
Definition fluent_tray.hpp:900
-
bool set_font(LONG font_size=0, LONG font_weight=0, const std::string &font_name="")
Set font information to draw menus.
Definition fluent_tray.hpp:1280
-
TrayStatus status() const noexcept
Get the current status of tray.
Definition fluent_tray.hpp:1189
-
FluentTray(int message_id_offset=25, int autocolorpick_offset=5, unsigned char autofadedborder_from_backcolor=10)
Create tray object.
Definition fluent_tray.hpp:713
-
const FluentMenu & back() const
Returns the const reference to the last of menus.
Definition fluent_tray.hpp:1260
-
bool change_icon(const std::string &icon_path)
Load the image file and change the icon.
Definition fluent_tray.hpp:1366
-
std::size_t count_menus() const noexcept
Returns the number of menus.
Definition fluent_tray.hpp:1268
-
bool update_with_loop(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(1))
Create a message loop to update the tray.
Definition fluent_tray.hpp:978
-
std::vector< FluentMenu >::const_iterator cbegin() const noexcept
Returns a constant iterator to the beginning of menus.
Definition fluent_tray.hpp:1220
-
std::vector< FluentMenu >::const_iterator cend() const noexcept
Returns a constant iterator to the end of menus.
Definition fluent_tray.hpp:1228
-
const FluentMenu & front() const
Returns the const reference to the beginning of menus.
Definition fluent_tray.hpp:1244
-
void add_separator()
Add a separator line under the last menu item added.
Definition fluent_tray.hpp:923
-
bool hide_menu_window()
Hide the menu window above the tray icon.
Definition fluent_tray.hpp:1139
+
bool add_menu(const std::string &label_text="", const std::string &icon_path="", bool toggleable=false, const std::string &checkmark="✓", const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})
Add a menu in order from the top.
Definition fluent_tray.hpp:895
+
bool set_font(LONG font_size=0, LONG font_weight=0, const std::string &font_name="")
Set font information to draw menus.
Definition fluent_tray.hpp:1275
+
TrayStatus status() const noexcept
Get the current status of tray.
Definition fluent_tray.hpp:1184
+
const FluentMenu & back() const
Returns the const reference to the last of menus.
Definition fluent_tray.hpp:1255
+
bool change_icon(const std::string &icon_path)
Load the image file and change the icon.
Definition fluent_tray.hpp:1361
+
std::size_t count_menus() const noexcept
Returns the number of menus.
Definition fluent_tray.hpp:1263
+
bool update_with_loop(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(1))
Create a message loop to update the tray.
Definition fluent_tray.hpp:973
+
std::vector< FluentMenu >::const_iterator cbegin() const noexcept
Returns a constant iterator to the beginning of menus.
Definition fluent_tray.hpp:1215
+
std::vector< FluentMenu >::const_iterator cend() const noexcept
Returns a constant iterator to the end of menus.
Definition fluent_tray.hpp:1223
+
const FluentMenu & front() const
Returns the const reference to the beginning of menus.
Definition fluent_tray.hpp:1239
+
void add_separator()
Add a separator line under the last menu item added.
Definition fluent_tray.hpp:918
+
bool hide_menu_window()
Hide the menu window above the tray icon.
Definition fluent_tray.hpp:1134
FluentTray(const FluentTray &)=delete
-
FluentMenu & front()
Returns the reference to the beginning of menus.
Definition fluent_tray.hpp:1236
+
FluentMenu & front()
Returns the reference to the beginning of menus.
Definition fluent_tray.hpp:1231
FluentTray(FluentTray &&)=default
-
HWND window_handle() const noexcept
Refer to the handle of menu window.
Definition fluent_tray.hpp:1000
-
std::vector< FluentMenu >::iterator begin() noexcept
Returns an iterator to the beginning of menus.
Definition fluent_tray.hpp:1204
-
bool update()
Get window message and update tray.
Definition fluent_tray.hpp:933
-
FluentMenu & back()
Returns the reference to the last of menus.
Definition fluent_tray.hpp:1252
+
HWND window_handle() const noexcept
Refer to the handle of menu window.
Definition fluent_tray.hpp:995
+
std::vector< FluentMenu >::iterator begin() noexcept
Returns an iterator to the beginning of menus.
Definition fluent_tray.hpp:1199
+
bool update()
Get window message and update tray.
Definition fluent_tray.hpp:928
+
bool create_tray(const std::string &app_name, const std::string &icon_path="", unsigned char opacity=255, bool round_corner=true)
Initialize tray and create icon on tray.
Definition fluent_tray.hpp:775
+
FluentTray(LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, int message_id_offset=25)
Create tray object.
Definition fluent_tray.hpp:717
+
FluentMenu & back()
Returns the reference to the last of menus.
Definition fluent_tray.hpp:1247
bool exists(const std::wstring &path)
Checks if the file exists.
Definition fluent_tray.hpp:223
constexpr std::size_t bit2mask(std::size_t bits) noexcept
Generates a mask with the specified number of lower bits set to 1.
Definition fluent_tray.hpp:160
bool wstring2string(const std::wstring &wstr, std::string &str)
Converts a wide string to a UTF-8 encoded string.
Definition fluent_tray.hpp:129
diff --git a/docs/functions.html b/docs/functions.html index a2f4223..a2f0679 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -97,7 +97,7 @@

- c -

@@ -113,7 +113,7 @@

- e -

diff --git a/docs/search/all_2.js b/docs/search/all_2.js index 3b4a0b3..aa42065 100644 --- a/docs/search/all_2.js +++ b/docs/search/all_2.js @@ -10,5 +10,5 @@ var searchData= ['concept_7',['Concept',['../index.html#autotoc_md0',1,'']]], ['count_5fmenus_8',['count_menus',['../classfluent__tray_1_1_fluent_tray.html#a6e7ec8d9589d3b1fdb14885349f8daec',1,'fluent_tray::FluentTray']]], ['create_5fmenu_9',['create_menu',['../classfluent__tray_1_1_fluent_menu.html#a9626aab1a2407277fc347d97147ca191',1,'fluent_tray::FluentMenu']]], - ['create_5ftray_10',['create_tray',['../classfluent__tray_1_1_fluent_tray.html#a1ce960696567087f55044e711ed4ef21',1,'fluent_tray::FluentTray']]] + ['create_5ftray_10',['create_tray',['../classfluent__tray_1_1_fluent_tray.html#af7428f277fb0061101367ef3d1e084ba',1,'fluent_tray::FluentTray']]] ]; diff --git a/docs/search/all_5.js b/docs/search/all_5.js index 4f5a6f1..782a959 100644 --- a/docs/search/all_5.js +++ b/docs/search/all_5.js @@ -6,6 +6,6 @@ var searchData= ['fluent_5ftray_2ehpp_3',['fluent_tray.hpp',['../fluent__tray_8hpp.html',1,'']]], ['fluent_5ftray_3a_3autil_4',['util',['../namespacefluent__tray_1_1util.html',1,'fluent_tray']]], ['fluentmenu_5',['FluentMenu',['../classfluent__tray_1_1_fluent_menu.html',1,'fluent_tray::FluentMenu'],['../classfluent__tray_1_1_fluent_menu.html#a55a1de08b1e116b71f2225b76fa1a8ff',1,'fluent_tray::FluentMenu::FluentMenu(bool toggleable=false, const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})'],['../classfluent__tray_1_1_fluent_menu.html#ae65751fe8b47abcae26e99d2cc092c85',1,'fluent_tray::FluentMenu::FluentMenu(const FluentMenu &)=default'],['../classfluent__tray_1_1_fluent_menu.html#a68503bfb45988babdad9d70be8633698',1,'fluent_tray::FluentMenu::FluentMenu(FluentMenu &&)=default']]], - ['fluenttray_6',['FluentTray',['../classfluent__tray_1_1_fluent_tray.html',1,'fluent_tray::FluentTray'],['../classfluent__tray_1_1_fluent_tray.html#a63a9dd95b682b2a0ff45b4c7e3dd5877',1,'fluent_tray::FluentTray::FluentTray(int message_id_offset=25, int autocolorpick_offset=5, unsigned char autofadedborder_from_backcolor=10)'],['../classfluent__tray_1_1_fluent_tray.html#ac538f9a69ab74ead314a5004f717080f',1,'fluent_tray::FluentTray::FluentTray(const FluentTray &)=delete'],['../classfluent__tray_1_1_fluent_tray.html#adc5d4b971a378080dea22225c0a8e3a1',1,'fluent_tray::FluentTray::FluentTray(FluentTray &&)=default']]], + ['fluenttray_6',['FluentTray',['../classfluent__tray_1_1_fluent_tray.html',1,'fluent_tray::FluentTray'],['../classfluent__tray_1_1_fluent_tray.html#af8f0e2ea4e4c511b3afbd3e7469f46aa',1,'fluent_tray::FluentTray::FluentTray(LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, int message_id_offset=25)'],['../classfluent__tray_1_1_fluent_tray.html#ac538f9a69ab74ead314a5004f717080f',1,'fluent_tray::FluentTray::FluentTray(const FluentTray &)=delete'],['../classfluent__tray_1_1_fluent_tray.html#adc5d4b971a378080dea22225c0a8e3a1',1,'fluent_tray::FluentTray::FluentTray(FluentTray &&)=default']]], ['front_7',['front',['../classfluent__tray_1_1_fluent_tray.html#acd10bcf8769e9851026dd1302323cc90',1,'fluent_tray::FluentTray::front()'],['../classfluent__tray_1_1_fluent_tray.html#a974f39be7c66bf61750de98331b063c3',1,'fluent_tray::FluentTray::front() const']]] ]; diff --git a/docs/search/functions_2.js b/docs/search/functions_2.js index fe25046..9949618 100644 --- a/docs/search/functions_2.js +++ b/docs/search/functions_2.js @@ -8,5 +8,5 @@ var searchData= ['concatenate_5fbits_5',['concatenate_bits',['../namespacefluent__tray_1_1util.html#a7c27457aa89604dc7f6d7ecbb17a0fc4',1,'fluent_tray::util']]], ['count_5fmenus_6',['count_menus',['../classfluent__tray_1_1_fluent_tray.html#a6e7ec8d9589d3b1fdb14885349f8daec',1,'fluent_tray::FluentTray']]], ['create_5fmenu_7',['create_menu',['../classfluent__tray_1_1_fluent_menu.html#a9626aab1a2407277fc347d97147ca191',1,'fluent_tray::FluentMenu']]], - ['create_5ftray_8',['create_tray',['../classfluent__tray_1_1_fluent_tray.html#a1ce960696567087f55044e711ed4ef21',1,'fluent_tray::FluentTray']]] + ['create_5ftray_8',['create_tray',['../classfluent__tray_1_1_fluent_tray.html#af7428f277fb0061101367ef3d1e084ba',1,'fluent_tray::FluentTray']]] ]; diff --git a/docs/search/functions_5.js b/docs/search/functions_5.js index dea0f90..ce7b2f9 100644 --- a/docs/search/functions_5.js +++ b/docs/search/functions_5.js @@ -1,6 +1,6 @@ var searchData= [ ['fluentmenu_0',['FluentMenu',['../classfluent__tray_1_1_fluent_menu.html#a55a1de08b1e116b71f2225b76fa1a8ff',1,'fluent_tray::FluentMenu::FluentMenu(bool toggleable=false, const std::function< bool(void)> &callback=[] {return true ;}, const std::function< bool(void)> &unchecked_callback=[] {return true ;})'],['../classfluent__tray_1_1_fluent_menu.html#ae65751fe8b47abcae26e99d2cc092c85',1,'fluent_tray::FluentMenu::FluentMenu(const FluentMenu &)=default'],['../classfluent__tray_1_1_fluent_menu.html#a68503bfb45988babdad9d70be8633698',1,'fluent_tray::FluentMenu::FluentMenu(FluentMenu &&)=default']]], - ['fluenttray_1',['FluentTray',['../classfluent__tray_1_1_fluent_tray.html#a63a9dd95b682b2a0ff45b4c7e3dd5877',1,'fluent_tray::FluentTray::FluentTray(int message_id_offset=25, int autocolorpick_offset=5, unsigned char autofadedborder_from_backcolor=10)'],['../classfluent__tray_1_1_fluent_tray.html#ac538f9a69ab74ead314a5004f717080f',1,'fluent_tray::FluentTray::FluentTray(const FluentTray &)=delete'],['../classfluent__tray_1_1_fluent_tray.html#adc5d4b971a378080dea22225c0a8e3a1',1,'fluent_tray::FluentTray::FluentTray(FluentTray &&)=default']]], + ['fluenttray_1',['FluentTray',['../classfluent__tray_1_1_fluent_tray.html#af8f0e2ea4e4c511b3afbd3e7469f46aa',1,'fluent_tray::FluentTray::FluentTray(LONG menu_x_margin=5, LONG menu_y_margin=5, LONG menu_x_pad=10, LONG menu_y_pad=5, unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, int message_id_offset=25)'],['../classfluent__tray_1_1_fluent_tray.html#ac538f9a69ab74ead314a5004f717080f',1,'fluent_tray::FluentTray::FluentTray(const FluentTray &)=delete'],['../classfluent__tray_1_1_fluent_tray.html#adc5d4b971a378080dea22225c0a8e3a1',1,'fluent_tray::FluentTray::FluentTray(FluentTray &&)=default']]], ['front_2',['front',['../classfluent__tray_1_1_fluent_tray.html#acd10bcf8769e9851026dd1302323cc90',1,'fluent_tray::FluentTray::front()'],['../classfluent__tray_1_1_fluent_tray.html#a974f39be7c66bf61750de98331b063c3',1,'fluent_tray::FluentTray::front() const']]] ]; diff --git a/include/fluent_tray.hpp b/include/fluent_tray.hpp index 14b1e6a..60f3b92 100644 --- a/include/fluent_tray.hpp +++ b/include/fluent_tray.hpp @@ -706,14 +706,22 @@ namespace fluent_tray public: /** * @brief Create tray object. - * @param [in] message_id_offset Unique message identifier. - * @param [in] autocolorpick_offset Pixel offset to determine the background color. + * @param [in] menu_x_margin Horizontal margins outside menus. + * @param [in] menu_y_margin Vertical margins outside menus. + * @param [in] menu_x_pad Horizontal paddings inside menus. + * @param [in] menu_y_pad Vertical paddings inside menus. * @param [in] autofadedborder_from_backcolor Decay value from the background color to determine the background color of the currently selected menu and the color of the separator line. + * @param [in] autocolorpick_offset Pixel offset to determine the background color. + * @param [in] message_id_offset Unique message identifier. */ explicit FluentTray( - int message_id_offset=25, + LONG menu_x_margin=5, + LONG menu_y_margin=5, + LONG menu_x_pad=10, + LONG menu_y_pad=5, + unsigned char autofadedborder_from_backcolor=10, int autocolorpick_offset=5, - unsigned char autofadedborder_from_backcolor=10) + int message_id_offset=25) : menus_(), mouse_is_over_(), app_name_(), @@ -723,10 +731,10 @@ namespace fluent_tray icon_data_(), status_(TrayStatus::STOPPED), next_menu_id_(1), - menu_x_margin_(5), - menu_y_margin_(5), - menu_x_pad_(5), - menu_y_pad_(5), + menu_x_margin_(menu_x_margin), + menu_y_margin_(menu_y_margin), + menu_x_pad_(menu_x_pad), + menu_y_pad_(menu_y_pad), text_color_(CLR_INVALID), back_color_(CLR_INVALID), border_color_(CLR_INVALID), @@ -760,10 +768,6 @@ namespace fluent_tray * @brief Initialize tray and create icon on tray. * @param [in] app_name The application name to be displayed as tooltip text. * @param [in] icon_path A UTF-8 encoded path to the icon to be displayed in the system tray. - * @param [in] menu_x_margin Horizontal margins outside menus. - * @param [in] menu_y_margin Vertical margins outside menus. - * @param [in] menu_x_pad Horizontal paddings inside menus. - * @param [in] menu_y_pad Vertical paddings inside menus. * @param [in] opacity Menu opacity from 0 to 255. * @param [in] round_corner Option to round the corners of the menu window (Windows 11 only) * @return Returns true on success, false on failure. @@ -771,21 +775,12 @@ namespace fluent_tray bool create_tray( const std::string& app_name, const std::string& icon_path="", - LONG menu_x_margin=5, - LONG menu_y_margin=5, - LONG menu_x_pad=10, - LONG menu_y_pad=5, - unsigned char opacity=255, + unsigned char opacity=255, bool round_corner=true) { if(!util::string2wstring(app_name, app_name_)) { return false ; } - menu_x_margin_ = menu_x_margin ; - menu_y_margin_ = menu_y_margin ; - menu_x_pad_ = menu_x_pad ; - menu_y_pad_ = menu_y_pad ; - WNDCLASSW winc ; winc.style = CS_HREDRAW | CS_VREDRAW ; winc.lpfnWndProc = &FluentTray::callback ;