Bring to front inactive window












-1














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?










share|improve this question





























    -1














    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?










    share|improve this question



























      -1












      -1








      -1







      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 7:56







      Hawex

















      asked Nov 21 '18 at 15:01









      HawexHawex

      369




      369
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Try



          yourSpecificWindow.Activate();


          if that doesnt do the trick, also include



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





          share|improve this answer





















          • 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










          • 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













          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          Try



          yourSpecificWindow.Activate();


          if that doesnt do the trick, also include



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





          share|improve this answer





















          • 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










          • 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


















          1














          Try



          yourSpecificWindow.Activate();


          if that doesnt do the trick, also include



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





          share|improve this answer





















          • 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










          • 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
















          1












          1








          1






          Try



          yourSpecificWindow.Activate();


          if that doesnt do the trick, also include



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





          share|improve this answer












          Try



          yourSpecificWindow.Activate();


          if that doesnt do the trick, also include



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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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










          • 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










          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          To store a contact into the json file from server.js file using a class in NodeJS

          Marschland

          Redirect URL with Chrome Remote Debugging Android Devices