Skip to content

Commit

Permalink
a function of setting icon overlay on taskbar (ITaskbarList3::SetOver…
Browse files Browse the repository at this point in the history
…layIcon method)
  • Loading branch information
nikitatg committed Jan 31, 2022
1 parent 32bcc67 commit 7e8ed85
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ WindowsTaskbar.flashTaskbarAppIcon(
WindowsTaskbar.stopFlashingTaskbarAppIcon();
```

**Set overlay icon (a badge)**

```dart
WindowsTaskbar.setOverlayIcon(icon: 'res/circle.ico', altTooltip: 'Alternative tooltip for badge');
```

**Remove overlay icon (a badge)**

```dart
WindowsTaskbar.resetOverlayIcon();
```

## License

Copyright © 2021 & 2022, Hitesh Kumar Saini <<[email protected]>>
Expand Down
20 changes: 20 additions & 0 deletions lib/windows_taskbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const String _kSetThumbnailTooltip = 'SetThumbnailTooltip';
/// Flashes app icon on the taskbar.
const String _kSetFlashTaskbar = 'SetFlashTaskbar';

/// Sets overlay icon (a badge)
const String _kSetOverlayIcon = 'SetOverlayIcon';

/// Removes overlay icon (a badge)
const String _kResetOverlayIcon = 'ResetOverlayIcon';

/// Method channel for making native WIN32 calls.
final MethodChannel _kChannel =
const MethodChannel('com.alexmercerind/windows_taskbar')
Expand Down Expand Up @@ -288,6 +294,20 @@ class WindowsTaskbar {
},
);
}

static Future<void> setOverlayIcon({String? icon, String altTooltip = ''}) {
return _kChannel.invokeMethod(
_kSetOverlayIcon,
{
'icon': icon,
'altTooltip': altTooltip,
},
);
}

static Future<void> resetOverlayIcon() {
return _kChannel.invokeMethod(_kResetOverlayIcon, {});
}
}

/// Maximum button count in the thumbnail toolbar.
Expand Down
36 changes: 36 additions & 0 deletions windows/windows_taskbar_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class WindowsTaskbarPlugin : public flutter::Plugin {
static constexpr auto kSetThumbnailToolbar = "SetThumbnailToolbar";
static constexpr auto kSetThumbnailTooltip = "SetThumbnailTooltip";
static constexpr auto kSetFlashTaskbar = "SetFlashTaskbar";
static constexpr auto kSetOverlayIcon = "SetOverlayIcon";
static constexpr auto kResetOverlayIcon = "ResetOverlayIcon";

void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
Expand Down Expand Up @@ -238,6 +240,40 @@ void WindowsTaskbarPlugin::HandleMethodCall(
::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT);
flash_info.uCount = flash_count;
::FlashWindowEx(&flash_info);
} else if (method_call.method_name().compare(kSetOverlayIcon) == 0) {
auto icon =
std::get<std::string>(arguments[flutter::EncodableValue("icon")]);
auto altTooltip =
std::get<std::string>(arguments[flutter::EncodableValue("altTooltip")]);
auto image = (HICON)LoadImage(
0, Utf16FromUtf8(icon).c_str(), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON),
LR_LOADFROMFILE | LR_LOADTRANSPARENT);
ITaskbarList3* taskbar_list;
HRESULT hr;
hr = ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&taskbar_list));
if (SUCCEEDED(hr)) {
taskbar_list->SetOverlayIcon(
::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT),
image,
Utf16FromUtf8(altTooltip).c_str());
}
taskbar_list->Release();
DestroyIcon(image);
result->Success(flutter::EncodableValue(nullptr));
} else if (method_call.method_name().compare(kResetOverlayIcon) == 0) {
ITaskbarList3* taskbar_list;
HRESULT hr;
hr = ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&taskbar_list));
if (SUCCEEDED(hr)) {
taskbar_list->SetOverlayIcon(
::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT),
nullptr,
Utf16FromUtf8("").c_str());
}
taskbar_list->Release();
result->Success(flutter::EncodableValue(nullptr));
} else {
result->NotImplemented();
Expand Down

0 comments on commit 7e8ed85

Please sign in to comment.