예제 #1
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            //WM_NOTIFY
            case 78:
                NMSHN nm = (NMSHN)Marshal.PtrToStructure(m.LParam, typeof(NMSHN));
                NotificationWithSoftKeys n = m_notifications[nm.idFrom];

                switch (nm.code)
                {
                case SHNN.DISMISS:
                    n.OnBalloonChanged(new BalloonChangedEventArgs(false));
                    break;

                case SHNN.SHOW:
                    n.OnBalloonChanged(new BalloonChangedEventArgs(true));
                    break;

                case SHNN.LINKSEL:
                    string link = Marshal.PtrToStringUni((IntPtr)nm.union1);
                    n.OnResponseSubmitted(new ResponseSubmittedEventArgs(link));
                    break;

                case SHNN.NAVNEXT:
                    n.OnSpinnerClick(new SpinnerClickEventArgs(true));
                    break;

                case SHNN.NAVPREV:
                    n.OnSpinnerClick(new SpinnerClickEventArgs(false));
                    break;
                }
                break;

            //WM_COMMAND
            case 0x0111:
            {
                uint value = ((uint)m.WParam & 0xFFFF);
                int  id    = (int)(value >> 8);
                byte index = (byte)(value & 0xFF);

                NotificationWithSoftKeys z = m_notifications[id];
                if (index == 0)
                {
                    z.OnLeftSoftKeyClick(EventArgs.Empty);
                }
                else
                {
                    z.OnRightSoftKeyClick(EventArgs.Empty);
                }
            }
            break;
            }

            //do base wndproc
            base.WndProc(ref m);
        }
예제 #2
0
파일: Program.cs 프로젝트: xorkrus/vk_wm
        static void Main(string[] args)
        {
            InitNotification();

            //Определение нотификаций и событий
            _notification = new NotificationWithSoftKeys();
            _notification.LeftSoftKey = new NotificationSoftKey(SoftKeyType.Hide, Properties.Resources.Program_LeftSoftKey);
            _notification.RightSoftKey = new NotificationSoftKey(SoftKeyType.Dismiss, Properties.Resources.Program_RightSoftKey);
            _notification.RightSoftKeyClick += OnNotificationRightSoftKeyClick;

            //Запуск сервиса и регистрация сообщения для него
            ServiceApplication.Name = Interprocess.ServiceName;
            ServiceApplication.RegisterMessage(Interprocess.WM_QUIT_SERVICE);
            ServiceApplication.RegisterMessage(Interprocess.WM_TIMER_TICK);
            ServiceApplication.OnRegisteredMessage += ServiceApplication_OnRegisteredMessage;

            Cache.InitPath(SystemConfiguration.AppInstallPath + "\\Cache");
            _baseLogic = new BaseLogic(new DataLogic(), new CommunicationLogic());
            //_baseLogic.IDataLogic.ClearNotificationTempDataInCache();
            _eventsGetResponsePrev = new EventsGetResponse();

            //автовход
            if (_baseLogic.IDataLogic.GetToken() != "")
            {
                try
                {
                    _baseLogic.AutoLogin();
                    _eventsGetResponsePrev = _baseLogic.EventsGet(true, false, true);

                    DebugHelper.WriteLogEntry("Notificator AutoLogin success.");

                    /*_eventsGetResponsePrev.CommentsCount = 0;
                    _eventsGetResponsePrev.FriendsCount = 0;
                    _eventsGetResponsePrev.MessagesCount = 0;*/

                }
                catch (VKException ex)
                {
                    CatchErrors(ex);
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteLogEntry(ex, "Unexpected error.");
                }
            }
            else
            {
                DebugHelper.WriteLogEntry("Notificator service can't be started, there are no token in registry.");
                Application.Exit();
            }

            //Устанавливаем время последней проверки
            _lastCheckedTime = DateTime.Now;

            //Считываем из реестра значение периода проверки
            _checkInterval = GetCheckInterval();

            //Задаем время, когда необходимо будет разбудить устройство
            try
            {
                WakeupScheduler.ScheduleWakeUp(_lastCheckedTime.AddMilliseconds(_checkInterval));
            }
            catch (ExternalException exception)
            {
                DebugHelper.WriteLogEntry(exception, exception.Message);
                throw;
            }
            catch (Exception exception)
            {
                DebugHelper.WriteLogEntry(exception, "Error in scheduling wakeup program launch");
                throw;
            }

            ServiceApplication.Run();
        }