diff --git a/docs/classfluent__tray_1_1_fluent_menu.html b/docs/classfluent__tray_1_1_fluent_menu.html index b9e91bd..5a2ee8e 100644 --- a/docs/classfluent__tray_1_1_fluent_menu.html +++ b/docs/classfluent__tray_1_1_fluent_menu.html @@ -197,7 +197,7 @@

[in]toggleableCreate a switchable menu [in]callbackFunction called when a click on the menu or a check is enabled. - [in]unchecked_callbackFunction called when a check is distabled. + [in]unchecked_callbackFunction called when a check is disabled. diff --git a/docs/classfluent__tray_1_1_fluent_tray.html b/docs/classfluent__tray_1_1_fluent_tray.html index 2cdd985..91f5538 100644 --- a/docs/classfluent__tray_1_1_fluent_tray.html +++ b/docs/classfluent__tray_1_1_fluent_tray.html @@ -301,12 +301,12 @@

Parameters
- - - - - - + + + + + +
[in]label_text
[in]icon_path
[in]toggleable
[in]checkmark
[in]callback
[in]unchecked_callback
[in]label_textThe UTF-8 encoded string of the button label.
[in]icon_pathAn icon path to show next to the label.
[in]toggleableCreate a switchable menu
[in]checkmarkA checkmark string.
[in]callbackFunction called when a click on the menu or a check is enabled.
[in]unchecked_callbackFunction called when a check is disabled.
@@ -429,14 +429,14 @@

Parameters
- - - - - - - - + + + + + + + +
[in]app_name
[in]icon_path
[in]menu_x_margin
[in]menu_y_margin
[in]menu_x_pad
[in]menu_y_pad
[in]opacity
[in]round_corner
[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)
@@ -557,9 +557,9 @@

Parameters
- - - + + +
[in]text_color
[in]back_color
[in]color_decay
[in]text_colorThe color for label text.
[in]back_colorThe color for background.
[in]color_decayDecay value from the background color to determine the background color of the currently selected menu and the color of the separator line.
@@ -602,13 +602,14 @@

Parameters
- - - + + +
[in]font_size
[in]font_weight
[in]font_name
[in]font_sizeThe height of fonts.
[in]font_weightThe value from 0 to 1000 to determine font weight.
[in]font_nameThe UTF-8 encoded font name for label rendering.
-
Returns
Returns true on success, false on failure.
+
Returns
Returns true on success, false on failure.
+

For font_weight, you can use the constant value specified for lfWeght in LOGFONT. The default value used is FW_MEDIUM(500).

diff --git a/docs/fluent__tray_8hpp_source.html b/docs/fluent__tray_8hpp_source.html index 7c167f0..f1d9055 100644 --- a/docs/fluent__tray_8hpp_source.html +++ b/docs/fluent__tray_8hpp_source.html @@ -1005,322 +1005,322 @@
1058 }
1059
-
- -
1068 LONG font_size=0,
-
1069 LONG font_weight=0,
-
1070 const std::string& font_name="") {
-
1071 NONCLIENTMETRICS metrics ;
-
1072 metrics.cbSize = sizeof(metrics) ;
-
1073
-
1074 if(!SystemParametersInfo(
-
1075 SPI_GETNONCLIENTMETRICS,
-
1076 metrics.cbSize, &metrics, 0)) {
-
1077 return false ;
-
1078 }
-
1079
-
1080 auto& logfont = metrics.lfCaptionFont ;
-
1081 if(font_size != 0) {
-
1082 logfont.lfHeight = font_size ;
-
1083 }
-
1084 else {
-
1085 logfont.lfHeight = 20 ;
-
1086 }
-
1087 if(font_weight != 0) {
-
1088 logfont.lfWeight = font_weight ;
-
1089 }
-
1090 else {
-
1091 logfont.lfWeight = FW_MEDIUM ;
-
1092 }
-
1093
-
1094 if(!font_name.empty()) {
-
1095 std::wstring font_name_wide ;
-
1096 if(!util::string2wstring(font_name, font_name_wide)) {
-
1097 return false ;
-
1098 }
-
1099 auto dst = logfont.lfFaceName ;
-
1100
-
1101 if(font_name_wide.size() < LF_FACESIZE) {
-
1102 std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * font_name_wide.length()) ;
-
1103 dst[font_name_wide.size()] = L'\0' ;
-
1104 }
-
1105 else {
-
1106 std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * (LF_FACESIZE - 1)) ;
-
1107 dst[LF_FACESIZE - 1] = L'\0' ;
-
1108 }
-
1109 }
-
1110
-
1111 auto font = CreateFontIndirectW(&logfont) ;
-
1112 if(!font) {
-
1113 return false ;
-
1114 }
-
1115 font_ = font ;
-
1116 menu_font_size_ = std::abs(logfont.lfHeight) ;
-
1117
-
1118 return true;
-
1119 }
+
+ +
1069 LONG font_size=0,
+
1070 LONG font_weight=0,
+
1071 const std::string& font_name="") {
+
1072 NONCLIENTMETRICS metrics ;
+
1073 metrics.cbSize = sizeof(metrics) ;
+
1074
+
1075 if(!SystemParametersInfo(
+
1076 SPI_GETNONCLIENTMETRICS,
+
1077 metrics.cbSize, &metrics, 0)) {
+
1078 return false ;
+
1079 }
+
1080
+
1081 auto& logfont = metrics.lfCaptionFont ;
+
1082 if(font_size != 0) {
+
1083 logfont.lfHeight = font_size ;
+
1084 }
+
1085 else {
+
1086 logfont.lfHeight = 20 ;
+
1087 }
+
1088 if(font_weight != 0) {
+
1089 logfont.lfWeight = font_weight ;
+
1090 }
+
1091 else {
+
1092 logfont.lfWeight = FW_MEDIUM ;
+
1093 }
+
1094
+
1095 if(!font_name.empty()) {
+
1096 std::wstring font_name_wide ;
+
1097 if(!util::string2wstring(font_name, font_name_wide)) {
+
1098 return false ;
+
1099 }
+
1100 auto dst = logfont.lfFaceName ;
+
1101
+
1102 if(font_name_wide.size() < LF_FACESIZE) {
+
1103 std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * font_name_wide.length()) ;
+
1104 dst[font_name_wide.size()] = L'\0' ;
+
1105 }
+
1106 else {
+
1107 std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * (LF_FACESIZE - 1)) ;
+
1108 dst[LF_FACESIZE - 1] = L'\0' ;
+
1109 }
+
1110 }
+
1111
+
1112 auto font = CreateFontIndirectW(&logfont) ;
+
1113 if(!font) {
+
1114 return false ;
+
1115 }
+
1116 font_ = font ;
+
1117 menu_font_size_ = std::abs(logfont.lfHeight) ;
+
1118
+
1119 return true;
+
1120 }
-
1120
-
- -
1129 const COLORREF& text_color=CLR_INVALID,
-
1130 const COLORREF& back_color=CLR_INVALID,
-
1131 unsigned char color_decay=10) {
-
1132 if(back_color == CLR_INVALID) {
-
1133 // Get Taskbar color
-
1134 APPBARDATA abd ;
-
1135 abd.cbSize = sizeof(abd) ;
-
1136 if(!SHAppBarMessage(ABM_GETTASKBARPOS, &abd)) {
-
1137 return false ;
-
1138 }
-
1139
-
1140 if(auto dc = GetDC(NULL)) {
-
1141 // Get Taskbar color
-
1142 back_color_ = GetPixel(dc, abd.rc.left + 1, abd.rc.top + 1) ;
-
1143 if(back_color_ == CLR_INVALID) {
-
1144 // if failed, use COLOR_WINDOW color.
-
1145 back_color_ = GetSysColor(COLOR_WINDOW) ;
-
1146 }
-
1147 if(!ReleaseDC(NULL, dc)) {
-
1148 return false ;
-
1149 }
-
1150 }
-
1151 }
-
1152 else {
-
1153 back_color_ = back_color ;
-
1154 }
-
1155
-
1156 auto back_gray_color_ = util::rgb2gray(back_color_) ;
-
1157
-
1158 unsigned char ash_value = back_gray_color_ ;
-
1159 if(back_gray_color_ < 128) {
-
1160 ash_value = static_cast<decltype(ash_value)>(
-
1161 (std::min)(ash_value + color_decay, 255)) ;
-
1162 }
-
1163 else {
-
1164 ash_value = static_cast<decltype(ash_value)>(
-
1165 (std::max)(ash_value - color_decay, 0)) ;
-
1166 }
-
1167 ash_color_ = RGB(ash_value, ash_value, ash_value) ;
-
1168
-
1169 if(text_color == CLR_INVALID) {
-
1170 text_color_ = GetSysColor(COLOR_WINDOWTEXT) ;
-
1171 if(back_gray_color_ < 128) {
-
1172 // if dark background, use light text color.
-
1173 text_color_ = 0x00FFFFFF & ~text_color_ ;
-
1174 }
-
1175 }
-
1176 else {
-
1177 text_color_ = text_color ;
-
1178 }
-
1179
-
1180 if(back_brush_) {
-
1181 // Release old handle.
-
1182 if(!DeleteObject(back_brush_)) {
-
1183 return false ;
-
1184 }
-
1185 }
-
1186 back_brush_ = CreateSolidBrush(back_color_) ;
-
1187 if(back_brush_ == NULL) {
-
1188 return false ;
-
1189 }
-
1190
-
1191 if(!SetClassLongPtr(
-
1192 hwnd_, GCLP_HBRBACKGROUND,
-
1193 reinterpret_cast<LONG_PTR>(back_brush_))) {
-
1194 return false ;
-
1195 }
-
1196
-
1197 return true ;
-
1198 }
+
1121
+
+ +
1130 const COLORREF& text_color=CLR_INVALID,
+
1131 const COLORREF& back_color=CLR_INVALID,
+
1132 unsigned char color_decay=10) {
+
1133 if(back_color == CLR_INVALID) {
+
1134 // Get Taskbar color
+
1135 APPBARDATA abd ;
+
1136 abd.cbSize = sizeof(abd) ;
+
1137 if(!SHAppBarMessage(ABM_GETTASKBARPOS, &abd)) {
+
1138 return false ;
+
1139 }
+
1140
+
1141 if(auto dc = GetDC(NULL)) {
+
1142 // Get Taskbar color
+
1143 back_color_ = GetPixel(dc, abd.rc.left + 1, abd.rc.top + 1) ;
+
1144 if(back_color_ == CLR_INVALID) {
+
1145 // if failed, use COLOR_WINDOW color.
+
1146 back_color_ = GetSysColor(COLOR_WINDOW) ;
+
1147 }
+
1148 if(!ReleaseDC(NULL, dc)) {
+
1149 return false ;
+
1150 }
+
1151 }
+
1152 }
+
1153 else {
+
1154 back_color_ = back_color ;
+
1155 }
+
1156
+
1157 auto back_gray_color_ = util::rgb2gray(back_color_) ;
+
1158
+
1159 unsigned char ash_value = back_gray_color_ ;
+
1160 if(back_gray_color_ < 128) {
+
1161 ash_value = static_cast<decltype(ash_value)>(
+
1162 (std::min)(ash_value + color_decay, 255)) ;
+
1163 }
+
1164 else {
+
1165 ash_value = static_cast<decltype(ash_value)>(
+
1166 (std::max)(ash_value - color_decay, 0)) ;
+
1167 }
+
1168 ash_color_ = RGB(ash_value, ash_value, ash_value) ;
+
1169
+
1170 if(text_color == CLR_INVALID) {
+
1171 text_color_ = GetSysColor(COLOR_WINDOWTEXT) ;
+
1172 if(back_gray_color_ < 128) {
+
1173 // if dark background, use light text color.
+
1174 text_color_ = 0x00FFFFFF & ~text_color_ ;
+
1175 }
+
1176 }
+
1177 else {
+
1178 text_color_ = text_color ;
+
1179 }
+
1180
+
1181 if(back_brush_) {
+
1182 // Release old handle.
+
1183 if(!DeleteObject(back_brush_)) {
+
1184 return false ;
+
1185 }
+
1186 }
+
1187 back_brush_ = CreateSolidBrush(back_color_) ;
+
1188 if(back_brush_ == NULL) {
+
1189 return false ;
+
1190 }
+
1191
+
1192 if(!SetClassLongPtr(
+
1193 hwnd_, GCLP_HBRBACKGROUND,
+
1194 reinterpret_cast<LONG_PTR>(back_brush_))) {
+
1195 return false ;
+
1196 }
+
1197
+
1198 return true ;
+
1199 }
-
1199
-
-
1204 bool change_icon(const std::string& icon_path) {
-
1205 if(icon_data_.cbSize > 0) {
-
1206 if(!Shell_NotifyIconW(NIM_DELETE, &icon_data_)) {
-
1207 return false ;
-
1208 }
-
1209 }
-
1210
-
1211 ZeroMemory(&icon_data_, sizeof(icon_data_)) ;
-
1212
-
1213 if(icon_path.empty()) {
-
1214 icon_data_.cbSize = 0 ;
-
1215 return true ;
-
1216 }
-
1217
-
1218 std::wstring icon_path_wide ;
-
1219 if(!util::string2wstring(icon_path, icon_path_wide)) {
-
1220 return false ;
-
1221 }
-
1222
-
1223 if(!util::exists(icon_path_wide)) {
-
1224 return false ;
-
1225 }
-
1226
-
1227 icon_data_.cbSize = sizeof(icon_data_) ;
-
1228 icon_data_.hWnd = hwnd_ ;
-
1229 icon_data_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP ;
-
1230 icon_data_.uCallbackMessage = MESSAGE_ID ;
-
1231 icon_data_.hIcon = static_cast<HICON>(
-
1232 LoadImageW(
-
1233 NULL, icon_path_wide.c_str(),
-
1234 IMAGE_ICON, 0, 0, LR_LOADFROMFILE)) ;
-
1235 wcscpy_s(icon_data_.szTip, app_name_.c_str()) ;
-
1236 icon_data_.dwState = NIS_SHAREDICON ;
-
1237 icon_data_.dwStateMask = NIS_SHAREDICON ;
-
1238
-
1239 if(!Shell_NotifyIconW(NIM_ADD, &icon_data_)) {
-
1240 return false ;
-
1241 }
- -
1243
-
1244 return true ;
-
1245 }
+
1200
+
+
1205 bool change_icon(const std::string& icon_path) {
+
1206 if(icon_data_.cbSize > 0) {
+
1207 if(!Shell_NotifyIconW(NIM_DELETE, &icon_data_)) {
+
1208 return false ;
+
1209 }
+
1210 }
+
1211
+
1212 ZeroMemory(&icon_data_, sizeof(icon_data_)) ;
+
1213
+
1214 if(icon_path.empty()) {
+
1215 icon_data_.cbSize = 0 ;
+
1216 return true ;
+
1217 }
+
1218
+
1219 std::wstring icon_path_wide ;
+
1220 if(!util::string2wstring(icon_path, icon_path_wide)) {
+
1221 return false ;
+
1222 }
+
1223
+
1224 if(!util::exists(icon_path_wide)) {
+
1225 return false ;
+
1226 }
+
1227
+
1228 icon_data_.cbSize = sizeof(icon_data_) ;
+
1229 icon_data_.hWnd = hwnd_ ;
+
1230 icon_data_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP ;
+
1231 icon_data_.uCallbackMessage = MESSAGE_ID ;
+
1232 icon_data_.hIcon = static_cast<HICON>(
+
1233 LoadImageW(
+
1234 NULL, icon_path_wide.c_str(),
+
1235 IMAGE_ICON, 0, 0, LR_LOADFROMFILE)) ;
+
1236 wcscpy_s(icon_data_.szTip, app_name_.c_str()) ;
+
1237 icon_data_.dwState = NIS_SHAREDICON ;
+
1238 icon_data_.dwStateMask = NIS_SHAREDICON ;
+
1239
+
1240 if(!Shell_NotifyIconW(NIM_ADD, &icon_data_)) {
+
1241 return false ;
+
1242 }
+ +
1244
+
1245 return true ;
+
1246 }
-
1246
-
1247 private:
-
1248 static LRESULT CALLBACK callback(
-
1249 HWND hwnd,
-
1250 UINT msg,
-
1251 WPARAM wparam,
-
1252 LPARAM lparam) {
-
1253 auto get_instance = [hwnd]() {
-
1254 auto upper_addr = GetWindowLongW(hwnd, 0) ;
-
1255 if(!upper_addr) {
-
1256 return reinterpret_cast<FluentTray*>(nullptr) ;
-
1257 }
-
1258
-
1259 auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ;
-
1260 if(!lower_addr) {
-
1261 return reinterpret_cast<FluentTray*>(nullptr) ;
-
1262 }
-
1263
-
1264 FluentTray* self ;
-
1265 util::concatenate_bits(upper_addr, lower_addr, self) ;
-
1266 return self ;
-
1267 } ;
-
1268
-
1269 if(msg == WM_DESTROY || msg == WM_QUIT || msg == WM_CLOSE) {
-
1270 if(auto self = get_instance()) {
-
1271 self->stop() ;
-
1272 return 0 ;
-
1273 }
-
1274 }
-
1275 else if(msg == WM_ACTIVATE && wparam == WA_INACTIVE) {
-
1276 if(auto self = get_instance()) {
-
1277 if(!self->hide_menu_window()) {
-
1278 self->fail() ;
-
1279 }
-
1280 return 0 ;
-
1281 }
-
1282 }
-
1283 else if(msg == WM_DRAWITEM) {
-
1284 if(auto self = get_instance()) {
-
1285 auto item = reinterpret_cast<LPDRAWITEMSTRUCT>(lparam) ;
-
1286 auto menu_idx = self->get_menu_index_from_window(item->hwndItem) ;
-
1287 if(menu_idx < 0) {
-
1288 return FALSE ;
-
1289 }
-
1290 auto& menu = self->menus_[menu_idx] ;
-
1291 if(!menu.draw_menu(item, self->font_)) {
-
1292 self->fail() ;
-
1293 return FALSE ;
-
1294 }
-
1295 return TRUE ;
-
1296 }
-
1297 }
-
1298 else if(msg == WM_CTLCOLORBTN) {
-
1299 if(auto self = get_instance()) {
-
1300 auto menu_idx = self->get_menu_index_from_window(reinterpret_cast<HWND>(lparam)) ;
-
1301 if(menu_idx < 0) {
-
1302 return DefWindowProc(hwnd, msg, wparam, lparam) ;
-
1303 }
-
1304 auto& menu = self->menus_[menu_idx] ;
-
1305 return reinterpret_cast<LRESULT>(menu.background_brush()) ;
-
1306 }
-
1307 }
-
1308 else if(msg == WM_COMMAND) {
-
1309 if(auto self = get_instance()) {
-
1310 auto menu_idx = self->get_menu_index_from_id(LOWORD(wparam)) ;
-
1311 if(menu_idx < 0) {
-
1312 return FALSE ;
-
1313 }
-
1314 auto& menu = self->menus_[menu_idx] ;
-
1315 if(!menu.process_click_event()) {
-
1316 self->stop() ;
-
1317 return FALSE ;
-
1318 }
-
1319 if(menu.toggleable()) {
-
1320 // Update the toggle menu for checkmark
-
1321 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
-
1322 return false ;
-
1323 }
-
1324 }
-
1325 return TRUE ;
-
1326 }
-
1327 }
-
1328 else if(msg == MESSAGE_ID) { //On NotifyIcon
-
1329 if(auto self = get_instance()) {
-
1330 if(lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
-
1331 self->show_menu_window() ;
-
1332 return 0 ;
-
1333 }
-
1334 }
-
1335 }
-
1336
-
1337 return DefWindowProc(hwnd, msg, wparam, lparam) ;
-
1338 }
-
1339
-
1340 int get_menu_index_from_window(HWND hwnd) {
-
1341 int i = 0 ;
-
1342 for(auto& m : menus_) {
-
1343 if(m.window_handle() == hwnd) {
-
1344 return i ;
-
1345 }
-
1346 i ++ ;
-
1347 }
-
1348 return -1 ;
-
1349 }
-
1350
-
1351 int get_menu_index_from_id(WORD id) {
-
1352 int i = 0 ;
-
1353 for(auto& m : menus_) {
-
1354 if(m.id() == static_cast<std::size_t>(id)) {
-
1355 return i ;
-
1356 }
-
1357 i ++ ;
-
1358 }
-
1359 return -1 ;
-
1360 }
-
1361
-
1362 void get_message(MSG& message) {
-
1363 if(PeekMessage(&message, hwnd_, 0, 0, PM_REMOVE)) {
-
1364 DispatchMessage(&message) ;
-
1365 }
-
1366 }
-
1367
-
1368 void fail() noexcept {
-
1369 status_ = TrayStatus::FAILED ;
-
1370 }
-
1371
-
1372 bool change_menu_back_color(FluentMenu& menu, COLORREF new_color) {
-
1373 if(!menu.set_color(
-
1374 text_color_, new_color, ash_color_)) {
-
1375 return false ;
-
1376 }
-
1377 // Redraw
-
1378 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
-
1379 return false ;
-
1380 }
-
1381 return true ;
-
1382 }
-
1383 } ;
+
1247
+
1248 private:
+
1249 static LRESULT CALLBACK callback(
+
1250 HWND hwnd,
+
1251 UINT msg,
+
1252 WPARAM wparam,
+
1253 LPARAM lparam) {
+
1254 auto get_instance = [hwnd]() {
+
1255 auto upper_addr = GetWindowLongW(hwnd, 0) ;
+
1256 if(!upper_addr) {
+
1257 return reinterpret_cast<FluentTray*>(nullptr) ;
+
1258 }
+
1259
+
1260 auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ;
+
1261 if(!lower_addr) {
+
1262 return reinterpret_cast<FluentTray*>(nullptr) ;
+
1263 }
+
1264
+
1265 FluentTray* self ;
+
1266 util::concatenate_bits(upper_addr, lower_addr, self) ;
+
1267 return self ;
+
1268 } ;
+
1269
+
1270 if(msg == WM_DESTROY || msg == WM_QUIT || msg == WM_CLOSE) {
+
1271 if(auto self = get_instance()) {
+
1272 self->stop() ;
+
1273 return 0 ;
+
1274 }
+
1275 }
+
1276 else if(msg == WM_ACTIVATE && wparam == WA_INACTIVE) {
+
1277 if(auto self = get_instance()) {
+
1278 if(!self->hide_menu_window()) {
+
1279 self->fail() ;
+
1280 }
+
1281 return 0 ;
+
1282 }
+
1283 }
+
1284 else if(msg == WM_DRAWITEM) {
+
1285 if(auto self = get_instance()) {
+
1286 auto item = reinterpret_cast<LPDRAWITEMSTRUCT>(lparam) ;
+
1287 auto menu_idx = self->get_menu_index_from_window(item->hwndItem) ;
+
1288 if(menu_idx < 0) {
+
1289 return FALSE ;
+
1290 }
+
1291 auto& menu = self->menus_[menu_idx] ;
+
1292 if(!menu.draw_menu(item, self->font_)) {
+
1293 self->fail() ;
+
1294 return FALSE ;
+
1295 }
+
1296 return TRUE ;
+
1297 }
+
1298 }
+
1299 else if(msg == WM_CTLCOLORBTN) {
+
1300 if(auto self = get_instance()) {
+
1301 auto menu_idx = self->get_menu_index_from_window(reinterpret_cast<HWND>(lparam)) ;
+
1302 if(menu_idx < 0) {
+
1303 return DefWindowProc(hwnd, msg, wparam, lparam) ;
+
1304 }
+
1305 auto& menu = self->menus_[menu_idx] ;
+
1306 return reinterpret_cast<LRESULT>(menu.background_brush()) ;
+
1307 }
+
1308 }
+
1309 else if(msg == WM_COMMAND) {
+
1310 if(auto self = get_instance()) {
+
1311 auto menu_idx = self->get_menu_index_from_id(LOWORD(wparam)) ;
+
1312 if(menu_idx < 0) {
+
1313 return FALSE ;
+
1314 }
+
1315 auto& menu = self->menus_[menu_idx] ;
+
1316 if(!menu.process_click_event()) {
+
1317 self->stop() ;
+
1318 return FALSE ;
+
1319 }
+
1320 if(menu.toggleable()) {
+
1321 // Update the toggle menu for checkmark
+
1322 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
+
1323 return false ;
+
1324 }
+
1325 }
+
1326 return TRUE ;
+
1327 }
+
1328 }
+
1329 else if(msg == MESSAGE_ID) { //On NotifyIcon
+
1330 if(auto self = get_instance()) {
+
1331 if(lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
+
1332 self->show_menu_window() ;
+
1333 return 0 ;
+
1334 }
+
1335 }
+
1336 }
+
1337
+
1338 return DefWindowProc(hwnd, msg, wparam, lparam) ;
+
1339 }
+
1340
+
1341 int get_menu_index_from_window(HWND hwnd) {
+
1342 int i = 0 ;
+
1343 for(auto& m : menus_) {
+
1344 if(m.window_handle() == hwnd) {
+
1345 return i ;
+
1346 }
+
1347 i ++ ;
+
1348 }
+
1349 return -1 ;
+
1350 }
+
1351
+
1352 int get_menu_index_from_id(WORD id) {
+
1353 int i = 0 ;
+
1354 for(auto& m : menus_) {
+
1355 if(m.id() == static_cast<std::size_t>(id)) {
+
1356 return i ;
+
1357 }
+
1358 i ++ ;
+
1359 }
+
1360 return -1 ;
+
1361 }
+
1362
+
1363 void get_message(MSG& message) {
+
1364 if(PeekMessage(&message, hwnd_, 0, 0, PM_REMOVE)) {
+
1365 DispatchMessage(&message) ;
+
1366 }
+
1367 }
+
1368
+
1369 void fail() noexcept {
+
1370 status_ = TrayStatus::FAILED ;
+
1371 }
+
1372
+
1373 bool change_menu_back_color(FluentMenu& menu, COLORREF new_color) {
+
1374 if(!menu.set_color(
+
1375 text_color_, new_color, ash_color_)) {
+
1376 return false ;
+
1377 }
+
1378 // Redraw
+
1379 if(!InvalidateRect(menu.window_handle(), NULL, TRUE)) {
+
1380 return false ;
+
1381 }
+
1382 return true ;
+
1383 }
+
1384 } ;
-
1384}
-
1385
-
1386#endif
+
1385}
+
1386
+
1387#endif
Class with information on each menu.
Definition fluent_tray.hpp:223
bool is_mouse_over() const
Checks whether the mouse cursor is over the menu or not.
Definition fluent_tray.hpp:368
bool draw_menu(LPDRAWITEMSTRUCT info, HFONT font)
Draws a menu using drawing information and the specified font.
Definition fluent_tray.hpp:507
@@ -1353,12 +1353,12 @@
FluentTray & operator=(FluentTray &&)=default
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=5, LONG menu_y_pad=5, BYTE opacity=255, bool round_corner=true)
Initialize tray and create icon on tray.
Definition fluent_tray.hpp:728
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:829
-
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:1067
+
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:1068
TrayStatus status() const noexcept
Get the current status of tray.
Definition fluent_tray.hpp:1049
-
bool change_icon(const std::string &icon_path)
Load the image file and change the icon.
Definition fluent_tray.hpp:1204
+
bool change_icon(const std::string &icon_path)
Load the image file and change the icon.
Definition fluent_tray.hpp:1205
FluentTray()
Create tray object.
Definition fluent_tray.hpp:677
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:902
-
bool set_color(const COLORREF &text_color=CLR_INVALID, const COLORREF &back_color=CLR_INVALID, unsigned char color_decay=10)
Set colors to draw menus.
Definition fluent_tray.hpp:1128
+
bool set_color(const COLORREF &text_color=CLR_INVALID, const COLORREF &back_color=CLR_INVALID, unsigned char color_decay=10)
Set colors to draw menus.
Definition fluent_tray.hpp:1129
void add_separator()
Add a separator line under the last menu item added.
Definition fluent_tray.hpp:852
bool hide_menu_window()
Hide the menu window above the tray icon.
Definition fluent_tray.hpp:1035
FluentTray(const FluentTray &)=delete
diff --git a/include/fluent_tray.hpp b/include/fluent_tray.hpp index 1c5abe6..138e36a 100644 --- a/include/fluent_tray.hpp +++ b/include/fluent_tray.hpp @@ -247,7 +247,7 @@ namespace fluent_tray * @brief Create menu object. * @param [in] toggleable Create a switchable menu * @param [in] callback Function called when a click on the menu or a check is enabled. - * @param [in] unchecked_callback Function called when a check is distabled. + * @param [in] unchecked_callback Function called when a check is disabled. * @details The callback function must be a function with a bool return value and no arguments. The tray will exit successfully if the callback function returns false. */ explicit FluentMenu( @@ -714,15 +714,15 @@ namespace fluent_tray } /** - * @brief Initialize tray and create icon on tray - * @param [in] app_name - * @param [in] icon_path - * @param [in] menu_x_margin - * @param [in] menu_y_margin - * @param [in] menu_x_pad - * @param [in] menu_y_pad - * @param [in] opacity - * @param [in] round_corner + * @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. */ bool create_tray( @@ -818,12 +818,12 @@ namespace fluent_tray /** * @brief Add a menu in order from the top. - * @param [in] label_text - * @param [in] icon_path - * @param [in] toggleable - * @param [in] checkmark - * @param [in] callback - * @param [in] unchecked_callback + * @param [in] label_text The UTF-8 encoded string of the button label. + * @param [in] icon_path An icon path to show next to the label. + * @param [in] toggleable Create a switchable menu + * @param [in] checkmark A checkmark string. + * @param [in] callback Function called when a click on the menu or a check is enabled. + * @param [in] unchecked_callback Function called when a check is disabled. * @return Returns true on success, false on failure. */ bool add_menu( @@ -1059,10 +1059,11 @@ namespace fluent_tray /** * @brief Set font information to draw menus. - * @param [in] font_size - * @param [in] font_weight - * @param [in] font_name + * @param [in] font_size The height of fonts. + * @param [in] font_weight The value from 0 to 1000 to determine font weight. + * @param [in] font_name The UTF-8 encoded font name for label rendering. * @return Returns true on success, false on failure. + * @details For font_weight, you can use the constant value specified for lfWeght in LOGFONT. The default value used is FW_MEDIUM(500). */ bool set_font( LONG font_size=0, @@ -1120,9 +1121,9 @@ namespace fluent_tray /** * @brief Set colors to draw menus. - * @param [in] text_color - * @param [in] back_color - * @param [in] color_decay + * @param [in] text_color The color for label text. + * @param [in] back_color The color for background. + * @param [in] color_decay Decay value from the background color to determine the background color of the currently selected menu and the color of the separator line. * @return Returns true on success, false on failure. */ bool set_color(