使用CeSetUserNotification启动程序(译文)
By S.F.
本文链接 https://www.kyfws.com/news/using-cesetusernotification-to-start-a-program/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 2 分钟阅读 - 653 个词 阅读量 0使用CeSetUserNotification启动程序(译文)
原文地址:https://www.codeproject.com/Articles/55430/Using-CeSetUserNotification-to-Start-a-Program
原文作者:Joel Ivory Johnson
译文由本站翻译
前言
如何使用CeSetUserNotification启动程序
几天前,我收到一个开发人员的消息,该开发人员试图使用[CeRunAppAtTime](http://msdn.microsoft.com/zh-cn/library/ms913957.aspx)
安排应用程序启动.正如我在上一篇文章中提到的那样,应该使用此功能代替使用CeSetUserNotification,因为在较新的设备上CeRunAppAtTime不那么可靠(更不用说在MSDN文档中已将其标记为已弃用).
开发人员要求我提供一个如何从.NET调用该方法的示例,因此我为他提供了一个示例.我将共享下面的示例,并计划以后使用相同的代码在自动启动Windows Mobile程序上的CodeProject.com上更新我的文章.
public static extern IntPtr CeSetUserNotification(IntPtr hNotification, string application,
SystemTime startTime,
UserNotification notification);
[DllImport("CoreDLL.dll")]
public static extern int FileTimeToSystemTime(ref long lpFileTime, SystemTime lpSystemTime);
[DllImport("CoreDLL.dll")]
public static extern int FileTimeToLocalFileTime(ref long lpFileTime, ref long lpLocalFileTime);
[StructLayout(LayoutKind.Sequential)]
public class UserNotification
{
public int ActionFlags;
[MarshalAs(UnmanagedType.LPWStr)]
public string DialogTitle;
[MarshalAs(UnmanagedType.LPWStr)]
public string DialogText;
[MarshalAs(UnmanagedType.LPWStr)]
public string SoundPath;
public int MaxSoundPath;
public IntPtr Reserved;
public UserNotification()
{
DialogTitle = String.Empty;
DialogText = String.Empty;
SoundPath = String.Empty;
MaxSoundPath = 0;
Reserved = IntPtr.Zero;
ActionFlags = 0;
}
}
public static void RunAppAtTime(string applicationEvent, DateTime startTime)
{
long fileTimeUTC = startTime.ToFileTime();
long fileTimeLocal = 0;
UserNotification notification;
notification = new UserNotification();
notification.ActionFlags = 0;
notification.Reserved = IntPtr.Zero;
SystemTime systemStartTime = new SystemTime();
FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal);
FileTimeToSystemTime(ref fileTimeLocal, systemStartTime);
CeSetUserNotification(IntPtr.Zero ,applicationEvent, systemStartTime,
notification);
}
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# All-Topics 新闻 翻译