SystemParametersInfo sets wallpaper completly black (using SPI_SETDESKWALLPAPER)

可紊 提交于 2019-12-03 17:53:42

问题


I try to change my desktop wallpaper. It works just fine when I use it like this:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\1.jpg", SPIF_SENDCHANGE);

But when I use it like this, the desktop wallpaper is set completly black:

std::string s = "C:\\1.jpg";
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, &s, SPIF_SENDCHANGE);

I tried to get some more info via using GetLastError(), but the return value is just 0. I also tried to use .png-files, but this doesn't change anything.

Any ideas what I am doing wrong?


回答1:


Try this:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)s.c_str(), SPIF_SENDCHANGE);

The SystemParametersInfo function doesn't accept std::string pointer as path, it accepts a null-terminated char array. Which is what the c_str() method of std::string provides.



来源:https://stackoverflow.com/questions/34710677/systemparametersinfo-sets-wallpaper-completly-black-using-spi-setdeskwallpaper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!