Rafraichir le bureau Windows


Contenu du snippet

//using System;
//using System.Runtime.InteropServices;
private const uint RDW_INVALIDATE = 0x1U;
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern bool LockWindowUpdate(IntPtr hWndLock);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool RedrawWindow(IntPtr hWnd, HandleRef lprcUpdate, HandleRef hrgnUpdate, uint flags);

public static void RefreshDesktop() {
  IntPtr hDesk = GetDesktopWindow();
  LockWindowUpdate(hDesk);
  RedrawWindow(hDesk, new HandleRef(null, IntPtr.Zero), new HandleRef(null, IntPtr.Zero), RDW_INVALIDATE);
  LockWindowUpdate(IntPtr.Zero);
}

Compatibilité : C# 1.x, C# 2.x, C# 3.x

Disponible dans d'autres langages :

A voir également