Screen Savers and ShowModal

I have an app that detects when a file if changed on disk and pops up a modal dialog when this occurs asking the user if they want to load the new file.  This works fine until the screen saver kicks in.  If the modal dialog pops up after the screen saver kicks in, then the mouse is moved and the main form repaints, the modal dialog is behind the main form but has the focus.

You can get it back to the front with Alt-Tab, but it is confusing for users, as they don't know the pop-up is there and when they click on the main form they get a beep (as the hidden modal form has focus).  They usually end up killing the task or the machine, even though they don't need to.

I've tried BringToFront anf fsStayOnTop.  How can you force a form to the front when its owner is repainted after a screen save?
 

rossmcmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
You could use a thread that periodically (second or so), forces the modal dialog to the top with ShowWindow...

Cheers,

Raymond.

0
simonetCommented:
You can make the dialog window detect if the screen saver is running before it shows it self. If the screen saver is indeed running, then the dialog closes the SS and shows itself.

You can use SystemParametersInfo for the above.

let me know if this solution works for you and if you need help implementing it. I have some code here (just can't find them now!) that can do what I mentioned above.

Yours,

Alex
0
intheCommented:
Hi all,
you are forgetting the SetForeGroundWindow api which is for this purpose..
just do this when you call the modal dialog:

var
 Modal_dlg_Wnd : HWND;
begin      
 your_modal_form.showmodal;
  Modal_dlg_Wnd := FindWindow(Nil,'Form1');
              {replace 'Form1' with the modal forms caption}
 SetForeGroundWindow(Modal_dlg_Wnd);
end;

this will show your dialog form as the topmost window and if the screensaver is running it will first stop the screensaver.
Regards Barry

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

rossmcmAuthor Commented:
Hey, not quite the solution, it turns out, because the thread doesn't return from the call to ShowModal until the dialog is closed, so the SetForeGroundWindow doesn't get executed yet.  Am I missing somwthing here ?

Ross.  

var
 Modal_dlg_Wnd : HWND;
begin        
 your_modal_form.showmodal;
  Modal_dlg_Wnd := FindWindow(Nil,'Form1');
              {replace 'Form1' with the modal forms caption}
 SetForeGroundWindow(Modal_dlg_Wnd);
end;



0
intheCommented:
Hi
2 possible ideas:
1) just call form.show; {not form.showmodal}
2) as above and set formstyle to bsdialog as well.
try them and see wghat turns out.
Regards Barry
0
rossmcmAuthor Commented:
the form needs to be modal.

I tried adding the SetForegroundWinbdow stuff to the OnShow method instead of after the ShowModal - no change to behaviour.

Ross
0
intheCommented:
what about SetForegroundWindow on a timer event ,that is how i use it anyway..and how the demo in my winapi book uses it.see if that works instead.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.