1

I use without problems a program that uses [SetForegroundWindow] in C# to bring the window to the foreground and activate in Windows 7 and Windows 10 operating systems, but now with Windows 11 it stopped working.

I need help, does anyone know how to be able to use SetForegroundWindow on Windows 11?

Site: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow

//windows forms project

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("USER32.DLL")]

public static extern bool SetForegroundWindow(IntPtr hWnd);

//use

IntPtr janela = FindWindow(null, "Seleção de Cliente");

SetForegroundWindow(janela);

  • 1
    The problem with [SetForegroundWindow] was solved, when running the program as administrator it can use [SetForegroundWindow]. before it was not necessary in windows 10 – André Luiz Aug 04 '22 at 21:11

0 Answers0