Let say there is a galactica-wallpaper.jpg at My Documents folder. We can change desktop background image using SystemParametersInfoW function of User32. (tested on Windows 11 Pro 22H2).
Module TestMe {
module changeWallPaper (strImagePath$){
declare SystemParametersInfo lib "User32.SystemParametersInfoW" {Long action, Long Param, &pvParam$, Long fWinIni}
const SPI_SETDESKWALLPAPER = 20&
const SPIF_SENDWININICHANGE = &H2
const SPIF_UPDATEINIFILE = &H1
Call void SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, &strImagePath$, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
}
// 0x5 for Documents Folder - see: help path$()
changeWallPaper path$(0x5)+"galactica-wallpaper.jpg"
}
TestMe
Now what if we have some jpg files at My Documents and we wish to cbange desktop background every half minute ?
This is the slide show. We get file names and put them to menu, without showing menu. We just read the menu items one by one.
Module TestMe {
module changeWallPaper (strImagePath$){
declare SystemParametersInfo lib "User32.SystemParametersInfoW" {Long action, Long Param, &pvParam$, Long fWinIni}
const SPI_SETDESKWALLPAPER = 20&
const SPIF_SENDWININICHANGE = &H2
const SPIF_UPDATEINIFILE = &H1
Call void SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, &strImagePath$, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
}
// 0x5 for My Documents Folder - see: help path$()
Title "SlideShow", 0
Try {
Repeat
dir path$(0x5)
menu
files + "jpg"
dir user
if menuitems>0 then
for i=1 to menuitems
try {
changeWallPaper path$(0x5)+menu$(i)+".jpg"
}
wait 30000
next
end if
Until menuitems=0
}
Title "M2000", 1
}
TestMe
And the best of all (using 0% processor for most time):
Module TestMe {
module changeWallPaper (strImagePath$){
declare SystemParametersInfo lib "User32.SystemParametersInfoW" {Long action, Long Param, &pvParam$, Long fWinIni}
const SPI_SETDESKWALLPAPER = 20&
const SPIF_SENDWININICHANGE = &H2
const SPIF_UPDATEINIFILE = &H1
Call void SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, &strImagePath$, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
}
// 0x5 for My Documents Folder - see: help path$()
flush
Title "SlideShow", 0
Try {
every 30000 {
if empty then
dir path$(0x5)
menu
files + "jpg"
dir user
if menuitems>0 then
for i=1 to menuitems
try {
data path$(0x5)+menu$(i)+".jpg"
}
next
end if
end if
if not empty then changeWallPaper
}
}
Title "M2000", 1
}
TestMe
And final, using a mutex to run only once and without using a window at taskbar (running like a service). When the first (which create the mutex) exit delete the mutex. (We have to clode by task manager, or automatic close at shutdown of windows.
Module TestMe {
Declare m Mutex
boolean pass
try {
method m, "CREATE", "Global\SLIDE10101001"
pass=true
}
if pass else exit
module changeWallPaper (strImagePath$){
declare SystemParametersInfo lib "User32.SystemParametersInfoW" {Long action, Long Param, &pvParam$, Long fWinIni}
const SPI_SETDESKWALLPAPER = 20&
const SPIF_SENDWININICHANGE = &H2
const SPIF_UPDATEINIFILE = &H1
Call void SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, &strImagePath$, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
}
// 0x5 for My Documents Folder - see: help path$()
flush
Title "", 0
Try {
every 30000 {
if empty then
dir path$(0x5)
menu
files + "jpg"
dir user
if menuitems>0 then
for i=1 to menuitems
try {
data path$(0x5)+menu$(i)+".jpg"
}
next
end if
end if
if not empty then changeWallPaper
}
}
Title "M2000", 1
}
TestMe: End
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.