码迷,mamicode.com
首页 > 其他好文 > 详细

VB6中如何防止系统休眠?(博问出现问题,在些先编辑好以做备份)

时间:2017-04-22 14:46:42      阅读:966      评论:0      收藏:0      [点我收藏+]

标签:declare   dllimport   color   休眠   dll   play   dex   nstat   res   

以下VB6代码无效:

Option Explicit

Private Enum Execution_State
    ES_SYSTEM_REQUIRED = &H1
    ES_DISPLAY_REQUIRED = &H2
    ES_USER_PRESENT = &H4
    ES_CONTINUOUS = &H80000000
End Enum

Private Declare Sub SetThreadExecutionState Lib "kernel32" (ByRef esFlags As Long)

Private Sub Form_Load()
    SetThreadExecutionState Execution_State.ES_SYSTEM_REQUIRED Or Execution_State.ES_DISPLAY_REQUIRED Or Execution_State.ES_CONTINUOUS
End Sub

但以下C#代码却非常管用:

public partial class Form1 : Form
    {
        [DllImport("kernel32.dll")]
        static extern uint SetThreadExecutionState(uint esFlags);
        const uint ES_SYSTEM_REQUIRED = 0x00000001;
        const uint ES_DISPLAY_REQUIRED = 0x00000002;
        const uint ES_CONTINUOUS = 0x80000000;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
        }
    }

哪位知道原因,还望不吝赐教。

VB6中如何防止系统休眠?(博问出现问题,在些先编辑好以做备份)

标签:declare   dllimport   color   休眠   dll   play   dex   nstat   res   

原文地址:http://www.cnblogs.com/nanfei/p/6747612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!