dummzeuch 1505 Posted March 22, 2019 (edited) Normally, when a VCL program is started via double click or commandline it shows its main window in the foreground thereby taking the focus from the previously active window. Is there any way how such a program can prevent that? I still want it to show the main window but the focus should stay with the previously active window. I don't want my program to get into the foreground at all, not just move the window into the background or minimize it after a short time. No flickering, no interrupting the user from the work he is currently doing. Edited March 22, 2019 by dummzeuch Share this post Link to post
Attila Kovacs 629 Posted March 22, 2019 I'd try to override the "show" process and call showwindow with SW_SHOWNOACTIVATE. Maybe there is already something in VCL. Share this post Link to post
dummzeuch 1505 Posted March 22, 2019 3 hours ago, Attila Kovacs said: I'd try to override the "show" process and call showwindow with SW_SHOWNOACTIVATE. Maybe there is already something in VCL. As of Delphi 2007, there isn't. But I found one option: WindowState := wsMinimized; Application.MainFormOnTaskbar := false; Not quite what I am looking for, because the window is shown minimized rather than normal, but for now that's ok. Share this post Link to post
Attila Kovacs 629 Posted March 22, 2019 The simplest way, without having to reimplement a couple of things from the original CMShowingChanged is leaving the form on wsMinimized and then calling a SW_SHOWNOACTIVATE: private procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED; procedure TForm3.CMShowingChanged(var Message: TMessage); begin inherited; ShowWindow(Handle, SW_SHOWNOACTIVATE); end; This will also result a "restore" animation, if enabled. 1 Share this post Link to post
dummzeuch 1505 Posted March 23, 2019 I ended up using the following code: constructor Tf_MyForm.Create(_Owner: TComponent); begin inherited; WindowState := wsMinimized; ShowWindow(Handle, SW_SHOWNOACTIVATE); end; So far it seems to work fine. 3 Share this post Link to post