vs2012 c# SystemParametersInfo 在win7下无法设置桌面背景

程序在win10下可用.在win7下一直返回值:0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        int temp = SystemParametersInfo(20,0,"C:\\Windows\\Web\\Wallpaper\\img0.bmp",0);
        Console.WriteLine(temp);
    }


    [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
    public static extern int SystemParametersInfo(
     int uAction,
     int uParam,
     string lpvParam,
     int fuWinIni
     );


}

}

在win10下正常.在WIN7下一直返回零,麻烦各位大神支个招

4个回答

修改注册也只在WIN10有用.WIN7无用.真是奇了怪了

 "C:\\Windows\\Web\\Wallpaper\\img0.bmp"
这个图片存在么?
    SystemParametersInfo(20, 0, strFile, SPIF_UpdateAndSend)
'after Public Class class_name
Public Const SPI_SetWallpaper As Integer = &H14
'Win.ini flag values (intWinIniFlag)
Public Const SPIF_UpdateIni As Integer = 1
Public Const SPIF_SendIniChange As Integer = 2
Public Const SPIF_UpdateAndSend As Integer = SPIF_UpdateIni Or SPIF_SendIniChange '3
Public Const SPI_GETDESKWALLPAPER = &H73
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!