Wnd := GetLastActivePopup(Application.Handle);
if (Wnd <> 0) and (Wnd <> Application.Handle) then
PostMessage(Wnd, wm_close,0,0);
但是,它会关闭所有打开的对话框.当我尝试指定特定表单时,例如:
if (Wnd <> 0) and (Wnd <> FormTest.Handle) then
它会引发访问冲突错误.
如何确定是否正在弹出特定单元的对话框?
有一个简单的解决方案可行.
你可以使用:
procedure TForm1.Button2Click(Sender: TObject);
var
h: hwnd;
begin
h := FindWindow(PChar('TForm1'), PChar('Form1'));
if h <> 0 then
PostMessage(h, WM_CLOSE, 0,0);
end;
Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
要搜索子窗口,请使用以下功能:
FindWindowEx function:
Retrieves a handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the specified child window. This function does not perform a case-sensitive search.
Wnd := GetLastActivePopup(Application.Handle);
if (Wnd <> 0) and (Wnd <> Application.Handle) then
PostMessage(Wnd, wm_close,0,0);
但是,它会关闭所有打开的对话框.当我尝试指定特定表单时,例如:
if (Wnd <> 0) and (Wnd <> FormTest.Handle) then
它会引发访问冲突错误.
如何确定是否正在弹出特定单元的对话框?
有一个简单的解决方案可行.
你可以使用:
procedure TForm1.Button2Click(Sender: TObject);
var
h: hwnd;
begin
h := FindWindow(PChar('TForm1'), PChar('Form1'));
if h <> 0 then
PostMessage(h, WM_CLOSE, 0,0);
end;
Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
要搜索子窗口,请使用以下功能:
FindWindowEx function:
Retrieves a handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the specified child window. This function does not perform a case-sensitive search.