示例#1
0
        private void SetupNotifications()
        {
            DateTime         time         = new DateTime();
            DateTime         timeAlarm    = this.endTime.AddMinutes(-this.alarmPeriod);
            UserNotification notification = new UserNotification();

            if (this.isPreAlarmEnabled && timeAlarm.CompareTo(DateTime.Now) > 0)
            {
                time = timeAlarm;
                notification.Text = string.Format(global::AdaTimerPpc.Properties.Resources.TimeAlarm, this.alarmPeriod);
            }
            else if (this.endTime.CompareTo(DateTime.Now) > 0)
            {
                time = this.endTime;
                notification.Text = global::AdaTimerPpc.Properties.Resources.TimeUp;
            }

            if (notification.Text.Length > 0)
            {
                notification.Action = NotificationAction.Dialog;
                notification.Title  = this.title;

                UserNotificationTrigger trigger = new UserNotificationTrigger();
                trigger.Application = this.application;
                trigger.Arguments   = "-TIMER";
                trigger.Type        = NotificationType.Time;
                trigger.StartTime   = time;

                this.timerNotificationHandle = Notify.SetUserNotification(trigger, notification);
                Notify.RunAppAtTime(application, time);
            }
        }
示例#2
0
        ///// <summary>
        ///// Unregister an application given the path to the executable or the token that was provided
        ///// </summary>
        ///// <param name="applicationOrToken">The path to the application executable or the token, whichever was provided.</param>
        //public static void UnscheduleApplicationLaunch(string applicationOrToken)
        //{
        //    IntPtr handle = FindApplicationNotification(applicationOrToken);
        //    while (handle != IntPtr.Zero)
        //    {
        //        CeClearUserNotification(handle);
        //        handle = FindApplicationNotification(applicationOrToken);
        //    }
        //    //bool bret = UnscheduleCeRunAppAtTime(applicationOrToken, IntPtr.Zero);
        //    //int ret = ConnMgrUnregisterScheduledConnection(GetTokenFromApplication(applicationOrToken));
        //}
        private static void CeSetUserNotificationEx(string application, string arguments, DateTime start)
        {
            //UnscheduleApplicationLaunch(application);

            IntPtr appBuff = Marshal.StringToBSTR(application);
            IntPtr argsBuff = Marshal.StringToBSTR(arguments);

            var trigger = new UserNotificationTrigger
            {
                dwSize = Marshal.SizeOf(typeof(UserNotificationTrigger)),
                dwType = NotificationType.CNT_TIME,
                lpszApplication = appBuff,
                lpszArguments = argsBuff,
                stStartTime = SystemTime.FromDateTime2(start)
            };

            IntPtr handle = CeSetUserNotificationExNoType(IntPtr.Zero, ref trigger, IntPtr.Zero);
            Marshal.FreeBSTR(appBuff);
            Marshal.FreeBSTR(argsBuff);

            //TODO: fix this please

            if (handle == IntPtr.Zero)
                throw new ExternalException(string.Format("Unable to schedule application launch {0}: {1} {2}", start, application, arguments));
        }
示例#3
0
        ///// <summary>
        ///// Unregister an application given the path to the executable or the token that was provided
        ///// </summary>
        ///// <param name="applicationOrToken">The path to the application executable or the token, whichever was provided.</param>
        //public static void UnscheduleApplicationLaunch(string applicationOrToken)
        //{
        //    IntPtr handle = FindApplicationNotification(applicationOrToken);
        //    while (handle != IntPtr.Zero)
        //    {
        //        CeClearUserNotification(handle);
        //        handle = FindApplicationNotification(applicationOrToken);
        //    }

        //    //bool bret = UnscheduleCeRunAppAtTime(applicationOrToken, IntPtr.Zero);

        //    //int ret = ConnMgrUnregisterScheduledConnection(GetTokenFromApplication(applicationOrToken));
        //}

        private static void CeSetUserNotificationEx(string application, string arguments, DateTime start)
        {
            //UnscheduleApplicationLaunch(application);

            IntPtr appBuff  = Marshal.StringToBSTR(application);
            IntPtr argsBuff = Marshal.StringToBSTR(arguments);

            var trigger = new UserNotificationTrigger
            {
                dwSize          = Marshal.SizeOf(typeof(UserNotificationTrigger)),
                dwType          = NotificationType.CNT_TIME,
                lpszApplication = appBuff,
                lpszArguments   = argsBuff,
                stStartTime     = SystemTime.FromDateTime2(start)
            };

            IntPtr handle = CeSetUserNotificationExNoType(IntPtr.Zero, ref trigger, IntPtr.Zero);

            Marshal.FreeBSTR(appBuff);
            Marshal.FreeBSTR(argsBuff);

            //TODO: fix this please

            if (handle == IntPtr.Zero)
            {
                throw new ExternalException(string.Format("Unable to schedule application launch {0}: {1} {2}", start, application, arguments));
            }
        }
示例#4
0
        private void menuItem2_Click(object sender, EventArgs e)
        {
            OpenNETCF.WindowsCE.Notification.UserNotificationTrigger myTrig = new UserNotificationTrigger();

            if (!System.IO.File.Exists(txtApp.Text))
            {
                txtApp.BackColor = Color.Red;
                return;
            }
            myTrig.Application = txtApp.Text;

            myTrig.Arguments = txtArg.Text;

            try
            {
                myTrig.StartTime = DateTime.Parse(txtStart.Text);
            }
            catch (Exception)
            {
                txtStart.BackColor = Color.Red;
                return;
            }
            try
            {
                myTrig.EndTime = DateTime.Parse(txtEnd.Text);
            }
            catch (Exception)
            {
                txtEnd.BackColor = Color.Red;
                return;
            }

            myTrig.Event = NotificationEvent.None;

            myTrig.Type = NotificationType.Time;

            UserNotification myUN = new UserNotification();


            int iRes = OpenNETCF.WindowsCE.Notification.Notify.SetUserNotification(myTrig, null);

            if (iRes != 0)
            {
                MessageBox.Show("Added new UserNotification");
            }
            else
            {
                MessageBox.Show("Adding new UserNotification failed");
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        private void menuItem2_Click(object sender, EventArgs e)
        {
            OpenNETCF.WindowsCE.Notification.UserNotificationTrigger myTrig = new UserNotificationTrigger();

            if (!System.IO.File.Exists(txtApp.Text))
            {
                txtApp.BackColor = Color.Red;
                return;
            }
            myTrig.Application=txtApp.Text;
            
            myTrig.Arguments=txtArg.Text;

            try
            {
                myTrig.StartTime=DateTime.Parse(txtStart.Text);
            }
            catch (Exception)
            {
                txtStart.BackColor = Color.Red;                
                return;
            }
            try
            {
                myTrig.EndTime = DateTime.Parse(txtEnd.Text);
            }
            catch (Exception)
            {
                txtEnd.BackColor = Color.Red;
                return;
            }

            myTrig.Event= NotificationEvent.None;

            myTrig.Type=NotificationType.Time;

            UserNotification myUN = new UserNotification();
            

            int iRes = OpenNETCF.WindowsCE.Notification.Notify.SetUserNotification(myTrig, null);
            if (iRes != 0)
                MessageBox.Show("Added new UserNotification");
            else
                MessageBox.Show("Adding new UserNotification failed");

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#6
0
        private void menuItemAlarm_Click(object sender, EventArgs e)
        {
            AlarmForm f = new AlarmForm();

            if (this.alarmDateTime.CompareTo(DateTime.Now) <= 0)
            {
                this.isAlarmSet    = false;
                this.alarmDateTime = DateTime.Now.AddMinutes(10);
            }

            f.IsAlarmSet    = this.isAlarmSet;
            f.AlarmDateTime = this.alarmDateTime;

            if (f.ShowDialog() == DialogResult.OK)
            {
                this.isAlarmSet    = f.IsAlarmSet;
                this.alarmDateTime = f.AlarmDateTime;

                Notify.ClearUserNotification(this.alarmNotificationHandle);

                if (this.isAlarmSet)
                {
                    UserNotification notification = new UserNotification();

                    notification.Text   = string.Format(global::AdaTimerPpc.Properties.Resources.AlarmMessage, this.title);
                    notification.Action = NotificationAction.Dialog;
                    notification.Title  = this.title;

                    UserNotificationTrigger trigger = new UserNotificationTrigger();
                    trigger.Application = this.application;
                    trigger.Arguments   = "-ALARM";
                    trigger.Type        = NotificationType.Time;
                    trigger.StartTime   = this.alarmDateTime;

                    this.alarmNotificationHandle = Notify.SetUserNotification(trigger, notification);
                }

                this.SaveSetting();
            }
        }
示例#7
0
 internal static extern int CeSetUserNotificationEx(int hNotification, UserNotificationTrigger lpTrigger, UserNotification lpUserNotification);
示例#8
0
 static extern IntPtr CeSetUserNotificationExNoType(IntPtr hNotification, ref UserNotificationTrigger pcnt, IntPtr pceun);
示例#9
0
 extern static IntPtr CeSetUserNotificationExNoType(IntPtr hNotification, ref UserNotificationTrigger pcnt, IntPtr pceun);