Hawex
Hawex

Reputation: 133

Bring to front inactive window

I've got two WPF applications. Both of them has a window with Topmost property set to true. Window of first application is a full-screen window and second app takes only part of the screen. The important thing is also that, the second application can't be activated (activation was blocked by following code):

private const int GWL_EXSTYLE = -20;
private const int WS_EX_NOACTIVATE = 0x08000000;

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

protected override void OnSourceInitialized(EventArgs e)
{
    WindowInteropHelper helper = new WindowInteropHelper(window);
    SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
}

I'm trying to bring to front second application, when user click on button which is placed on first application. I tried to achieve this by using SetForegroundWindow and ShowWindow, but it's not working. Do someone have any solution for this problem?

Upvotes: 0

Views: 381

Answers (1)

mahlatse
mahlatse

Reputation: 1307

Try

yourSpecificWindow.Activate();

if that doesnt do the trick, also include

yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();

Upvotes: 1

Related Questions