简体   繁体   中英

Desktop Win10 Toast Notification active callback not firing

The question is that: I have a WPF application and want to send a Win10 Style notification.
I searched all the website I know and find the MSDN way to do that: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop .
But unfortunately, I'm not using a Wix Installer, so I managed to create the shortcut in an other way: IShellLinkW .
So far, I succeed in sending a Toast. but I can't get a callback when operating on it.
My create short cut code:

using (PropVariant appId = new PropVariant(_aumid))
{
    ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue
    (
        new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5), appId)
    );
}

It works well,so the SetValue method should be OK
I think I can hock the callback method with its GUID in the same way:

var toastclass = typeof(T).GUID.ToString();
using (PropVariant toastid = new PropVariant(toastclass))
{
    toastid.SetEnum(VarEnum.VT_CLSID);
    ErrorHelper.VerifySucceeded
    (
        newShortcutProperties.SetValue
        (
            new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 26), toastid
        )
    );
}
ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());

I register it this way

// Register type
var regService = new RegistrationServices();

regService.RegisterTypeForComClients
(
    typeof(T),
    RegistrationClassContext.LocalServer,
    RegistrationConnectionType.MultipleUse
);

_registeredActivator = true;

but finally the callback method not firing

[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(INotificationActivationCallback))]
[Guid("9a88b91d-f9c4-4c63-91dd-175c2c2cb458"), ComVisible(true)]
public class AreaIconToast : NotificationActivator
{

最后我解决了这个问题,我发现这是因为我在创建快捷方式时以字符串格式传递了 CLSID,但正确的方法是将其作为 byte[] 传递,这就是回调方法不起作用的原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM