Results 1 to 7 of 7

Thread: Windows focus / Windows Shutdown Problems

  1. #1
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Windows focus / Windows Shutdown Problems

    Hi All,

    I am have 2 annoying problems with the Windows version of my program. I mostly use Linux and neither of these occur there, so I'm hoping someone who uses Windows a lot might be able to help.

    1) My program runs mostly in the icon tray, and uses a pop-up to alert users when they have new messages. The popup is a QDialog with the following in the constructor:

    setWindowFlags( Qt:: Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint );

    This works great on Linux, but on Windows causes the pop-up to steal focus. I have tried playing with just about every windows flag I can find, but there seems to be no way for a widget to be On Top in Windows but not steal focus when it first appears with QT, although I have seen it done with GTK and Visual C++. Any ideas?

    2) I modified the TrayIcon example so that my program minimized instead of shutting down when someone clicks the close button. To exit the program the Tray-icon Context menu is used.

    The problem is that on Windows, if the App is open (And the main window showing) and you shutdown or restart Windows, the program is minimized, and windows halts it's shutdown.

    Is there any way to detect if the close came from outside the program or from a user clicking the close button?

    Thanks loads
    Last edited by December; 21st October 2007 at 08:13.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    1. What window flags are set in the examples you've seen?

    2. Override winEvent and look for the WM_QUERYENDSESSION. More details on http://msdn2.microsoft.com/en-us/library/aa376890.aspx. You should set the result param of winEvent to a non-zero value, so the shut-down/restart won't halt. When you catch this event you should also close your app.

  3. The following user says thank you to marcel for this useful post:

    December (22nd October 2007)

  4. #3
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    I am trying to use the winEvent, but every time I try to do anything with the message, I get this error:

    error: invalid use of undefined type 'struct tagMSG'

    Which headers should that be defined in?

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    Try
    Qt Code:
    1. #include <qt_windows.h>
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to marcel for this useful post:

    December (22nd October 2007)

  7. #5
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    That doesn't exist on Linux, so explains why I never found it. Will check my windows install when I get home.

    As for the Focus stealing problem, never actually seen any source from programs that manage ok, but look at MSN messenger, that has popups that don't steal focus.. I just wish I knew how!

  8. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    That doesn't exist on Linux, so explains why I never found it. Will check my windows install when I get home.
    You asked for a Windows solution.

    As for the Focus stealing problem, never actually seen any source from programs that manage ok, but look at MSN messenger, that has popups that don't steal focus.. I just wish I knew how!
    Try searching codeproject.com, maybe you find something there. Still, you can find a Windows-only solution there.

  9. #7
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Windows focus / Windows Shutdown Problems

    Quote Originally Posted by marcel View Post
    You asked for a Windows solution.
    Yes I did, and thanks for helping me find the correct include. I was just saying that the reason I hadn't found it initially (and I did search a fair bit) was because it doesn't exist on the Linux install, I really should have also looked on Windows!

Similar Threads

  1. Replies: 2
    Last Post: 24th July 2006, 19:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.