在windows7中使用python和IActiveDesktop设置墙纸

2024-09-30 22:10:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在寻找如何使用IActiveDesktop来更改墙纸,并拼凑了以下来自不同来源的代码。在

sys.coinit_flags = 0
pythoncom.CoInitialize()
iad = pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IActiveDesktop)
iad.SetWallpaper(bmpPath)
iad.ApplyChanges(7)

我得到以下错误:

pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)

我真的不知道我在这里做什么。在

请注意,我不想使用SystemParametersInfo,因为它没有IActiveDesktop明显具有的淡入效果。在


Tags: 代码none墙纸sys来源errorshellflags
1条回答
网友
1楼 · 发布于 2024-09-30 22:10:28

我想您只是缺少了SetWallPaper的第二个参数,它应该总是0。 这对我有用:

import pythoncom
from win32com.shell import shell, shellcon

imagePath = "c:\\temp\\bug.png"

iad = pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, None,
          pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IActiveDesktop)
iad.SetWallpaper(imagePath, 0)
iad.ApplyChanges(shellcon.AD_APPLY_ALL)

参考号:IActiveDesktop::ApplyChanges Method

相关问题 更多 >