锁定电脑屏幕,相当于“Win + L” 锁定效果

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/nokianasty/article/details/76411228

LockWorkStation function

Locks the workstation's display. Locking a workstation protects it from unauthorized use.

Syntax

BOOL WINAPI LockWorkStation(void);

Parameters

This function has no parameters.

Return value

If the function succeeds, the return value is nonzero. Because the function executes asynchronously, a nonzero return value indicates that the operation has been initiated. It does not indicate whether the workstation has been successfully locked.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The LockWorkStation function is callable only by processes running on the interactive desktop. In addition, the user must be logged on, and the workstation cannot already be locked.

Common reasons the workstation might not be locked even if the function succeeds include the following: no user is logged on, the workstation is already locked, the process is not running on the interactive desktop, or the request is denied by the Graphical Identification and Authentication (GINA) DLL.

This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation. To unlock the workstation, the user must log in. There is no function you can call to determine whether the workstation is locked. To receive notification when the user logs in, use the WTSRegisterSessionNotification function to receiveWM_WTSSESSION_CHANGE messages. You can use session notifications to track the desktop state so you know whether it is possible to interact with the user.

Examples

For an example, see How to Lock the Workstation.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

System Shutdown Functions
展开阅读全文

如何锁定软件!不是锁定电脑屏幕

01-13

公司需要对一个自己出的软件实现锁定软件功能。是一个WinForm程序。例如这个程序有一个主界面,在主界面的右上角有一个锁定的BUTTON1。点了之后呢使这个软件被锁定。而用户可以最小化它。而去干别的事情。rn 我的思路是(建设主界面叫做Form1).rn 在Form1 设置一个全局变量,bool IsLock,当我点击锁定按钮BUTTON1的时候,我在按钮事件里面写给Form1的MouseDown事件添加一个实现事件的函数。rn 例如 xxxxx(object sender,MouseEventArgs)rn rn if(IsLock)rn rn Form form2 = new Form();rn form2.showdialog();//这个Form2上面就显示输入框和确认按钮。如果用户输入正确密码rn if (form2.passWord==true)rn IsLock=false;rn rn rn 这样在你点击了锁定按钮之后呢,再点击页面呢,会使得响应这个函数。但是有2个很大的缺陷,1、首先我锁定软件之后呢,一般用户会想吧主页面缩小到最小,但是当他点击页面时候,页面已经处于锁定状态了!rn 2、当点击锁定按钮的时候呢。我觉得最好是有个明确的显示让客户知道页面已经被锁定。当然我可以在点击锁定按钮BUTTON1中做个提示框告诉用户你已经锁定这个程序,但是我希望最好不是弹出提示框,而是在我点击BUTTON1的时候呢,在软件80%的范围上覆盖一个薄薄的透明层。这个透明层呢和主界面一起变大变小。并且不影响用户操作电脑上面其他软件。rn rn 论坛

没有更多推荐了,返回首页