How can I make a form that is not disabled when another form is shown modally?

梦想的初衷 提交于 2019-11-29 03:23:06

问题


I have a utility dialog (non-modal and stay-on-top) that should be accessible at all times when using the application (think of a dialog that can be used to take notes while working with the application) even if a modal dialog is displayed.

The rest of the application cannot be changed.

Is it possible? How could I go about it?


回答1:


When ShowModal is called, all existing top level windows are disabled. That's how modality is meant to work. If you have a window with which interaction is reasonable, you just need to enable it again.

For example, you could add this to your utility window:

type
  TMyUtilityForm = class(TForm)
  protected
    procedure WMEnable(var Message: TWMEnable); message WM_ENABLE;
  end;
....
procedure TMyUtilityForm.WMEnable(var Message: TWMEnable);
begin
  if not Message.Enabled then
    EnableWindow(Handle, True);
  inherited;
end;

This will make sure that your utility window can never be disabled.



来源:https://stackoverflow.com/questions/12953225/how-can-i-make-a-form-that-is-not-disabled-when-another-form-is-shown-modally

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