Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: Show window without activation

Tags:

I struggle to show a second form above the main form without losing focus.

I have tried ShowWindow(second.handle, SW_SHOWNOACTIVATE), but the mainform loses focus. If I set Visible := false on the second window, the call to ShowWindow does not activate the second form, but the windows is empty when shown...

Does anyone have a good recipe for this?

UPDATE: What I'm trying to do, is showing a notify-window at a given event. It's crucial that the main form does not lose focus at any time.

like image 484
Vegar Avatar asked Mar 31 '09 09:03

Vegar


2 Answers

There has to be something wrong with your code.

I tested this code, it works:

procedure TForm1.Button1Click(Sender: TObject); begin   ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE);   Form2.Visible := True; end; 

Be careful to use Visible, not Show ! Otherwise it'll override the SW_SHOWNOACTIVATE.

like image 182
Daniel Rikowski Avatar answered Nov 20 '22 22:11

Daniel Rikowski


You can show the window (non modal) and reset the focus to the mainwindow.

procedure TMainForm.ButtonClick(Sender: TObject); begin   OtherForm.Show;   SetFocus; end; 

Tested on 2006.

This does not show the other form on top. But it is very counter intuitive to have a window on top that does not have the focus.

like image 32
Toon Krijthe Avatar answered Nov 20 '22 22:11

Toon Krijthe