Delphi - detecting if my app has a modal dialog open

微笑、不失礼 提交于 2019-12-22 10:05:00

问题


I have a Delphi 2006 app that pops up a modal alert dialog when an error condition is detected. As the check for the error condition is done in an idle handler, the dialog can pop up over the top of another modal dialog if that one happens to be displayed. This can lead to a confusing situation for the user where the application main form doesn't get focus after the alert dialog is closed because these is another obscured modal dialog.

What I would like to do is postpone the alert popups while the app has any Modal dialogs open.

I tried GetLastActivePopup (MyMainWindow.Handle) but it seems to return non-zero all the time.


回答1:


See TApplication.ModalLevel or the TApplication.OnModalBegin and TApplication.OnModalEnd events. Also see this question.




回答2:


Just test

if not IsWindowEnabled(MyMainWindow.Handle) then

This would also take care of situtations when a non-Delphi dialog is acting modal, like in windows.MessageBox(Handle.... or a common dialog is showing (i.e. a TOpenDialog).




回答3:


use AnyPopup() function

About GetLastActivePopup(). It may return value is the same as the hWnd parameter when

  • The window identified by hWnd was most recently active.
  • The window identified by hWnd does not own any pop-up windows.
  • The window identifies by hWnd is not a top-level window, or it is owned by another window.


来源:https://stackoverflow.com/questions/3306260/delphi-detecting-if-my-app-has-a-modal-dialog-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!