[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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?
 

0
rossmcm
Asked:
rossmcm
1 Solution
 
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now