1、找到windows和system目录的安装位置
2、把屏幕保护文件复制到system目录下
3、在system.ini中的[boot]中写入:
SCRNSAVE.EXE=C:/WINDOWS/SYSTEM/工程1.SCR
4、告诉系统切换屏幕保护。
下面的例子成功地改变了屏幕保护,全部源代码如下:
'得到windows目录
PRivateDeclareFunctionGetWindowsDirectoryLib"kernel32"Alias"GetWindowsDirectoryA"(ByVallpBufferAsString,ByValnSizeAsLong)AsLong
'修改system.ini
PrivateDeclareFunctionWritePrivateProfileStringLib"kernel32"Alias"WritePrivateProfileStringA"(ByVallpapplicationNameAsString,ByVallpKeyNameAsAny,ByVallpStringAsAny,ByVallplFileNameAsString)AsLong
'得到system目录
PrivateDeclareFunctionGetSystemDirectoryLib"kernel32"Alias"GetSystemDirectoryA"(ByVallpBufferAsString,ByValnSizeAsLong)AsLong
'设置屏幕保护
PrivateConstSPI_SETSCREENSAVETIMEOUT=15
PrivateConstSPI_SETSCREENSAVEACTIVE=17
PrivateConstSPIF_UPDATEINIFILE=&H1
PrivateConstSPIF_SENDWININICHANGE=&H2
PrivateDeclareFunctionSystemParametersInfoLib"user32"Alias"SystemParametersInfoA"(ByValuActionAsLong,ByValuParamAsLong,ByVallpvParamAsLong,ByValfuWinIniAsLong)AsLong
'启动屏幕保护
PrivateDeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLong
PrivateConstWM_SYSCOMMAND=&H112
PrivateConstSC_SCREENSAVE=&HF140
PrivateSubForm_Load()
'得到system目录
DimsSaveAsString,RetAsLong
sSave=Space(255)
Ret=GetSystemDirectory(sSave,255)
sSave=Left$(sSave,Ret)
'把屏保复制到系统目录
FileCopyApp.Path&"/工程1.scr",sSave&"/工程1.SCR"
'得到windows目录
DimPathAsString,strSaveAsString
strSave=String(250,Chr$(0))
Path=Left$(strSave,GetWindowsDirectory(strSave,Len(strSave)))
'修改system.ini
DimrAsLong
DiminipathAsString
iniPath$=Path "/system.ini"
r=WritePrivateProfileString("boot","SCRNSAVE.EXE",sSave&"/工程1.SCR",iniPath)
'设置时间间隔为1分钟=60秒
lRet=SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,60,ByVal0&,
SPIF_UPDATEINIFILE SPIF_SENDWININICHANGE)
'设置屏幕保护
retval=SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,True,0,0)
'启动屏幕保护
DimresultAsLong
result=SendMessage(Form1.hwnd,WM_SYSCOMMAND,SC_SCREENSAVE,0&)
EndSub
本例在vb6.0 win95下运行通过。
->新闻热点
疑难解答