tags:

views:

153

answers:

1

We have a C# application which contains both modal and non-modal windows. It is possible for a user to have several non-modal windows open and open a modal window from one of these.

If the user switches to another application and then switches back to ours by clicking one of the non-modal windows (other than the one which opened the modal window) in the Task Bar, the non-modal window becomes activated but does not accept input because the modal window is open, but is behind other windows.

How can we ensure that no matter which of our windows the user switches back to, the one which is modal is the one which is actually activated? This is the behaviour exhibited by Microsoft Outlook, for example.

Any assistance would be appreciated.

+1  A: 

Its certainly possible, but is really annoying to maintain. I regularly work on an application which mixes modal and non-modal windows. This is my strategy (which isn't 100% full-proof)

  1. Set the modal windows TOPMOST when possible.
  2. When certain actions are detected (like pressing windows-d button), you have to manually set the window back to topmost. I dont know why the windows go to the back, but the behavior is not consistent between windows XP, vista, 2003, etc.

Its really annoying maintaining the code that rearranges the windows. I would urge you to try to not mix modal and non-modal windows.

Edit

I forgot to mention that i use WTL and alot of native win32 functions. I also try to create windows which have parent / child relationship so that keyboard and mouse messages get REFLECTED as much as possible to the child windows.

Andrew Keith
I can understand your pain :P
o.k.w
Thank you for your response.I have added some code to intercept the WM_ACTIVATEAPP window message as described in the example on MSDN for the NativeWindow class and to activate the topmost modal window when this occurs, which seems to produce the desired behaviour.Do you have any thoughts on this approach?
Rob_TT