请高手帮忙?如何通过程序启动NT4.0的屏幕保护,又如何强行关闭正在运行的有密码保护的屏幕保护程序?(100分)

Q

qinmiao

Unregistered / Unconfirmed
GUEST, unregistred user!
在WINDOW NT4。0 运行程序侦听到关机信息后关闭NT,但在屏幕保护程序运行后,
NT不会关闭,不知为何,请大狭帮助,在需要时关掉带密码保护的屏保。请贴全码。
另,这有一篇关于启动、关闭屏幕保护的文章,本人看不懂。
HOWTO: Force a Screen Saver to Close Once Started in Windows NT
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Win32 Software Development Kit (SDK), used with:
Microsoft Windows NT Server versions 3.1, 3.5, 3.51, 4.0
Microsoft Windows NT Workstation versions 3.1, 3.5, 3.51, 4.0
The Microsoft Windows 2000 operating system
--------------------------------------------------------------------------------

SUMMARY
Sometimes applications need to terminate a screen saver that is already running. In Windows 3.1 or Windows 95, a screen saver could be terminated easily by posting a WM_CLOSE message to the currently active screen saver window as in this example:
PostMessage (GetActiveWindow(), WM_CLOSE, 0, 0L);
Windows NT, however, introduces the concept of separate desktops, so that applications can run on one, and screen savers can run on another. This makes screen saver termination under Windows NT and Windows 2000 a bit more difficult.

MORE INFORMATION
Obtaining a handle to the currently active screen saver window under Windows NT or Windows 2000 is not as straightforward as it is in Windows 3.1 and Windows 95. Calling GetForegroundWindow() returns NULL because the screen saver is running on a different desktop than the calling application. Similarly, calling FindWindow ("WindowsScreenSaverClass", NULL) to determine if the screen saver is currently active do
es not work either.
To do
this, get a handle to the screen saver's desktop, enumerate that desktop's windows, and then
post a WM_CLOSE to the screen saver window.
The following code demonstrates how to do
this. Note that if a screen saver password is set, the following code brings up the password dialog box, prompts the user for a password, and then
actually terminates the screen saver application.

BOOL CALLBACK KillScreenSaverFunc(HWND hwnd, LPARAM lParam)
{
if(IsWindowVisible(hwnd))
PostMessage(hwnd, WM_CLOSE, 0, 0);
return TRUE;
}
HDESK hdesk;
hdesk = OpenDesktop(TEXT("Screen-saver"),
0,
FALSE,
DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS);
if (hdesk)
{
EnumDesktopWindows(hdesk, KillScreenSaverFunc, 0);
CloseDesktop(hdesk);
}
Note that terminating a screen saver that is already running as demonstrated above is totally separate from disabling the screen saver altogether, so that no screen saver starts after the designated time period expires. This can be do
ne easily using:
SystemParametersInfo( SPI_SETSCREENSAVEACTIVE,
FALSE,
0,
SPIF_SENDWININICHANGE
);
This method works well for terminating the currently running screen saver. However, one problem that you might encounter is that the system will not restart the screen saver unless the user moves the mouse or presses a key. If you need the screen saver to start up again, you'll need to reinitialize the time-out period. do
this by:
Calling SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, TRUE, 0, SPIF_SENDWININICHANGE).
-or-

Using SetCursorPos() to simulate user input.

Both of these methods will cause the system to restart the time-out counter for the screen saver.
Additional query words: deactivate disable stop running turn off screensaver
Keywords : kbcode kbOSWinNT kbOSWinNT310 kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbScreenSaver kbSDKWin32 kbGrpUser
Issue type : kbhowto
Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT351search kbWinNT350search kbWinNT400search kbWinNTW350 kbWinNTW350search kbWinNTW351search kbWinNTW351 kbWinNTW310 kbWinNTSsearch kbWinNTS400search kbWinNTS400 kbWinNTS351 kbWinNTS350 kbWinNTS310 kbWinNTS351search kbWinNTS350search kbWinNTS310search kbOSWinNT kbOSWinSearch kbWinNT310Search kbWinNTW310Search

http://support.microsoft.com/support/kb/articles/Q140/7/23.asp

 
qinmiao:
可以参考关闭进程的例子,如果要继续请提前,否则请结束问题,谢谢
 
启动屏幕保护
SendMessage(handle, wm_syscommand, SC_SCREENSAVE, 0);
禁止屏幕保护
function KillScreenSaverFunc(hwnd: HWND;
lParam: LPARAM): Boolean;
stdcall;
begin
PostMessage(hwnd, WM_CLOSE, 0, 0);
Result := True;
end;

procedure CScrnDesktop.KillScreenSaver;
var
osversioninfo: TOSVersionInfo;
hsswnd: HWND;
hDesk: THandle;
begin
osversioninfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);

if not GetVersionEx(osversioninfo) then
Exit;
case osversioninfo.dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS:
begin
hsswnd := FindWindow('WindowsScreenSaverClass', nil);
if hsswnd <> 0 then
PostMessage(hsswnd, WM_CLOSE, 0, 0);
end;
VER_PLATFORM_WIN32_NT:
begin
hDesk := OpenDesktop('Screen-saver',
0,
False,
DESKTOP_READOBJECTS or DESKTOP_WRITEOBJECTS);
if hDesk <> 0 then
begin
EnumDesktopWindows(hDesk, @KillScreenSaverFunc, 0);
CloseDesktop(hDesk);
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,
Cardinal(True),
nil,
SPIF_SENDWININICHANGE);
end;
end;
end;
end;
 
多人接受答案了。
 

Similar threads

顶部