How to get the current Windows wallpaper name using IActiveDesktop interface with C++ Win32 API

1 Answer

0 votes
#include <Windows.h> 
#include <Wininet.h>
#include <Shlobj.h>
#include <iostream>

int main()
{
    CoInitialize(nullptr);
    IActiveDesktop* pDesktop = nullptr;
    WCHAR wszWallpaper[MAX_PATH];

    CoCreateInstance(
        CLSID_ActiveDesktop,
        nullptr,
        CLSCTX_INPROC_SERVER,
        _uuidof(IActiveDesktop),
        reinterpret_cast<void**>(&pDesktop)
    );

    pDesktop->GetWallpaper(wszWallpaper, MAX_PATH, 0);
    std::wcout << wszWallpaper;

    CoUninitialize();
}


/*
run:

c:\users\...\pictures\saved pictures\abc-3840x2160-4k-wallpaper-beautiful-view-741.jpg

*/

 



answered Oct 31, 2024 by avibootz
edited Oct 31, 2024 by avibootz
...