windows - Understanding SystemParametersInfo SPI_SETFOREGROUNDLOCKTIMEOUT -
my app needs focus when get's called external tool (via api), know default is, should flash in taskbar, in case absolutely not behaviour want. in case try focus "this.activate()" (c#).
this foregroundlocktimeout comes play. however, got little problem understanding systemparameterinfo spi_setforegroundlocktimeout.
i know it's used set foregroundlocktimeout defines how long app has wait until gets focus requested.
(for further information variable "val" intptr set 0)
systemparametersinfo(spi_setforegroundlocktimeout,0,val,spif_sendwininichange + spif_updateinifile);
this 1 change registry key that handles timeout (hkey_current_user\control panel\desktop\foregroundlocktimout) since change behaviour of apps, it's last resort use.
now thought if don't update registry key. tried this:
systemparametersinfo(spi_setforegroundlocktimeout, 0, val, 0);
however doesn't change behavior of app in way,
systemparametersinfo(spi_setforegroundlocktimeout,0,val,spif_sendwininichange);
does.
what not understand why works app, absolutely want, not understandit .why have broadcast change, works app, when there has been no change made registry key or whatsoever, , why work app.
note: if want test behavior, test when visual studio not running, while it's running (even if solution not loaded) changes behavior of app getting focus in case.
this not per-app setting, global system setting. there's no way set application, when call systemparametersinfo
0 last parameter, nothing happens.
on other hand, when use spif_sendwininichange
, new setting gets broadcast in form of wm_settingchange
message. (which why manually editing registry wrong thing do; call documented api.)
aside that, code wrong:
spif_sendwininichange + spif_updateinifile
to concatenate 2 flags, must use boolean or operator (|
), not addition operator (+
). in particular case, because 0x1 + 0x2
, 0x1 | 0x2
both equal 3, seems work, that's accident.
the real solution problem needs not involve manipulating global settings (because surely don't want on client machines, if you're ok on own). need work with system, rather trying work against it. in system's model, process has focus 1 privilege of setting/changing focus. there 3 options:
just have external tool call
setforegroundwindow
, pass application's window parameter. altogether avoids app having activate itself.use
allowsetforegroundwindow
function delegate external tool's foreground-window-setting privileges application. should call function, passing id of app's process parameter. way, when app callssetforegroundwindow
, work expected.depending on how tool , application designed, have external tool launch application. the documentation says, if process launched foreground process, allowed set foreground window.
Comments
Post a Comment