PDA

View Full Version : Windows focus / Windows Shutdown Problems



December
21st October 2007, 08:05
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

marcel
21st October 2007, 08:57
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.

December
21st October 2007, 13:02
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?

marcel
21st October 2007, 14:38
Try


#include <qt_windows.h>

December
22nd October 2007, 07:48
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!

marcel
22nd October 2007, 07:58
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.

December
22nd October 2007, 15:10
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!