Some questions about focus on WPF

Posted by ThitoO on Stack Overflow See other posts from Stack Overflow or by ThitoO
Published on 2010-05-05T08:12:48Z Indexed on 2010/05/05 8:18 UTC
Read the original article Hit count: 204

Filed under:
|
|

Hello,

I've a little problem about focus on WPF. I whant to create a window, always on top, and that never get the focus (even if we click on it).

Here's my solution :

public partial class SkinWindow : Window
{
    public SkinWindow()
    {
        InitializeComponent();
        Loaded += ( object sender, RoutedEventArgs e ) => SetNoActiveWindow();
    }

    private void SetNoActiveWindow()
    {
        WindowInteropHelper helper = new WindowInteropHelper( this );
        SetWindowLong( helper.Handle, GWL_EXSTYLE, WS_EX_NOACTIVATE );
        LockSetForegroundWindow( LSFW_LOCK );
    }

    const int GWL_EXSTYLE = -20;
    const int WS_EX_NOACTIVATE = 134217728;
    const int LSFW_LOCK = 1;

    [DllImport( "user32" )]
    public static extern bool LockSetForegroundWindow( uint UINT );

    [DllImport( "user32" )]
    public static extern IntPtr SetWindowLong( IntPtr hWnd, int nIndex, int dwNewLong );
}

First problem : It's works, but I've to select an other window to "remove" the focus of my application (after the focus is not gave again, even if I click on my window). Second problem : When I move or resize the window, the modifications happens when I drop the window.

Do you have any ideas / links / docs ? Thank you :)

© Stack Overflow or respective owner

Related posts about wpf

Related posts about focus