Udostępnij za pośrednictwem


Create Secondary Tiles from your Desktop Application

Starting from the Insider Preview Build 16199 you can create SecondaryTiles directly from your desktop application by leveraging the Desktop Bridge.

A secondary tile provides a consistent, efficient way for users to directly access specific areas within a packaged app from the Start screen. Although a user chooses whether or not to "pin" a secondary tile to the Start screen, the pinnable areas in an app are determined by the developer.
Adding a Secondary tile from your WPF or Winforms is very similar to a pure UWP application, however there are few things to remember;
If you have a Win32 desktop application or a desktop application you need to specify your main window handle (HWND) in the API. The SecondaryTile displays a modal dialog to the user to get a confirmation from the user. If a desktop application does not configure the SecondaryTile object to specify the owner window for modal dialogs, this object will return inaccurate data or errors.

SecondaryTile

To configure a SecondaryTile object in a desktop application that uses the Desktop Bridge, follow these steps;

1. Do one of the following to enable your app to access the IInitializeWithWindow interface:
o If your application is written in a managed language such as C# or Visual Basic, declare the IInitializeWithWindow interface in your app's code with the ComImport attribute as shown in the following C# example. This example assumes that your code file has a using statement for the System.Runtime.InteropServices namespace.

 
[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
  void Initialize(IntPtr hwnd);
}

o If your application is written in C++, add a reference to the shobjidl.h header file in your code. This header file contains the declaration of the IInitializeWithWindow interface.

2. Create the secondary tile (it is the same code you will write in UWP);

 
Uri square150x150Logo = new Uri("ms-appx:///Assets/square150x150Tile-sdk.png");
SecondaryTile tile = new SecondaryTile("SecondaryTileId" + PhotoListBox.SelectedIndex,
                                                            displayName,
                                                            tileActivationArguments,
                                                            square150x150Logo,
                                                            TileSize.Default);

3. Cast the object to an IInitializeWithWindow object. Then, call the IInitializeWithWindow.Initialize method, and pass the handle of the window that you want to be the owner for the modal dialog. The following C# example shows how to pass the handle of your app's main window to the method.

 
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)tile;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
tile.RequestCreateAsync();

The full sample is available on GitHub, here.
To learn more about Secondary tiles and the Desktop Bridge, check out the resources below;

Resources

 

Any questions? Leave them in the comments!

Enjoy!
Vladimir Postel, Program Manager – Windows Developer Platform