gpt4 book ai didi

windows - 如何关闭打开的 OLE 对话框

转载 作者:可可西里 更新时间:2023-11-01 10:08:03 27 4
gpt4 key购买 nike

我有一个函数可以关闭应用程序中除主窗体之外的所有窗体

procedure CloseOpenForms(const Component: TComponent);
var
i: Integer;
begin
for i := 0 to pred(Component.ComponentCount) do
begin
CloseOpenForms(Component.Components[i]);

if Component.Components[i] is TForm then
begin
TForm(Component.Components[i]).OnCloseQuery := nil;

TForm(Component.Components[i]).Close;
end;
end;
end;

从主窗体调用:

CloseOpenForms(Self);

只要没有事件的 OLE 对话框(例如 TJvObjectPickerDialog),它就可以正常工作。

如何强制关闭这些非模态 OLE 对话框?

最佳答案

JVCL 将应用程序句柄传递给 IDSObjectPicker.InvokeDialog 的“hwndParent”参数,因此该对话框是拥有(不像 VCL 中的“所有者”,但更像是弹出父级)由应用程序窗口。然后您可以枚举窗口以找出应用程序窗口拥有的窗口并向它们发送关闭命令。

procedure CloseOpenForms(const AComponent: TComponent);

function CloseOwnedWindows(wnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
Result := TRUE;

if (GetWindow(wnd, GW_OWNER) = HWND(lParam)) and (not IsVCLControl(wnd)) then
begin
if not IsWindowEnabled(wnd) then // has a modal dialog of its own
EnumWindows(@CloseOwnedWindows, wnd);

SendMessage(wnd, WM_CLOSE, 0, 0);
end;
end;

procedure CloseOpenFormsRecursive(const RecComponent: TComponent);
var
i: Integer;
begin
for i := 0 to pred(RecComponent.ComponentCount) do
begin
CloseOpenFormsRecursive(RecComponent.Components[i]);

if RecComponent.Components[i] is TForm then
begin
TForm(RecComponent.Components[i]).OnCloseQuery := nil;

TForm(RecComponent.Components[i]).Close;
end;
end;
end;

begin
EnumWindows(@CloseOwnedWindows, Application.Handle);

CloseOpenFormsRecursive(AComponent)
end;

关于windows - 如何关闭打开的 OLE 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10294392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com