未在C ++中设置墙纸 [英] Wallpaper not set in c++

查看:83
本文介绍了未在C ++中设置墙纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更改墙纸的程序..

但是未设置壁纸



This is the program to change the wallpaper..

But the wallpaper is not set



#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <iostream.h>
int main(int argc, char* argv[])
{

     LPWSTR  test = L"C:\\WINDOWS\\Web\\wallpaper\\Bliss.bmp";

     //C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures
char a[1024];

     sprintf(a,"%s","C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Blue hills.jpg");


    int result;

    result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, a, SPIF_SENDCHANGE);

//    result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, test, SPIF_UPDATEINIFILE);

    if (result)
    {
        cout << "Wallpaper set";
    }
    else
    {
        cout << "Wallpaper not set"<<endl;
        cout << "SPI returned" << result<<endl;;
    }

    return 0;
}

推荐答案

注意:使用SPI_SETDESKWALLPAPER标志时,SystemParametersInfo始终返回TRUE.来自 MSDN [
"Note When the SPI_SETDESKWALLPAPER flag is used, SystemParametersInfo always returns TRUE." from MSDN[^].
There is a note about the SPI_GETDESKWALLPAPER function at the bottom of that page by Razeen2008. It basically says that the data type is WCHAR, not char.

(I have not tried this code)
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <iostream.h>
int main(int argc, char* argv[]) {
    WCHAR a[1024] = L"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Blue hills.jpg"; //This has changed to WCHAR
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, a, SPIF_SENDCHANGE);
    //No point checking return value, it is always TRUE.
    return 0;
}


这篇关于未在C ++中设置墙纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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