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 / C++ / MFC
  4. Foreground process

Foreground process

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
18 Posts 7 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.
  • K KKumarTG

    How to make a process foreground. Krishnakumar

    stefanmihaimogaS Offline
    stefanmihaimogaS Offline
    stefanmihaimoga
    wrote on last edited by
    #2

    Please have a look on CreateThread[^] function. Some good examples you can found on http://www.codeproject.com/threads/[^]

    1 Reply Last reply
    0
    • K KKumarTG

      How to make a process foreground. Krishnakumar

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #3

      What do you mean by "foreground process?" Windows does not have the concept of foreground/background processes. This is a concept from platforms such as Unix.


      "The largest fire starts but with the smallest spark." - David Crow

      S 1 Reply Last reply
      0
      • D David Crow

        What do you mean by "foreground process?" Windows does not have the concept of foreground/background processes. This is a concept from platforms such as Unix.


        "The largest fire starts but with the smallest spark." - David Crow

        S Offline
        S Offline
        Sebastian Schneider
        wrote on last edited by
        #4

        It does. Just not exactly in the *nix sense. @Topic Basically, if you start a program - either under Unix or Windows - its a foreground-process. Its the background-processes which need special consideration. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

        D N 2 Replies Last reply
        0
        • S Sebastian Schneider

          It does. Just not exactly in the *nix sense. @Topic Basically, if you start a program - either under Unix or Windows - its a foreground-process. Its the background-processes which need special consideration. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #5

          Sebastian Schneider wrote:

          Its the background-processes which need special consideration.

          Windows does not have "background processes." Please explain what you are referring to.


          "The largest fire starts but with the smallest spark." - David Crow

          K J S 3 Replies Last reply
          0
          • D David Crow

            Sebastian Schneider wrote:

            Its the background-processes which need special consideration.

            Windows does not have "background processes." Please explain what you are referring to.


            "The largest fire starts but with the smallest spark." - David Crow

            K Offline
            K Offline
            KKumarTG
            wrote on last edited by
            #6

            My problem is that, I want to make a window active ( foreground ). When i do this, the window icon in the taskbar is flashing. Not getting exact focus. (Used function 'SetForegroundWindow()') Please comment Krishnakumar

            D 1 Reply Last reply
            0
            • K KKumarTG

              My problem is that, I want to make a window active ( foreground ). When i do this, the window icon in the taskbar is flashing. Not getting exact focus. (Used function 'SetForegroundWindow()') Please comment Krishnakumar

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              This behavior is by design (for Windows 2000). Instead of bringing the window to the front, it simply calls FlashWindow(). As a workaround, try:

              if (GetForegroundWindow() != hWnd)
              {
              DWORD dwThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
              DWORD dwThreadID2 = GetWindowThreadProcessId(hWnd, NULL);

              if (dwThreadID1 != dwThreadID2)
              {
                   AttachThreadInput(dwThreadID1, dwThreadID2, TRUE);
                   SetForegroundWindow(hWnd);
                   AttachThreadInput(dwThreadID1, dwThreadID2, FALSE);
              }
              else
                   SetForegroundWindow(hWnd);
              
              if (IsIconic(hWnd))
                  ShowWindow(hWnd, SW\_RESTORE);
              else
                  ShowWindow(hWnd, SW\_SHOW);
              

              }


              "The largest fire starts but with the smallest spark." - David Crow

              K 1 Reply Last reply
              0
              • D David Crow

                Sebastian Schneider wrote:

                Its the background-processes which need special consideration.

                Windows does not have "background processes." Please explain what you are referring to.


                "The largest fire starts but with the smallest spark." - David Crow

                J Offline
                J Offline
                James R Twine
                wrote on last edited by
                #8

                Would a Win32 Service be considered a type of "background process" (quotes intentional), akin to dæmons (demons) in *nix?    Peace! -=- James


                If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                DeleteFXPFiles & CheckFavorites (Please rate this post!)

                N 1 Reply Last reply
                0
                • J James R Twine

                  Would a Win32 Service be considered a type of "background process" (quotes intentional), akin to dæmons (demons) in *nix?    Peace! -=- James


                  If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  DeleteFXPFiles & CheckFavorites (Please rate this post!)

                  N Offline
                  N Offline
                  Nemanja Trifunovic
                  wrote on last edited by
                  #9

                  Win32 services are similar to Unix daemons, but it is not the same concept as "background processes"


                  My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it. -- modified at 10:55 Friday 2nd June, 2006

                  1 Reply Last reply
                  0
                  • S Sebastian Schneider

                    It does. Just not exactly in the *nix sense. @Topic Basically, if you start a program - either under Unix or Windows - its a foreground-process. Its the background-processes which need special consideration. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                    N Offline
                    N Offline
                    Nemanja Trifunovic
                    wrote on last edited by
                    #10

                    Sebastian Schneider wrote:

                    Just not exactly in the *nix sense.

                    What do you mean by that?


                    My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                    S 1 Reply Last reply
                    0
                    • D David Crow

                      Sebastian Schneider wrote:

                      Its the background-processes which need special consideration.

                      Windows does not have "background processes." Please explain what you are referring to.


                      "The largest fire starts but with the smallest spark." - David Crow

                      S Offline
                      S Offline
                      Sebastian Schneider
                      wrote on last edited by
                      #11

                      I just checked: Windows allows you to optimize your computer for "Application" or "Background Services" (German Windows XP Pro). Ill admit that services are more likely the "Windows version" of "system daemons". But, well, if you are not using an applications windows, it will literally be "behind" another application. You are unable to use that application until you click its windows and thus "bring it to the front". And that is just what background processes under *nix are like: You specifically put them in the back to use another application and be able to return to them later on without restarting them from scratch. I admit that "foreground processes" and active windows / "background processes" and inactive windows do not follow the exact same definitions under *nix and Windows, but they are similar enough to use the term". Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                      Z 1 Reply Last reply
                      0
                      • N Nemanja Trifunovic

                        Sebastian Schneider wrote:

                        Just not exactly in the *nix sense.

                        What do you mean by that?


                        My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                        S Offline
                        S Offline
                        Sebastian Schneider
                        wrote on last edited by
                        #12

                        See my previous post. I consider this to be a "religious issue", so you might want to not reply to that. I am probably gonna be ripped apart soon... ;) Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                        1 Reply Last reply
                        0
                        • D David Crow

                          This behavior is by design (for Windows 2000). Instead of bringing the window to the front, it simply calls FlashWindow(). As a workaround, try:

                          if (GetForegroundWindow() != hWnd)
                          {
                          DWORD dwThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
                          DWORD dwThreadID2 = GetWindowThreadProcessId(hWnd, NULL);

                          if (dwThreadID1 != dwThreadID2)
                          {
                               AttachThreadInput(dwThreadID1, dwThreadID2, TRUE);
                               SetForegroundWindow(hWnd);
                               AttachThreadInput(dwThreadID1, dwThreadID2, FALSE);
                          }
                          else
                               SetForegroundWindow(hWnd);
                          
                          if (IsIconic(hWnd))
                              ShowWindow(hWnd, SW\_RESTORE);
                          else
                              ShowWindow(hWnd, SW\_SHOW);
                          

                          }


                          "The largest fire starts but with the smallest spark." - David Crow

                          K Offline
                          K Offline
                          KKumarTG
                          wrote on last edited by
                          #13

                          I tried. But now also the window (in tastbar icon) is flashing ( not getting the focus ). :( Krishnakumar

                          D 1 Reply Last reply
                          0
                          • S Sebastian Schneider

                            I just checked: Windows allows you to optimize your computer for "Application" or "Background Services" (German Windows XP Pro). Ill admit that services are more likely the "Windows version" of "system daemons". But, well, if you are not using an applications windows, it will literally be "behind" another application. You are unable to use that application until you click its windows and thus "bring it to the front". And that is just what background processes under *nix are like: You specifically put them in the back to use another application and be able to return to them later on without restarting them from scratch. I admit that "foreground processes" and active windows / "background processes" and inactive windows do not follow the exact same definitions under *nix and Windows, but they are similar enough to use the term". Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                            Z Offline
                            Z Offline
                            Zac Howland
                            wrote on last edited by
                            #14

                            There are subtle differences between an application that does not have the focus in Windows (which you are equating to "background") and actually backgrounding an application in a *nix system. In Windows, you cannot pause an application that was started on the command line and then tell it to resume in the background (that is, without control of stdout). On top of that, you cannot tell the very same application that you want to have it resume control of the console (stdout). Effectively, all processes in Windows are background applications. That is, when you double click their icon to start them up, they don't have a stdout. When you do start an app from the command line (assuming it is a GUI), it doesn't have a stdout by default (though, you can jump through some hoops to give it one). The concept of "foreground" is different in Windows as well. The foreground application in Windows is whatever application has the current focus. This isn't the case in *nix systems, where you can have as many foreground applications as you have consoles open for. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                            S 1 Reply Last reply
                            0
                            • Z Zac Howland

                              There are subtle differences between an application that does not have the focus in Windows (which you are equating to "background") and actually backgrounding an application in a *nix system. In Windows, you cannot pause an application that was started on the command line and then tell it to resume in the background (that is, without control of stdout). On top of that, you cannot tell the very same application that you want to have it resume control of the console (stdout). Effectively, all processes in Windows are background applications. That is, when you double click their icon to start them up, they don't have a stdout. When you do start an app from the command line (assuming it is a GUI), it doesn't have a stdout by default (though, you can jump through some hoops to give it one). The concept of "foreground" is different in Windows as well. The foreground application in Windows is whatever application has the current focus. This isn't the case in *nix systems, where you can have as many foreground applications as you have consoles open for. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                              S Offline
                              S Offline
                              Sebastian Schneider
                              wrote on last edited by
                              #15

                              I know. However, this just refers to the ability to easily put an application into the background or pull it into the foreground. However, there are application which do not have a visible Window, namely the "iconified" programs (such as ZoneAlarm, QuickTime Helper, ATI Catalyst Control Center, Antivirus SW, etc.) - and not all of those are service-GUIs. This really is more like a religious thing, so I will stop now. Basically, I'd even say that EVERY program you are not using is a background process - just because there is only a single input-focus, and thus, only one application is active - or "in the foreground". I am not claiming that Windows can do everything Linux can - or vice versa. I am just saying that "foreground", "background" and "process" are not Linux-specific concepts. Just that the implementations vary. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                              Z 1 Reply Last reply
                              0
                              • S Sebastian Schneider

                                I know. However, this just refers to the ability to easily put an application into the background or pull it into the foreground. However, there are application which do not have a visible Window, namely the "iconified" programs (such as ZoneAlarm, QuickTime Helper, ATI Catalyst Control Center, Antivirus SW, etc.) - and not all of those are service-GUIs. This really is more like a religious thing, so I will stop now. Basically, I'd even say that EVERY program you are not using is a background process - just because there is only a single input-focus, and thus, only one application is active - or "in the foreground". I am not claiming that Windows can do everything Linux can - or vice versa. I am just saying that "foreground", "background" and "process" are not Linux-specific concepts. Just that the implementations vary. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                                Z Offline
                                Z Offline
                                Zac Howland
                                wrote on last edited by
                                #16

                                I didn't mean to imply that I was debating you. I understand what you were getting at. I was simply stating that the 2 OS's define these terms (and hence the implementation of those features) differently. When going between systems, it is important to note the differences. You will run into areas where they are not synonomous quite often in low level coding, but if you just view it from a high level point of view, you can ignore those differences. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                                S 1 Reply Last reply
                                0
                                • K KKumarTG

                                  I tried. But now also the window (in tastbar icon) is flashing ( not getting the focus ). :( Krishnakumar

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #17

                                  What if you do the following prior to calling SetForegroundWindow():

                                  SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);


                                  "The largest fire starts but with the smallest spark." - David Crow

                                  1 Reply Last reply
                                  0
                                  • Z Zac Howland

                                    I didn't mean to imply that I was debating you. I understand what you were getting at. I was simply stating that the 2 OS's define these terms (and hence the implementation of those features) differently. When going between systems, it is important to note the differences. You will run into areas where they are not synonomous quite often in low level coding, but if you just view it from a high level point of view, you can ignore those differences. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                                    S Offline
                                    S Offline
                                    Sebastian Schneider
                                    wrote on last edited by
                                    #18

                                    Me neither. I just thought I had made an ambigious statement and wanted to clarify. I am not a native speaker, and I am really careful not to set people off just because my statements could be misunderstood (because, if they can, they will be ;) ). Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                                    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