TopMost without stealing focus

R

Robert Misiak

Is it possible to display a window on top without it stealing focus? (and
I'm not talking about stealing focus from my application - I'm talking about
it stealing focus from any application.) I've read that calling
ShowWindow() with SW_SHOWNOACTIVATE would work but I tried and it didn't.
I'm implementing a Windows Messenger-style notification window that
occasionally pops up with information.

Thanks,
Robert
 
S

Sean

Hi Robert,

Try the following(code for C#):

private const int SW_SHOWNA = 8;
[DllImport("user32", CharSet = CharSet.Auto)]
private extern static int ShowWindow(IntPtr hWnd, int
nCmdShow);

public void ShowWindow()
{
ShowWindow(ownerForm.Handle, SW_SHOWNA);
//ownerForm is the form that you want to retain the
//focus on
}

Please let me know if you still have problem getting it to
work. :)


regards,
Sean
 
R

Robert Misiak

Hi Sean-

Yes, it worked, thank you! I actually tried using SW_SHOWNA before I posted
but I also had TopMost set to true - calling it without setting TopMost
works fine.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top