分配给 Setparent(..) 后 Showmodal 出现问题
我创建了两个应用程序 MainApps 和 SubApps,SubApps 有一个模式类型对话框,例如登录/注销表单等,并且工作正常。
将其附加到 MainApps 后,模态对话框显示为正常的框形式。它的行为类似于“DIALOG.SHOW”而不是“DIALOG.SHOWMODAL”;
我正在使用delphi编译器
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;
主要应用程序按钮单击
begin
setparent(findwindow(nil,'SubApps'),TabSheet1.Handle);
.........
end;
I created two application MainApps and SubApps, the SubApps has a modal type dialogbox such as login/logout form etc. and its working fine.
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";
I am using delphi compiler
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
begin
setparent(findwindow(nil,'SubApps'),TabSheet1.Handle);
.........
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要感到惊讶,你正在尝试的事情充其量只是不寻常。
ShowModal
通过禁用调用线程除模态窗体之外的所有窗口来实现模态效果。由于您的父窗体不属于同一线程,甚至不属于同一进程,因此它不会被禁用。请参阅 forms.pas 中的DisableTaskWindows
以了解调用“ShowModal”时如何禁用表单。您必须设计自己的模态程序;测试应用程序是否在不是桌面的顶级窗口中建立父级,如果是这种情况,请禁用该窗口。
但如果我是你,我会首先考虑设计,如果,fi,你关闭父窗体,你如何结束父窗体的进程?
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.我谦虚地建议你提出一个关于你想要实现的设计建议的问题,例如,如果它是关于代码重用,你可以在 dll 中托管你的 SubApps 表单...这个设计是脆弱,你可能会继续遇到问题......
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. SeeDisableTaskWindows
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.
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.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...
尝试使您的窗口成为“系统模式”而不是“应用程序模式”。事实上,我不知道你是否能做到这一点。这可能是不可能的,或者是一个坏主意。事实上,整个问题给了我一种“坏主意”的味道。
Try making your windows "system modal" instead of "application modal". Actually, I have no idea if you can even do that. It might be impossible, or a bad idea. In fact, the whole question gives me the "bad idea" smell.