怎样判断电脑正在锁屏?

wujim2011 2011-01-12 11:23:31
  
    由于工作需要,写个小东西,其中有个功能要判断电脑正在锁屏,怎样实现? 

    谢谢了.
...全文
735 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ayw215 2011-01-12
  • 打赏
  • 举报
回复
Hook锁屏的那个函数即可
chuidiaoweng 2011-01-12
  • 打赏
  • 举报
回复
可以上MSDN查查ISensLogon;不过这个是在锁屏之后接到通知,而不是正在锁屏。
赵4老师 2011-01-12
  • 打赏
  • 举报
回复
HOWTO: Detect If a Screen Saver Is Running on Windows NT
Last reviewed: January 5, 1998
Article ID: Q150785

The information in this article applies to:
Microsoft Win32 Software Development Kit (SDK)


SUMMARY
In Windows NT, you may find it useful to determine whether a screen saver is running on the system. On Windows NT 5.0 and greater, you can use the SystemParametersInfo API and specify the SPI_GETSCREENSAVERRUNNING flag to determine this.

In previous versions of Windows NT, there is no direct way to detect whether a screen saver is running on the system. However, there is an indirect approach to determine if a screen saver is running by testing for the existence of a desktop named "screen-saver" that the winlogon component of Windows NT creates for the screen saver to execute on. This desktop is created and destroyed when the screen saver is started and stopped.



MORE INFORMATION
When you use the OpenDesktop() Win32 API to attempt to open the desktop named "screen-saver", three scenarios result that help you to determine whether a screen saver is running:


The OpenDesktop() call succeeds: Close the returned desktop handle with the CloseDesktop() Win32 API. A screen saver is running.

The OpenDesktop() call fails and GetLastError() indicates ERROR_ACCESS_DENIED: The screen-saver desktop exists, but the caller does not have access to the desktop. A screen saver is running.

The OpenDesktop() call fails, and GetLastError() does not indicate ERROR_ACCESS_DENIED: If the error is ERROR_FILE_NOT_FOUND, the desktop does not exist and a screen saver is not running. Otherwise, an error occurred attempting to open the desktop. A screen saver is not running.

WORKAROUND


Sample Code

/**
The following sample illustrates how to detect if a screen saver
is running on Windows NT. This sample works by checking for the
existence of a desktop named "screen-saver". This desktop is
created dynamically by winlogon when a screen saver needs to be
launched.
**/

#include <windows.h>
#include <stdio.h>

BOOL IsScreenSaverRunning( void );

int
__cdecl
main(
void
)
{
if(IsScreenSaverRunning()) {
printf("Screen saver is running!\n");
}
else {
printf("Screen saver is NOT running!\n");
}

return 0;
}

//
// returns TRUE if a screen saver is running, or FALSE if not.
//

BOOL
IsScreenSaverRunning(
void
)
{
HDESK hDesktop;

//
// try to open the desktop that the screen saver runs on. This
// desktop is created on the fly by winlogon, so it only exists
// when a screen saver is invoked.
//

hDesktop = OpenDesktop(
TEXT("screen-saver"), // desktop name where screen saver runs
0,
FALSE,
MAXIMUM_ALLOWED // open for all possible access
);

if(hDesktop == NULL) {

//
// if the call fails due to access denied, the screen saver
// is running because the specified desktop exists - we just
// don't have any access.
//

if(GetLastError() == ERROR_ACCESS_DENIED) return TRUE;

//
// otherwise, indicate the screen saver isn't running
//

return FALSE;
}

//
// successfully opened the desktop (the screen saver is running)
//

CloseDesktop(hDesktop);

return TRUE;
}

Keywords : BseMisc GdiScrSav kbcode
Version : WINNT:3.5,3.51,4.0,5.0;
Platform : NT WINDOWS
Issue type : kbhowto

wujim2011 2011-01-12
  • 打赏
  • 举报
回复
能给 ISensLogon 使用例子吗?不会用.
乐CC 2011-01-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ayw215 的回复:]
Hook锁屏的那个函数即可
[/Quote]
楼主是要查啊,你这样也太狠了,直接Hook

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧