禁用屏幕保护程序给用户

禁用屏幕保护程序给用户,第1张

概述禁用屏幕保护程序用户

我想要禁用另一个用户的屏幕保护程序。 如何做到这一点?

我有pipe理权限。 我有一个不能被屏幕保护程序中断的应用程序。

.NET windows服务 – 一个项目中的多个服务

在“stream程布局面板”内为“面板中的控件”设置锚点

记忆中密码的一般实践

移动和删除文件的密码确认?

Visual Studio 2010 .Net项目可以在linux下用MonoDevelop编译吗?

如果您自己编写应用程序,请查看调用非托管API SetThreadExecutionState( PInvoke参考 )。 从我的答案复制到如何防止屏幕保护程序和睡眠在我的程序执行过程中? :

不要乱用屏幕保护程序设置,请使用SetThreadExecutionState 。 这是用于通知窗口的API,您的应用程序处于活动状态:

使应用程序能够通知系统正在使用,从而防止系统在应用程序运行时进入睡眠状态或关闭显示屏。

,和

多媒体应用程序(如视频播放器和演示应用程序)在长时间不显示用户输入的情况下显示视频时,必须使用ES_disPLAY_required

如果您对应用程序无法控制,但屏幕保护程序踢入导致问题,则将此信息返回给开发人员。

禁用屏保几乎总是对问题的错误解决方案,因为它会影响用户的整体体验,而不仅仅是在应用程序运行时。

用C#控制屏幕保护程序

public static class ScreenSaver { // Signatures for unmanaged calls [Dllimport( "user32.dll",CharSet = CharSet.auto )] private static extern bool SystemParametersInfo( int uAction,int uParam,ref int lpvParam,int flags ); [Dllimport( "user32.dll",ref bool lpvParam,CharSet = CharSet.auto )] private static extern int PostMessage( IntPtr hWnd,int wMsg,int wParam,int lParam ); [Dllimport( "user32.dll",CharSet = CharSet.auto )] private static extern IntPtr OpenDesktop( string hDesktop,int Flags,bool inherit,uint DesiredAccess ); [Dllimport( "user32.dll",CharSet = CharSet.auto )] private static extern bool CloseDesktop( IntPtr hDesktop ); [Dllimport( "user32.dll",CharSet = CharSet.auto )] private static extern bool EnumDesktopwindows( IntPtr hDesktop,EnumDesktopwindowsProc callback,IntPtr lParam ); [Dllimport( "user32.dll",CharSet = CharSet.auto )] private static extern bool IsWindowVisible( IntPtr hWnd ); [Dllimport( "user32.dll",CharSet = CharSet.auto )] public static extern IntPtr GetForegrounDWindow( ); // Callbacks private delegate bool EnumDesktopwindowsProc( IntPtr hDesktop,IntPtr lParam ); // Constants private const int SPI_GETSCREENSAVERACTIVE = 16; private const int SPI_SETSCREENSAVERACTIVE = 17; private const int SPI_GETSCREENSAVERTIMEOUT = 14; private const int SPI_SETSCREENSAVERTIMEOUT = 15; private const int SPI_GETSCREENSAVERRUNNING = 114; private const int SPIF_SENDWININICHANGE = 2; private const uint DESKtop_WRITEOBJECTS = 0x0080; private const uint DESKtop_REAdobJECTS = 0x0001; private const int WM_CLOSE = 16; // Returns TRUE if the screen saver is active // (enabled,but not necessarily running). public static bool GetScreenSaverActive( ) { bool isActive = false; SystemParametersInfo( SPI_GETSCREENSAVERACTIVE,ref isActive,0 ); return isActive; } // Pass in TRUE(1) to activate or FALSE(0) to deactivate // the screen saver. public static voID SetScreenSaverActive( int Active ) { int nullVar = 0; SystemParametersInfo( SPI_SETSCREENSAVERACTIVE,Active,ref nullVar,SPIF_SENDWININICHANGE ); } // Returns the screen saver timeout setting,in seconds public static Int32 GetScreenSaverTimeout( ) { Int32 value = 0; SystemParametersInfo( SPI_GETSCREENSAVERTIMEOUT,ref value,0 ); return value; } // Pass in the number of seconds to set the screen saver // timeout value. public static voID SetScreenSaverTimeout( Int32 Value ) { int nullVar = 0; SystemParametersInfo( SPI_SETSCREENSAVERTIMEOUT,Value,SPIF_SENDWININICHANGE ); } // Returns TRUE if the screen saver is actually running public static bool GetScreenSaverRunning( ) { bool isRunning = false; SystemParametersInfo( SPI_GETSCREENSAVERRUNNING,ref isRunning,0 ); return isRunning; } // From Microsoft's KNowledge Base article #140723: // http://support.microsoft.com/kb/140723 // "How to force a screen saver to close once started // in windows NT,windows 2000,and windows server 2003" public static voID KillScreenSaver( ) { IntPtr hDesktop = OpenDesktop( "Screen-saver",false,DESKtop_REAdobJECTS | DESKtop_WRITEOBJECTS); if( hDesktop != IntPtr.Zero ) { EnumDesktopwindows( hDesktop,new EnumDesktopwindowsProc( KillScreenSaverFunc ),IntPtr.Zero ); CloseDesktop( hDesktop ); } else { PostMessage( GetForegrounDWindow( ),WM_CLOSE,0 ); } } private static bool KillScreenSaverFunc( IntPtr hWnd,IntPtr lParam ) { if( IsWindowVisible( hWnd ) ) PostMessage( hWnd,0 ); return true; } }

KillScreenSaver()

private voID KillTimer_Elapsed( object state ) { // Toggle kill state to indicate activity killState = ( killState == 1 ) ? 0 : 1; this.SetText( killState.ToString( ) ); // Stop the screen saver if it's active and running,// otherwise reset the screen saver timer. // Apparently it's possible for GetScreenSaverRunning() // to return TRUE before the screen saver has time to // actually become the foreground application. So... // Make sure we're not the foreground window to avoID // killing ourself. if( ScreenSaver.GetScreenSaverActive( ) ) { if( ScreenSaver.GetScreenSaverRunning( ) ) { if( ScreenSaver.GetForegrounDWindow() != hThisWnd) ScreenSaver.KillScreenSaver( ); } else { // reset the screen saver timer,so the screen // saver doesn't turn on until after a full // timeout period. If killPeriod is less than // sstimeout the screen saver should never // activate. ScreenSaver.SetScreenSaverActive( TRUE ); } } }

总结

以上是内存溢出为你收集整理的禁用屏幕保护程序给用户全部内容,希望文章能够帮你解决禁用屏幕保护程序给用户所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1288038.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存