c# - SetForegroundWindow does not activate my window -


i can't figure out why not working ?

static void activateapp(string processname) {     process[] p = process.getprocessesbyname(processname);      // activate first application find name     if (p.any()) setforegroundwindow(p[0].mainwindowhandle);     else     {         console.writeline("something wrong");     } }       [stathread]     static void main(string[] args)     {         activateapp("acrobat.exe");     } 

output :

something wrong

but i'm sure acrobat.exe exist.

there weird rules whether setforegroundwindow() work.

at least 1 of following must true:

  • the process foreground process.
  • the process started foreground process.
  • the process received last input event.
  • there no foreground process.
  • the foreground process being debugged.
  • the foreground not locked.
  • the foreground lock time-out has expired (see spi_getforegroundlocktimeout in systemparametersinfo).
  • no menus active.

is case?

see the msdn documentation full details.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -