Skip to content

Commit bf89276

Browse files
authored
updates for Win32 APIs (#3785)
* updates for Win32 APIs * add email link
1 parent 9d32da3 commit bf89276

File tree

2 files changed

+58
-29
lines changed

2 files changed

+58
-29
lines changed
238 KB
Loading
Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
---
2-
description: You can programmatically pin your app to the taskbar, bnd you can check if it's currently pinned.
2+
description: You can programmatically pin your app to the taskbar, and you can check if it's currently pinned.
33
title: Pin your app to the taskbar
44
template: detail.hbs
55
ms.date: 09/24/2020
66
ms.topic: article
7-
keywords: windows 10, uwp, taskbar, taskbar manager, pin to taskbar, primary tile
7+
keywords: windows 10, uwp, win32, taskbar, taskbar manager, pin to taskbar, primary tile
88
ms.localizationpriority: medium
99
---
1010
# Pin your app to the taskbar
1111

12-
You can programmatically pin your own app to the taskbar, just like you can [pin your app to the Start menu](tiles-and-notifications/primary-tile-apis.md). And you can check whether your app is currently pinned, and whether the taskbar allows pinning.
12+
Now you can programmatically request users to pin your Win32 or UWP app to the taskbar, similar to how you can [pin your app to the Start menu](tiles-and-notifications/primary-tile-apis.md). And you can check whether your app is currently pinned, and whether the taskbar allows pinning.
1313

1414
![Screenshot of a Windows 11 task bar showing the app pinned there.](images/taskbar/taskbar.png)
1515

1616
> [!IMPORTANT]
1717
> **Requires Fall Creators Update**: You must target SDK 16299 and be running build 16299 or later to use the taskbar APIs.
1818
19-
> **Important APIs**: [TaskbarManager class](/uwp/api/windows.ui.shell.taskbarmanager)
19+
> **Important APIs**: [TaskbarManager class](/uwp/api/windows.ui.shell.taskbarmanager)
2020
21+
## When should you ask the user to pin your app to the taskbar?
2122

22-
## When should you ask the user to pin your app to the taskbar?
23+
The [TaskbarManager](/uwp/api/windows.ui.shell.taskbarmanager) class lets you ask the user to pin your app to the taskbar; the user must approve the request. You put a lot of effort into building a stellar app, and now you have the opportunity to ask the user to pin it to taskbar. But before we dive into the code, here are some things to keep in mind as you are designing your experience:
2324

24-
The [TaskbarManager class](/uwp/api/windows.ui.shell.taskbarmanager) lets you ask the user to pin your app to the taskbar; the user must approve the request. You put a lot of effort into building a stellar app, and now you have the opportunity to ask the user to pin it to taskbar. But before we dive into the code, here are some things to keep in mind as you are designing your experience:
25-
26-
* **Do** craft a non-disruptive and easily dismissible UX in your app with a clear "Pin to taskbar" call to action. Avoid using dialogs and flyouts for this purpose.
27-
* **Do** clearly explain the value of your app before asking the user to pin it.
28-
* **Don't** ask a user to pin your app if the tile is already pinned or the device doesn’t support it. (This article explains how to determine whether pinning is supported.)
25+
* **Do** craft a non-disruptive and easily dismissible UX in your app with a clear call to action. Avoid using dialogs and flyouts for this purpose. Accessible pinning icons or similar UX is recommended but not required.
26+
* **Do** ensure your app has value to the user before asking the user to pin it.
27+
* **Don't** ask a user to pin your app if the tile is already pinned or the device doesn't support it. (This article explains how to determine whether pinning is supported.)
2928
* **Don't** repeatedly ask the user to pin your app (they will probably get annoyed).
30-
* **Don't** call the pin API without explicit user interaction or when your app is minimized/not open.
29+
* **Don't** call the pin API without explicit user interaction or when your app is minimized/not open. Your app must be in the foreground for the process to work.
30+
* **Don't** use installers to call the API.
31+
32+
## Limited Access Feature (LAF) approval
33+
34+
Taskbar pinning is a Limited Access Feature (LAF). To gain access to this API you will need to receive a token to unlock the LAF gating. To request a token, email [[email protected]](mailto:[email protected]) with the information listed below. If the request is approved you will receive a token to unlock the LAF.
3135

36+
* The UX experience – please provide images in the LAF request email.
37+
* Microsoft Store name – please provide the name of your app as represented in the Microsoft Store. Our team will manually check if you have an entry. A discoverable Microsoft Store entry is required for use.
3238

3339
## 1. Check whether the required APIs exist
3440

35-
If your app supports older versions of Windows 10, you need to check whether the TaskbarManager class is available. You can use the [ApiInformation.IsTypePresent method](/uwp/api/windows.foundation.metadata.apiinformation#Windows_Foundation_Metadata_ApiInformation_IsTypePresent_System_String_) to perform this check. If the TaskbarManager class isn't available, avoid executing any calls to the APIs.
41+
### UWP
42+
43+
If your app supports older versions of Windows 10, you need to check whether the `TaskbarManager` class is available. You can use the [ApiInformation.IsTypePresent method](/uwp/api/windows.foundation.metadata.apiinformation#Windows_Foundation_Metadata_ApiInformation_IsTypePresent_System_String_) to perform this check. If the `TaskbarManager` class isn't available, avoid executing any calls to the APIs.
3644

3745
```csharp
3846
if (ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager"))
@@ -46,62 +54,83 @@ else
4654
}
4755
```
4856

57+
### Win32
58+
59+
If you want to use `TaskbarManager` from your WIn32 desktop app, then you'll need to check whether desktop app support is present. You can look for the `ITaskbarManagerDesktopAppSupportStatics` marker interface on the `TaskbarManager` activation factory to perform this check. If this interface is not available, then you won't be able to use `TaskbarManager` from your desktop app.
60+
61+
```cpp
62+
if (winrt::try_get_activation_factory<winrt::Windows::UI::Shell::TaskbarManager, winrt::Windows::UI::Shell::ITaskbarManagerDesktopAppSupportStatics>())
63+
{
64+
// TaskbarManager desktop app support is available.
65+
}
66+
else
67+
{
68+
// TaskbarManager desktop app support is not available.
69+
}
70+
```
4971

5072
## 2. Check whether taskbar is present and allows pinning
5173

52-
Windows apps can run on a wide variety of devices; not all of them support the taskbar. Right now, only Desktop devices support the taskbar.
74+
Windows apps can run on a wide variety of devices; not all of them support the taskbar. Right now, only Desktop devices support the taskbar. Additionally, apps may request pinning, but pinning may not be allowed at any given time. It is suggested that apps check whether pinning is allowed before UX is surfaced to prevent confusing users.
5375

54-
Even if the taskbar is available, a group policy on the user's machine might disable taskbar pinning. So, before you attempt to pin your app, you need to check whether pinning to the taskbar is supported. The [TaskbarManager.IsPinningAllowed property](/uwp/api/windows.ui.shell.taskbarmanager.IsPinningAllowed) returns true if the taskbar is present and allows pinning.
76+
Even if the taskbar is available, a group policy on the user's machine might disable taskbar pinning. So, before you attempt to pin your app, you need to check whether pinning to the taskbar is supported. The [TaskbarManager.IsPinningAllowed](/uwp/api/windows.ui.shell.taskbarmanager.IsPinningAllowed) property returns `true` if the taskbar is present and allows pinning.
5577

5678
```csharp
57-
// Check if taskbar allows pinning (Group Policy can disable it, or some device families don't have taskbar)
79+
// Check if taskbar allows pinning, apps may request pinning, but pinning may not be allowed at any given time. It is suggested that apps check whether pinning is allowed before a UX is surfaced in order to prevent confusing users.
80+
5881
bool isPinningAllowed = TaskbarManager.GetDefault().IsPinningAllowed;
5982
```
6083

61-
> [!NOTE]
62-
> If you don't want to pin your app to the taskbar and just want to find out whether the taskbar is available, use the [TaskbarManager.IsSupported property](/uwp/api/windows.ui.shell.taskbarmanager.IsSupported).
84+
> [!IMPORTANT]
85+
> There are also requirements that must be met at the time the call is actually made for the pin request to be allowed:
86+
>
87+
> * App is in foreground
88+
> * App has a Start menu entry
89+
>
90+
> These requirements won't result in an exception if not met, the pin request will just be denied. `IsPinningAllowed` can be called to determine if a pin request (prompt) will be allowed.
6391
92+
> [!NOTE]
93+
> If you don't want to pin your app to the taskbar and just want to find out whether the taskbar is available, use the [TaskbarManager.IsSupported](/uwp/api/windows.ui.shell.taskbarmanager.IsSupported) property.
6494
6595
## 3. Check whether your app is currently pinned to the taskbar
6696

67-
Obviously, there's no point in asking the user to let you pin the app to the taskbar if it's already pinned there. You can use the [TaskbarManager.IsCurrentAppPinnedAsync method](/uwp/api/windows.ui.shell.taskbarmanager.IsCurrentAppPinnedAsync) to check whether the app is already pinned before asking the user.
97+
Obviously, there's no point in asking the user to let you pin the app to the taskbar if it's already pinned there. You can use the [TaskbarManager.IsCurrentAppPinnedAsync](/uwp/api/windows.ui.shell.taskbarmanager.IsCurrentAppPinnedAsync) method to check whether the app is already pinned before asking the user.
6898

6999
```csharp
70100
// Check whether your app is currently pinned
71101
bool isPinned = await TaskbarManager.GetDefault().IsCurrentAppPinnedAsync();
72102

73103
if (isPinned)
74104
{
75-
// The app is already pinned--no point in asking to pin it again!
105+
// The app is already pinned--no point in asking to pin it again!
76106
}
77-
else
107+
else
78108
{
79-
//The app is not pinned.
109+
//The app is not pinned.
80110
}
81111
```
82112

113+
## 4. Pin your app
83114

84-
## 4. Pin your app
115+
If the taskbar is present and pinning is allowed and your app currently isn't pinned, you might want to show a subtle tip to let users know that they can pin your app. For example, you might show a pin icon somewhere in your UI that the user can click.
85116

86-
If the taskbar is present and pinning is allowed and your app currently isn't pinned, you might want to show a subtle tip to let users know that they can pin your app. For example, you might show a pin icon somewhere in your UI that the user can click.
87-
88-
If the user clicks your pin suggestion UI, you would then call the [TaskbarManager.RequestPinCurrentAppAsync method](/uwp/api/windows.ui.shell.taskbarmanager.RequestPinCurrentAppAsync). This method displays a dialog that asks the user to confirm that they want your app pinned to the taskbar.
117+
If the user clicks your pin suggestion UI, you would then call the [TaskbarManager.RequestPinCurrentAppAsync](/uwp/api/windows.ui.shell.taskbarmanager.RequestPinCurrentAppAsync) method. This method displays a dialog that asks the user to confirm that they want your app pinned to the taskbar.
89118

90119
> [!IMPORTANT]
91120
> This must be called from a foreground UI thread, otherwise an exception will be thrown.
92121
93122
```csharp
94-
// Request to be pinned to the taskbar
123+
// Request to be pinned to the taskbar.
95124
bool isPinned = await TaskbarManager.GetDefault().RequestPinCurrentAppAsync();
96125
```
97126

98127
![Pin dialog](images/taskbar/pin-dialog.png)
99128

100-
This method returns a boolean value that indicates whether your app is now pinned to the taskbar. If your app was already pinned, the method immediately returns true without showing the dialog to the user. If the user clicks "no" on the dialog, or pinning your app to the taskbar isn't allowed, the method returns false. Otherwise, the user clicked yes and the app was pinned, and the API will return true.
101-
129+
This method returns a boolean value that indicates whether your app is now pinned to the taskbar. If your app was already pinned, the method immediately returns `true` without showing the dialog to the user. If the user clicks "no" on the dialog, or pinning your app to the taskbar isn't allowed, the method returns `false`. Otherwise, the user clicked yes and the app was pinned, and the API will return `true`.
102130

103131
## Resources
104132

105-
* [Full code sample on GitHub](https://github.com/WindowsNotifications/quickstart-pin-to-taskbar)
133+
* [Full UWP code sample on GitHub](https://github.com/WindowsNotifications/quickstart-pin-to-taskbar)
134+
* [Full desktop code sample on GitHub](https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/TaskbarManager)
106135
* [TaskbarManager class](/uwp/api/windows.ui.shell.taskbarmanager)
107136
* [Pin an app to the Start menu](tiles-and-notifications/primary-tile-apis.md)

0 commit comments

Comments
 (0)