分配给Setparent(..)后,Showmodal的问题 [英] Problems in Showmodal after assigning to Setparent(..)

查看:516
本文介绍了分配给Setparent(..)后,Showmodal的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个应用程序MainApps和SubApps,SubApps有一个模态类型的对话框,如登录/注销表单等,它的工作正常。

I created two application MainApps and SubApps, the SubApps has a modal type dialogbox such as login/logout form etc. and its working fine.

附加后对于MainApps,Modal对话框显示为正常的盒子形式。它的行为类似于DIALOG.SHOW而不是DIALOG.SHOWMODAL;

After I attach it to the MainApps, the Modal Dialog box shows like normal box form. It behaves like "DIALOG.SHOW" instead of "DIALOG.SHOWMODAL";

我使用的是delphi编译器

I am using delphi compiler

SubApps buttonclick;

SubApps buttonclick;

  begin
    with TfrmDialog.Create(Self, dtLogout) do
    try
      iMsgResult := ShowModal;
    finally
      Free;
    end;
    if iMsgResult = mrOk then
    begin
      dmVoca.FHomeworkXMLDoc.Active := False;
      //Disabled Double Login
      dmVoca.tmrDoubleLogin.Enabled := False;
      ................
    end;  
  end;

MainApps ButtonClick

MainApps ButtonClick

begin
setparent(findwindow(nil,'SubApps'),TabSheet1.Handle);
.........
end;


推荐答案

不要惊讶,你在做什么最不寻常的 ShowModal 通过禁用调用线程的所有窗口但是模态窗体来实现模态效果。由于您的父表单不属于同一个线程,甚至不属于同一个进程,因此不会被禁用。请参阅forms.pas中的 DisableTaskWindows 来了解如何在调用ShowModal时禁用表单。

Don't be surprised, what you are trying is unusual at best. ShowModal achieves the modal effect by disabling all the windows of the calling thread but the modal form. Since your parent form do not belong to the same thread, not even to the same process, it does not get disabled. See DisableTaskWindows in forms.pas to understand how the forms are disabled when 'ShowModal' is called.

你必须设计自己的模态程序;测试应用程序是否在不是桌面的顶级窗口中处于父级状态,如果是这样,请禁用该窗口。

You have to devise your own modal procedure; test if the application is parented in a top level window that's not the desktop, disable that window if that's the case.

但是,如果我是在设计中首先,如果你关闭父母表单,你如何结束父母表单的过程?



编辑:以下第三条评论 - 您可能会尝试通过MainApps表单拥有模态表单。类似于表单由应用程序主窗体拥有,而 MainFormOnTaskbar 为true。请参阅拥有的窗口 href =http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx =nofollow noreferrer>窗口功能主题msdn。

But if I were you I would think on the design first, what if, f.i., you close the parent form, how do you end the parented form's process?


edit: for 3rd comment below - you might try having the modal form "owned" by the MainApps's form. Similiar to forms being owned by the application main form while MainFormOnTaskbar is true. See owned windows on Window Features topic of msdn.

var
  frmDialog: TfrmDialog;
begin
  [...]
  frmDialog := TfrmDialog.Create(Self, dtLogout);
  try
    SetWindowLong(frmDialog.Handle, GWL_HWNDPARENT, GetAncestor(Handle, GA_ROOT));
    iMsgResult := frmDialog.ShowModal;
    [...]


我谦虚地建议你提出一个关于您想要实现的设计的建议的问题,例如,如果它是关于代码重用,您可以托管您的SubApps表单在一个dll ...这种设计是脆弱的,你可能会继续遇到问题与... ...


I'd humbly suggest you to ask a question on a suggestion of a design for what you want to achieve, for instance, if it is about code reuse you could host your SubApps forms in a dll... This design is fragile, you may continue to run into problems with it...

这篇关于分配给Setparent(..)后,Showmodal的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆