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?
c# wpf window pinvoke topmost
add a comment |
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?
c# wpf window pinvoke topmost
add a comment |
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?
c# wpf window pinvoke topmost
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?
c# wpf window pinvoke topmost
c# wpf window pinvoke topmost
edited Nov 22 '18 at 7:56
Hawex
asked Nov 21 '18 at 15:01
HawexHawex
369
369
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try
yourSpecificWindow.Activate();
if that doesnt do the trick, also include
yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it viaProcess.Start()
, so I can't do it this way. Updated my question.
– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414854%2fbring-to-front-inactive-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try
yourSpecificWindow.Activate();
if that doesnt do the trick, also include
yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it viaProcess.Start()
, so I can't do it this way. Updated my question.
– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
|
show 4 more comments
Try
yourSpecificWindow.Activate();
if that doesnt do the trick, also include
yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it viaProcess.Start()
, so I can't do it this way. Updated my question.
– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
|
show 4 more comments
Try
yourSpecificWindow.Activate();
if that doesnt do the trick, also include
yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();
Try
yourSpecificWindow.Activate();
if that doesnt do the trick, also include
yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();
answered Nov 21 '18 at 15:34
mahlatsemahlatse
796517
796517
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it viaProcess.Start()
, so I can't do it this way. Updated my question.
– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
|
show 4 more comments
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it viaProcess.Start()
, so I can't do it this way. Updated my question.
– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it via
Process.Start()
, so I can't do it this way. Updated my question.– Hawex
Nov 22 '18 at 7:53
Thanks for answer, unfortunately I forgot to tell you about one important thing - I'm opening second window is not in the same application, I'm running it via
Process.Start()
, so I can't do it this way. Updated my question.– Hawex
Nov 22 '18 at 7:53
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
Then you you maybe call the second application with commandline arguments are use those to call the above methods?
– mahlatse
Nov 22 '18 at 8:42
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
It's still not working, because Activation of window is blocked.
– Hawex
Nov 23 '18 at 8:03
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
even if you call the other application with commandline parameters?
– mahlatse
Nov 23 '18 at 8:11
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
Just to be clear: when I start second application, it's beign opened on top of screen, everything is fine. After that, when i click on first app, the second is going under it. I'm trying to reactivate it (send again to top) as I said before, but nothing is working. As a workaround for now I'm just closing second app and turning it on again when i need to reactivate it.
– Hawex
Nov 23 '18 at 11:29
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414854%2fbring-to-front-inactive-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown