Idad Wind
Idad Wind

Reputation: 61

How to get the user's wallpaper

As the title I would like the effect like UAC's background

Here is a code I found from web.

using System;
using System.Runtime.InteropServices;

namespace cleandesktop
{
    internal static class Program
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool SystemParametersInfo(uint uAction, uint uParam, StringBuilder lpvParam, uint init);
        const uint SPI_GETDESKWALLPAPER = 0x0073;
        static void Main(string[]) args
        {
            StringBuilder wallPaperPath = new StringBuilder(200);
            if (SystemParametersInfo(SPI_GETDESKWALLPAPER, 200, wallPaperPath, 0))
            {
                MessageBox.Show(wallPaperPath.ToString());
            }
        }
    }
}

This code get the path of the wallpaper picture, but this code only works when users hadn't delete their wallpaper picture.

Upvotes: 2

Views: 180

Answers (1)

Anders
Anders

Reputation: 101569

PaintDesktop

The PaintDesktop function fills the clipping region in the specified device context with the desktop pattern or wallpaper.

Upvotes: 1

Related Questions