* Tina:
I'm sorry but I do not understand what it is you're trying to achieve.
As Lucian Wishik wrote, when the goal is to disable the screensaver while a
particular application is active, then
Otherwise, for global screensaver management, there is a way to
enable/disable, and there is a way to select a screensaver. Which can
de-activate by selecting "none". Here's some olde code for that:
// Indent = Tab = 4
//////////////////////////////////////////////////////////////////////////////
//
// Module ScreenSaverUtil
// implementation
//
// Free-standing functions for controlling and obtaining info about screensavers.
// Copyright (c) Alf P. Steinbach, 2002.
//
// This file is part of Alf's ScreenSaver Manager.
//
// Alf's ScreenSaver Manager is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Alf's ScreenSaver Manager is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Alf's ScreenSaver Manager; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
#include "ScreenSaverUtil.h"
//-------------------------------------- Dependencies
#include <stdexcept> // std::runtime_error
#ifndef CPP_WINDOWS_H_
# include <win32/cpp_windows.h> // Wrapper for <windows.h>.
#endif
#ifndef KERNELUTIL_H_
# include <win32/KernelUtil.h> // IsWindow9x()
#endif
#ifndef _INC_SCRNSAVE
# include <scrnsave.h> // IDS_DESCRIPTION
#endif
#ifndef _INC_SHLWAPI
# include <shlwapi.h> // PathFindFileName()
#endif
//-------------------------------------- Implementation
namespace alfs { namespace windowing {
bool ScreenSaverIsEnabledFlag()
{
BOOL isEnabled = FALSE;
if( !::SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0, &isEnabled, 0 ) )
{
throw std::runtime_error( "Unable to find whether the screensaver is enabled" );
}
return !!isEnabled;
} // ScreenSaverIsEnabledFlag
bool ScreenSaverIsEnabled()
{
// In some Windows versions, or due to some faulty program, the ScreenSaverIsEnabledFlag()
// may be set even when there is no selected screensaver.
return (ScreenSaverIsEnabledFlag() && AScreenSaverIsSelected());
} // ScreenSaverIsEnabled
void SetScreenSaverIsEnabled( bool const newValue )
{
if( newValue == true && !AScreenSaverIsSelected() )
{
throw std::runtime_error( "Cannot enable the screensaver when none is selected" );
}
if( !::SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, newValue, NULL, SPIF_SENDCHANGE ) )
{
if( newValue == true )
{
throw std::runtime_error( "Unable to enable the screensaver" );
}
else
{
throw std::runtime_error( "Unable to disable the screensaver" );
}
}
} // SetScreenSaverIsEnabled
std::string const NameOfScreenSaver( char const ssPath[] )
{
// See KB article Q126239.
// "ssPath" is the "screen saver path", path to the screensaver executable.
HMODULE const moduleHandle = ::LoadLibraryEx( ssPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
if( moduleHandle == 0 )
{
throw std::runtime_error( "Unable to find or load the screensaver" );
}
unsigned const maxNameLength = 25; // See <scrnsave.h>.
char name[maxNameLength + 1];
int const nChars = ::LoadString( moduleHandle, IDS_DESCRIPTION, name, sizeof( name ) );
::FreeLibrary( moduleHandle );
return (nChars == 0? ::PathFindFileName( ssPath ) : name );
} // NameOfScreenSaver
void StartEnabledScreenSaver()
{
// Ver. 0.5: Changed ::GetDesktopWindow() to HWND_TOPMOST, as per
// KB article Q262646, "How to Lock a Workstation from the Command Line".
// Ver. 0.51: Changed it back to ::GetDesktopWindow, 'cause the documented
// way didn't work!
:
efWindowProc( ::GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0 );
} // StartEnabledScreenSaver
static char const* GetSelectedScreenSaverNT( char pathBuffer[MAX_PATH+1] )
{
HKEY keyHandle = 0;
LONG const rokeResult = ::RegOpenKeyEx(
HKEY_CURRENT_USER,
"Control Panel\\Desktop",
0, // Options, reserved.
KEY_READ,
&keyHandle
);
if( rokeResult != ERROR_SUCCESS )
{
throw std::runtime_error(
"Unable to open registry key [HKEY_CURRENT_USER\\Control Panel\\Desktop]"
);
}
else
{
DWORD valueType = 0;
DWORD byteCount = MAX_PATH + 1;
pathBuffer[0] = '\0';
LONG const rqveResult = ::RegQueryValueEx(
keyHandle,
"SCRNSAVE.EXE",
0, // Reserved.
&valueType,
reinterpret_cast<LPBYTE>( reinterpret_cast<ULONG_PTR>( pathBuffer ) ),
&byteCount
);
::RegCloseKey( keyHandle );
if( rqveResult == ERROR_SUCCESS || rqveResult == ERROR_FILE_NOT_FOUND )
{
return pathBuffer;
}
else
{
throw std::runtime_error( "Unable to read screensaver path value from registry" );
}
}
} // GetSelectedScreenSaverNT
static char const* GetSelectedScreenSaver9x( char pathBuffer[MAX_PATH+1] )
{
// Windows 9x code.
//
// This actually also works on Windows NT, since GetPrivateProfileString is
// redirected to the registry for backwards compatibility with Windows 3.x.
//
// Mainly based on KB article Q193794 "The Previous Screen Saver Is Still Used
// After You Change It", which for Windows 95 and 98 states that "When you change
// a screen saver, the change is recorded in the System.ini file in the [Boot]
// section on the 'scrnsave.exe=' line".
// No documented meaningful error status from GetPrivateProfileString.
::GetPrivateProfileString(
"boot", // Section name.
"scrnsave.exe", // Key name.
"", // Default result.
pathBuffer,
MAX_PATH + 1,
alfs::FileSpec( win32::WindowsDirectoryPath(), "\\system.ini" ).ToString().c_str()
);
return pathBuffer;
} // GetSelectedScreenSaver9x
static inline char const* GetSelectedScreenSaver( char pathBuffer[MAX_PATH+1] )
{
// TODO: Make a real choice when IsWindows9x has been confirmed to work.
return (
true || alfs::win32::IsWindows9x()
? GetSelectedScreenSaver9x( pathBuffer )
: GetSelectedScreenSaverNT( pathBuffer )
);
} // GetSelectedScreenSaver
std::string const SelectedScreenSaver()
{
char pathBuffer[MAX_PATH + 1];
return GetSelectedScreenSaver( pathBuffer );
} // SelectedScreenSaver
bool AScreenSaverIsSelected()
{
char pathBuffer[MAX_PATH + 1];
// Equivalent to (SelectedScreenSaver().length() > 0), but more efficient.
return !!*GetSelectedScreenSaver( pathBuffer );
} // AScreenSaverIsSelected()
void ShowScreenSaverProperties()
{
// The following command is *UNDOCUMENTED*. The documented command is "control desktop".
// But the documented command doesn't give any way to select which page (tab) should be
// initially displayed. The following displays the screensaver page on Windows XP, unless
// the applet is already running, in which case it's activated with no change of current
// page. Hopefully this command works on other Windows versions, too...
//
// Partial doc of this command (the general scheme) can be found in KB article Q135068,
// "HOWTO: Start a Control Panel Applet in Windows 95 or Later".
//
// "control.exe" is unqualified in case it resides in the Windows directory on Windows 9x.
// The applet is used instead of just "desktop" because the latter ignores parameters.
win32::Start(
"control.exe " +
alfs::FileSpec( win32::SystemDirectoryPath(), "desk.cpl,@0,1" ).ToString()
);
} // ShowScreenSaverProperties
} } // namespace alfs::windowing
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?