Vra

Het iemand die krag / bystand knoppie suksesvol vasgevang op 'n WM5 toestel so dat jou kode verhoed gebruikers "afskakeling" selfs die skerm?

Ek het 'n aansoek dat die skerm gebruik in 'n landskap-oriëntasie en ek wil graag die krag knoppie druk trap sodat (a) gebruikers kan die toestel met albei hande en nie per ongeluk power-down die skerm en hou (soos 'n bonus -. b) gebruik dit as 'n UI knoppie

Miskien iemand het 'n lae vlak hack? Ek gebruik WM5 as afgelewer op iPaq rx1950 (s).

Onthou, daar is nie so iets soos onmoontlik - veral met WM5. As ek dit beantwoord myself in die tussentyd, sal ek die vraag op te dateer.


Werk!

Ek ontdek drie truuks wat werk, in omgekeerde volgorde van bruikbaarheid:

  1. Patch keybddr.dll (op hierdie toestel), weer te spuit in die ROM via jou gunsteling middel. Op hierdie toestel met hierdie fabriek ROM -. Dit werk, maar ek wou nie permanent afskakel

  2. Sync aan die Power Management boodskap tou en draai die toestel "op" wanneer dit sê dit is om af te gaan.

  3. Verander die "Power State" in die register, sodat hulle is almal (die meeste van hulle) "op". Op hierdie manier kan ek RAPI gebruik om die krag knoppie te skakel en het die sagteware op die toestel "reset" die register op gebeurtenis x, y en z.

Was dit nuttig?

Oplossing

Die implementering van die krag knoppie is OEM afhanklik, so 'n oplossing op een toestel is nie geneig om te werk op 'n ander toestel. As gevolg van die wye variasie van implementering in Windows Mobile-toestelle wat jy sal vind dit is waar met baie lae vlak funksies.

Die alternatiewe behels 'n kombinasie van dinge

  • Begin jou aansoek in onbewaakte af
  • Monitor vir krag verandering gebeure
  • wanneer die veranderinge toestel om sonder toesig af versoek volle op modus

'n Volledige bespreking van krag bestuur is meer as wat ek hier kan bespreek. Jy kan meer daaroor hier lees: http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

Daar is ook 'n voorbeeld wat wys hoe 'n mens kan registreer vir krag gebeure hier: http://www.codeproject.com/KB/mobile/WiMoQueue.aspx

Ander wenke

Die volgende kode sal die krag knoppie nie afskakel, maar as die toestel is afgeskakel, dit sal die toestel weer aan te kom draai binne 10 sekondes. Dit sal ook 'n elektrisiteit sparing funksies uit te skakel.

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

namespace Core.Mobile
{
    /// <summary>
    /// Allows manipulation the power management i.e. system standby
    /// </summary>
    public static class PowerManipulation
    {
        #region Private variables
        private static System.Threading.Timer _timer = null;
        private const int INTERVAL = 10000; //10 seconds
        #endregion
        #region Public methods
        /// <summary>
        /// Prevents the application from suspending/sleeping
        /// </summary>
        public static void DisableSleep()
        {
            if (_timer == null)
            {
                _timer = new System.Threading.Timer(new System.Threading.TimerCallback(Timer_Tick), null, 0, INTERVAL);
            }
            try
            {
                PowerPolicyNotify(PPN_UNATTENDEDMODE, 1);  //Ensure the application still runs in suspend mode
            }
            catch { }
        }
        /// <summary>
        /// Allows suspend/sleep operations
        /// </summary>
        public static void EnableSleep()
        {
            if (_timer != null)
            {
                _timer.Dispose();
                _timer = null;
            }
            try
            {
                PowerPolicyNotify(PPN_UNATTENDEDMODE, 0);
            }
            catch { }
        }
        #endregion
        #region Private methods
        /// <summary>
        /// Internal timer for preventing standby
        /// </summary>
        private static void Timer_Tick(object state)
        {
            try
            {
                SystemIdleTimerReset();
                SetSystemPowerState(null, POWER_STATE_ON, POWER_FORCE);
            }
            catch { }
        }
        #endregion
        #region PInvoke
        private const int PPN_UNATTENDEDMODE = 0x00000003;
        private const int POWER_STATE_ON = 0x00010000;
        private const int POWER_STATE_OFF = 0x00020000;
        private const int POWER_STATE_SUSPEND = 0x00200000;
        private const int POWER_FORCE = 4096;
        private const int POWER_STATE_RESET = 0x00800000;
        /// <summary>
        /// This function resets a system timer that controls whether or not the
        /// device will automatically go into a suspended state.
        /// </summary>
        [DllImport("CoreDll.dll")]
        private static extern void SystemIdleTimerReset();
        /// <summary>
        /// This function resets a system timer that controls whether or not the
        /// device will automatically go into a suspended state.
        /// </summary>
        [DllImport("CoreDll.dll")]
        private static extern void SHIdleTimerReset();
        /// <summary>
        /// This function allows the current power state to be manipulated, i.e. turn the device on
        /// </summary>
        [DllImport("coredll.dll", SetLastError = true)]
        static extern int SetSystemPowerState(string psState, int StateFlags, int Options);
        /// <summary>
        /// This function sets any power notification options
        /// </summary>
        [DllImport("CoreDll.dll")]
        static extern bool PowerPolicyNotify(int dwMessage, int onOrOff);
        #endregion
    }
}
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top