在Windows 7中以编程方式更改背景 [英] Programmatically change background in Windows 7

查看:142
本文介绍了在Windows 7中以编程方式更改背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个为Windows 7 Starter创建幻灯片背景的程序.我当前的程序在XP中可以完美运行,而在Windows 7 Starter上却无能为力.它会很好地创建临时文件,但不会将其设置为后台.当它在Windows 7 Home Premium上运行时,在尝试运行更改背景的命令时出现了一般错误".这是我的脚本中实际设置背景的部分:

I''m trying to write a program that creates a slideshow background for Windows 7 Starter. My current program works perfect in XP and on Windows 7 Starter it does nothing. It creates the temporary file just fine but won''t set it to the background. When it''s run on Windows 7 Home Premium it gives me a "generic error" when trying to run the command to change the background. Here is the portion of my script that actually sets the background:

<pre lang="cs">private void setBackground()<br />
        {<br />
            if (Counter >= files.Length)<br />
                Counter = 0;<br />
            if (File.Exists(files[Counter]))<br />
            {<br />
                files[Counter] = files[Counter].ToLower();<br />
                using (Image img = Image.FromFile(files[Counter]))<br />
                {<br />
                    img.Save(tempPath, ImageFormat.Bmp);<br />
                }<br />
                try<br />
                {<br />
                    if (SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE) != 0)<br />
                    {<br />
                        Counter += 1;<br />
                    }<br />
                    else<br />
                    {<br />
                        MessageBox.Show("There was an error in setting the wallpaper.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);<br />
                    }<br />
                }<br />
                catch<br />
                {<br />
                    MessageBox.Show("There was an error in setting the wallpaper.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);<br />
                }<br />
            }<br />
        }</pre><br />


只是为了消除对此的任何混淆,tempPath指向在Windows目录中创建的temp.bmp,它是通过程序设置的,因此即使在非默认的Windows目录中,它也将以相同的方式工作.在定义的时间间隔后,将tempPath中的文件与数组中的下一个文件一起覆盖.我猜想在Windows 7中使用SystemParametersInfo会有问题,我意识到在Windows 7 Starter中可能无法实现,但是我很难相信,MSDN并没有说这两个都是真的.不用说,Google搜索什么都没有.


And just to clear up any confusion about it, tempPath points to temp.bmp which is created in the windows directory, set programmatically so it will work the same way even with a non-default windows directory. After the defined interval time the file at tempPath is written over with the next file in the array. I''m guessing there is a problem with using SystemParametersInfo in Windows 7 and I realize this may not be possible in Windows 7 Starter but I find it hard to believe, and MSDN says nothing of either of these being true. Needless to say, a Google search has turned nothing up.

推荐答案

您好,

有关更多信息,请参见此处:
http://social.answers.microsoft.com/论坛/en-US/w7install/thread/422801d5-89de-494d-8cc1-6f4fc21c2ac0 [
Hi,

see here for more information:
http://social.answers.microsoft.com/Forums/en-US/w7install/thread/422801d5-89de-494d-8cc1-6f4fc21c2ac0[^]
It doesn''t work since windows 7 starter does not allow changing the desktop wallpaper.
You can also google for "windows 7 starter limitations" to find more information.


这篇关于在Windows 7中以编程方式更改背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆