Results 1 to 18 of 18

Thread: How to raise application from background?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to raise application from background?

    Quote Originally Posted by stampede View Post
    Be careful, in this case this is danger close to "I know what is good for my user". IMHO there is nothing more annoying than application that pops at you out of nowhere, so this time I can agree with Microsoft, simple taskbar notification is less intrusive.
    I agree with you with nothing more annoying than an application popping up out of nowhere, but here this is done in case there is already an instance of the application running and the user starting a second instance of that application. In such a case, I want to the first instance to be shown to the user and the second instance closed. In this particular case, I think it's completely fine to go against the default Windows' behaviour.

    Otherwise, about "I know what is good for my user"... well, though my application is going to be used by many people, I will also happen to be one of those people. So, it's not, here, a matter of the programmer not being a user and, yet, thinking s/he knows better than the user. Also, I have done the above in the previous version of my application (which is written in Delphi and therefore only runs on Windows, hence my switching to Qt to have it cross-platform).

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to raise application from background?

    So, it's not, here, a matter of the programmer not being a user and, yet, thinking s/he knows better than the user.
    As you've said, you are one of many users, and it's impossible to know what is the best for all of them. If I were using your app, I'd prefer notification in taskbar (yes, I'm the client from hell )
    I can accept raise from background if I explicitly click on the icon in explorer (or start via cmd), but only then. If an application steals the focus without my clear permission, then well ... /dev/null awaits
    Sorry for little off topic btw.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to raise application from background?

    Isn't that what agarny is doing? The application is only popping up if you double click the application on your desktop (or start bar, or wherever).

    What he didn't want is double clicking the icon and the previous instance just flashing on the task bar. To me, that would be unacceptable. If I'm clicking the icon, I want the application to be in the foreground and not wink at me.

  4. #4
    Join Date
    Dec 2010
    Posts
    28
    Thanks
    6
    Thanked 10 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: How to raise application from background?

    Ok! I find the working solution for this problem. I describe this in the case somebody want do it.

    First of all there is mentioned article: http://blogs.msdn.com/b/oldnewthing/...0/9435239.aspx. It describes Microsoft point of view. There are two ways to solve this problem: use SetForegroundWindow in second runing process, or use AllowSetForegroundWindow in second runing proces in couple with SetForegroundWindow in first proces. I choose the latter variant because it does not mess in my project. So I do following steps:

    1. In first process (Proc1) open local socket and listen on it.
    2. In second process (Proc2) connect to the local socket Proc1.
    3. In Proc1 write to socket the proces ID.
    4. In Proc2 read proces ID and call AllowSetForegroundWindow.
    5. In Proc2 write list of file names that should be opened in Proc1.
    6. In Proc1 open each file and call SetForegroundWindow.

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to raise application from background?

    @squidge: You are right, I should read the topic more carefully. I was thinking about programmatically raising up from background in general whole time. My bad.

  6. #6
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to raise application from background?

    Quote Originally Posted by stampede View Post
    As you've said, you are one of many users, and it's impossible to know what is the best for all of them. If I were using your app, I'd prefer notification in taskbar (yes, I'm the client from hell )
    I can accept raise from background if I explicitly click on the icon in explorer (or start via cmd), but only then. If an application steals the focus without my clear permission, then well ... /dev/null awaits
    Sorry for little off topic btw.
    Well... this is exactly the situation we are talking about here. I mean, having the user explicitly clicking the icon in explorer or start the application from the command line...

  7. #7
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to raise application from background?

    The first solution code provided by agarny is working fine for me, Thanks to agarny for your solution.

Similar Threads

  1. Background image in an application
    By halvors in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2010, 11:27
  2. How to set background of application??
    By kamlesh.sangani in forum Newbie
    Replies: 21
    Last Post: 9th July 2009, 12:12
  3. widget raise!
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2009, 07:10
  4. Run application in background
    By raulftang in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 24th April 2007, 09:29
  5. Background QT application.
    By Thrantor in forum Qt Programming
    Replies: 4
    Last Post: 12th September 2006, 22:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.