none
手機待機後,程式就不執行了? RRS feed

  • 問題

  • 請教各位大大

    我利用wmp.dll開發一個播放廣播的軟體...

    但發現手機放著不動的話,手機會自動待機休眠(也就是銀目會自動關掉)
    而此時我的音樂就會斷掉了...試問如何排除這個問題呢???

    如何讓待機時我的程式仍然可以繼續播放???

    謝謝
    2009年4月7日 上午 10:03

解答

  • 關閉電源
    使用方法 Power.PowerOffTime=0;

     public class Power
            {
                private const string POWER_TIMEOUT = @"System\CurrentControlSet\Control\Power\Timeouts";
                private const string POWER_STATE_SUSPEND = @"System\CurrentControlSet\Control\Power\State\Suspend";
    
                [DllImport("CoreDll")]
                public static extern void SystemIdleTimerReset();
    
                        public static int PowerOffTime
                {
                    set
                    {
                          RegistryKey rktimeout = Registry.LocalMachine.OpenSubKey(POWER_TIMEOUT, true);
                        if (rktimeout != null)
                        {
                         
                            rktimeout.SetValue("ACSuspendTimeout", value, RegistryValueKind.DWord);
                                                    rktimeout.SetValue("BattSuspendTimeout", value, RegistryValueKind.DWord);
                            rktimeout.Close();
                        }
                                           RegistryKey rksuspend = Registry.LocalMachine.OpenSubKey(POWER_STATE_SUSPEND, true);
                        if (rksuspend != null)
                        {
                            rksuspend.SetValue("Default", value == 0 ? 0 : 3, RegistryValueKind.DWord);
                            rksuspend.SetValue("Flags", value == 0 ? 0 : 209152, RegistryValueKind.DWord);
                            rksuspend.Close();
                        }
                    }
                }
            }
    開啟背光
    使用方法 Screen.PowerOn

     public class Screen
            {
             
                private const uint QUERYESCSUPPORT = 8;
                private const uint GETVFRAMEPHYSICAL = 6144;
                private const uint GETVFRAMELEN = 6145;
                private const uint DBGDRIVERSTAT = 6146;
                private const uint SETPOWERMANAGEMENT = 6147;
                private const uint GETPOWERMANAGEMENT = 6148;
                private const int SHFS_SHOWSTARTICON = 0x0010;
                private const int SHFS_HIDESTARTICON = 0x0020;
                public static void PowerOff()
                {
                    IntPtr hdc = GetDC(IntPtr.Zero);
                    uint size = 12;
                    byte[] vpm = new byte[size];
                    BitConverter.GetBytes(size).CopyTo(vpm, 0);
                    BitConverter.GetBytes(0x0001).CopyTo(vpm, 4);
                    BitConverter.GetBytes((uint)ScreenPowerState.ScreenPowerOff).CopyTo(vpm, 8);
                    ExtEscapeSet(hdc, SETPOWERMANAGEMENT, size, vpm, 0, IntPtr.Zero);
                }
    
                 public static void PowerOn()
                {
                    IntPtr hdc = GetDC(IntPtr.Zero);
    
                    uint size = 12;
                    byte[] vpm = new byte[size];
    
                    BitConverter.GetBytes(size).CopyTo(vpm, 0);
                    BitConverter.GetBytes(0x0001).CopyTo(vpm, 4);
                    BitConverter.GetBytes((uint)ScreenPowerState.ScreenPowerOn).CopyTo(vpm, 8);
    
                    ExtEscapeSet(hdc, SETPOWERMANAGEMENT, size, vpm, 0, IntPtr.Zero);
                }
    
                [DllImport("coredll", EntryPoint = "ExtEscape")]
                private static extern int ExtEscapeSet(
                    IntPtr hdc,
                    uint nEscape,
                    uint cbInput,
                    byte[] lpszInData,
                    int cbOutput,
                    IntPtr lpszOutData
                    );
    
                [DllImport("coredll")]
                private static extern IntPtr GetDC(IntPtr hwnd);
            }
    
             public enum ScreenPowerState : uint
            {
                 ScreenPowerOn = 1,
                ScreenPowerStandBy,
                 ScreenPowerSuspend,
                 ScreenPowerOff
            }
    關閉待機是一定要執行如果你的程式跟螢幕畫面沒關係的話就不用關背光照明可是你做多媒體播放一定要背光開起來
    • 已提議為解答 sandy2009 2009年4月8日 上午 04:21
    • 已標示為解答 bauannModerator 2009年4月16日 上午 02:43
    2009年4月8日 上午 04:00

所有回覆

  • Hi doremicat,

    若您的機器進入待機模式的話,程式就會停下來,
    從application的層級可以做到的是避免機器進入待機模式,
    請參考此討論串:
    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/e200fbc6-0601-4c9d-ae06-3a380ae9b42a/


    每天都有進步的人值得敬重
    2009年4月7日 下午 01:30
  • 關閉電源
    使用方法 Power.PowerOffTime=0;

     public class Power
            {
                private const string POWER_TIMEOUT = @"System\CurrentControlSet\Control\Power\Timeouts";
                private const string POWER_STATE_SUSPEND = @"System\CurrentControlSet\Control\Power\State\Suspend";
    
                [DllImport("CoreDll")]
                public static extern void SystemIdleTimerReset();
    
                        public static int PowerOffTime
                {
                    set
                    {
                          RegistryKey rktimeout = Registry.LocalMachine.OpenSubKey(POWER_TIMEOUT, true);
                        if (rktimeout != null)
                        {
                         
                            rktimeout.SetValue("ACSuspendTimeout", value, RegistryValueKind.DWord);
                                                    rktimeout.SetValue("BattSuspendTimeout", value, RegistryValueKind.DWord);
                            rktimeout.Close();
                        }
                                           RegistryKey rksuspend = Registry.LocalMachine.OpenSubKey(POWER_STATE_SUSPEND, true);
                        if (rksuspend != null)
                        {
                            rksuspend.SetValue("Default", value == 0 ? 0 : 3, RegistryValueKind.DWord);
                            rksuspend.SetValue("Flags", value == 0 ? 0 : 209152, RegistryValueKind.DWord);
                            rksuspend.Close();
                        }
                    }
                }
            }
    開啟背光
    使用方法 Screen.PowerOn

     public class Screen
            {
             
                private const uint QUERYESCSUPPORT = 8;
                private const uint GETVFRAMEPHYSICAL = 6144;
                private const uint GETVFRAMELEN = 6145;
                private const uint DBGDRIVERSTAT = 6146;
                private const uint SETPOWERMANAGEMENT = 6147;
                private const uint GETPOWERMANAGEMENT = 6148;
                private const int SHFS_SHOWSTARTICON = 0x0010;
                private const int SHFS_HIDESTARTICON = 0x0020;
                public static void PowerOff()
                {
                    IntPtr hdc = GetDC(IntPtr.Zero);
                    uint size = 12;
                    byte[] vpm = new byte[size];
                    BitConverter.GetBytes(size).CopyTo(vpm, 0);
                    BitConverter.GetBytes(0x0001).CopyTo(vpm, 4);
                    BitConverter.GetBytes((uint)ScreenPowerState.ScreenPowerOff).CopyTo(vpm, 8);
                    ExtEscapeSet(hdc, SETPOWERMANAGEMENT, size, vpm, 0, IntPtr.Zero);
                }
    
                 public static void PowerOn()
                {
                    IntPtr hdc = GetDC(IntPtr.Zero);
    
                    uint size = 12;
                    byte[] vpm = new byte[size];
    
                    BitConverter.GetBytes(size).CopyTo(vpm, 0);
                    BitConverter.GetBytes(0x0001).CopyTo(vpm, 4);
                    BitConverter.GetBytes((uint)ScreenPowerState.ScreenPowerOn).CopyTo(vpm, 8);
    
                    ExtEscapeSet(hdc, SETPOWERMANAGEMENT, size, vpm, 0, IntPtr.Zero);
                }
    
                [DllImport("coredll", EntryPoint = "ExtEscape")]
                private static extern int ExtEscapeSet(
                    IntPtr hdc,
                    uint nEscape,
                    uint cbInput,
                    byte[] lpszInData,
                    int cbOutput,
                    IntPtr lpszOutData
                    );
    
                [DllImport("coredll")]
                private static extern IntPtr GetDC(IntPtr hwnd);
            }
    
             public enum ScreenPowerState : uint
            {
                 ScreenPowerOn = 1,
                ScreenPowerStandBy,
                 ScreenPowerSuspend,
                 ScreenPowerOff
            }
    關閉待機是一定要執行如果你的程式跟螢幕畫面沒關係的話就不用關背光照明可是你做多媒體播放一定要背光開起來
    • 已提議為解答 sandy2009 2009年4月8日 上午 04:21
    • 已標示為解答 bauannModerator 2009年4月16日 上午 02:43
    2009年4月8日 上午 04:00
  • 一般而言, 比較不會直接去對 display or backlight driver 下 command, 因為這樣會跳過 Power Manager 而讓 PM internal 的 state 會跟 driver 不同步。 所以比較建意用 Power Management Function 像是 DevicePowerNotify, SetDevicePower or SetPowerRequirement - http://msdn.microsoft.com/en-us/library/aa908456.aspx

    另一種方式則是透過改變 system power state 到某個特定的 power state, 比如說是 On, BacklightOff, ScreenOff 等等,SetSystemPowerState - http://msdn.microsoft.com/en-us/library/aa929708.aspx

    我需要勳章
    • 已提議為解答 JocoboNY 2009年4月16日 上午 04:44
    2009年4月8日 上午 06:40