jeudi 30 avril 2020

C# set foreground window from Console process

This is for a C# xUnit test project that spawns processes such as notepad.exe, winword.exe and winver.exe. I need to switch between these applications for the test (make them the foreground window).

So far, I have tried SetForegroundWindow, SwitchToThisWindow, SetActive, SetFocus etc from user32.dll, which doesn't work. I've tried using the AttachThreadInput trick, but it doesn't seem to work (maybe im doing it wrong? im using it from a console application after all). I've also tried the press alt then switch method, but I do not want to do it this way (notepad eats the alt).

Aucun commentaire:

Enregistrer un commentaire