1、找到windows和system目錄的安裝位置
2、把屏幕保護文件復制到system目錄下
3、在system.ini中的[boot]中寫入:
SCRNSAVE.EXE=C:WINDOWSSYSTEM工程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下運行通過。
->