|
Hello,
I've been trying to solve that problem for some time now and I'll be very grateful to anyone who can suggest a solution. The problem is a little tricky but I hope I'll be able to explain it clearly.
I have an application which might need to notify the user of an event even if it's not focused at the moment or is minimized. Think of something along the lines of an app that copies files for 5-6 minutes and needs to say 'Your files were copied' at the end, but the user has switched to writing emails in the meantime. I don't want to grab the keyboard focus because he might be doing something like writing in notepad in which case he'll be randomly pressing hotkeys on my dialog instead of writing to notepad. But I can't figure out how to do this properly.
Right now I use this code (from my main dialog class):
SetForegroundWindow();
By calling SetForegroundWindow() my dialog comes to the foreground (or flashes - but I don't know how Windows decides which of the two) and sometimes will steal focus which I don't want, but there are many problems if my dialog is also minimized. In this case the taskbar icon of my dialog will seem to become active on the taskbar, but my dialog won't show itself (it'll remain minimized but receive keyboard focus it seems). If I uncomment the other two lines, then it solves all problems with minimizing as it first unminimizes the dialog, but it _always_ steals focus which I don't want.
My second problem with the main dialog being minimized is I also create a dialog containing some information about the event and I display it with DoModal, and if I call DoModal while the main window was minimized, when the user switches to my program the new dialog created with DoModal is shown but the main dialog is not. Any way to fix that?
So it's all very complicated and I'm not sure how it's supposed to be implemented. Again, all I want is to notify the user without stealing keyboard focus, even if my dialog is minimized at the time. Do I unminimize my dialog? How do I prevent it from stealing focus then?
Any help will be greatly appreciated!
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Instead of SetForegroundWindow, why not install a system nofitication icon[^] while your dialog is doesn't have focus. Then you can display a balloon tip[^] when you want to tell the user that you're done.
There are several Code Project articles on the subject here[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply, this is interesting. I didn't think of doing that, but it'll certainly solve the problem.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I'm thinking of displaying an icon on the tray, and when the operation is done a balloon tooltip emerges and notifies the user. Optionally when the user clicks on it the focus is switched to my app.
The documentation seems a bit complicated, especially about which flags need to be used in the uFlags field of NOTIFYICONDATA. I see I need NIF_ICON and NIF_INFO for balloons, but do I need NIF_TIP also? Can you help me by telling me which flags do I need to set?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|