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);