Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. In which cases SetForegroundWindow return false

In which cases SetForegroundWindow return false

Scheduled Pinned Locked Moved C#
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bil l
    wrote on last edited by
    #1

    Hi, I need to know when SetForegroundWindow return false because i try to set a form to the front using this code :

       form.TopMost = true;
            form.BringToFront(); 
            bool focused = SetForegroundWindow(form.Handle);
            if (!focused)
                SwitchToThisWindow(form.Handle, true);
            form.TopMost = false;
    

    the form is showen but without having the focus. best regards.

    Keep it simple, stupid!

    0 L L 3 Replies Last reply
    0
    • B Bil l

      Hi, I need to know when SetForegroundWindow return false because i try to set a form to the front using this code :

         form.TopMost = true;
              form.BringToFront(); 
              bool focused = SetForegroundWindow(form.Handle);
              if (!focused)
                  SwitchToThisWindow(form.Handle, true);
              form.TopMost = false;
      

      the form is showen but without having the focus. best regards.

      Keep it simple, stupid!

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      IIRC, SetForegroundWindow returns false if the window is not brought to the foreground. In your case, perhaps it's because your form is already at the foreground.

      Between the motion And the act Falls the Shadow

      1 Reply Last reply
      0
      • B Bil l

        Hi, I need to know when SetForegroundWindow return false because i try to set a form to the front using this code :

           form.TopMost = true;
                form.BringToFront(); 
                bool focused = SetForegroundWindow(form.Handle);
                if (!focused)
                    SwitchToThisWindow(form.Handle, true);
                form.TopMost = false;
        

        the form is showen but without having the focus. best regards.

        Keep it simple, stupid!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        If only there would be some official documentation that holds such trivial information. Googling for it would have taken half the keystrokes and less than 1 minute. We prefer to help with real questions around here. :doh:

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        1 Reply Last reply
        0
        • B Bil l

          Hi, I need to know when SetForegroundWindow return false because i try to set a form to the front using this code :

             form.TopMost = true;
                  form.BringToFront(); 
                  bool focused = SetForegroundWindow(form.Handle);
                  if (!focused)
                      SwitchToThisWindow(form.Handle, true);
                  form.TopMost = false;
          

          the form is showen but without having the focus. best regards.

          Keep it simple, stupid!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can also prevent other applications from stealing the focus, using TweakUI :) <rant> It's bloody annoying; you're typing merrily away, and suddenly start hearing the bleeping-sound of the computer-speaker because some programmer assumed that his application is important enough to disturb me during my work.

          "Updates are available? Do you want to install/download them now?"

          If you must steal focus, then steal the entire screen and blink it red. It's either really important, or you behave and don't bug me at all. </rant>

          I are Troll :)

          L 1 Reply Last reply
          0
          • L Lost User

            You can also prevent other applications from stealing the focus, using TweakUI :) <rant> It's bloody annoying; you're typing merrily away, and suddenly start hearing the bleeping-sound of the computer-speaker because some programmer assumed that his application is important enough to disturb me during my work.

            "Updates are available? Do you want to install/download them now?"

            If you must steal focus, then steal the entire screen and blink it red. It's either really important, or you behave and don't bug me at all. </rant>

            I are Troll :)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Some automation jobs may require SetForegroundWindow in order to use keyboard/mouse actions on another app. Of course this would require: 1. A user requesting it 2. A warning window telling the user he shouldn't touch anything until told otherwise. 3. The automation stuff 4. A notification to the user all is over. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups