얘들 아, 모든 MDI 양식을 닫았을 때 누군가가 가로 챌 수있는 이벤트 나 방법을 아는 사람이 있다면 알려주고 싶습니다.모든 MDI 양식을 닫을 때의 이벤트
예 :
내가 모든 MDI 폼을 닫을 때, 이러한 이벤트가 트리거 된 곳 내 주요 형태의 이벤트를 구현하려는.
누구든지 도움을 주시면 감사하겠습니다.
얘들 아, 모든 MDI 양식을 닫았을 때 누군가가 가로 챌 수있는 이벤트 나 방법을 아는 사람이 있다면 알려주고 싶습니다.모든 MDI 양식을 닫을 때의 이벤트
예 :
내가 모든 MDI 폼을 닫을 때, 이러한 이벤트가 트리거 된 곳 내 주요 형태의 이벤트를 구현하려는.
누구든지 도움을 주시면 감사하겠습니다.
MDI 하위 폼 (사실상 어떤 폼이든)은 파괴되는 동안 주 폼에 알립니다. 이 알림 메커니즘을 사용할 수 있습니다. 예 :
type
TForm1 = class(TForm)
..
protected
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
..
procedure TForm1.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent is TForm) and
(TForm(AComponent).FormStyle = fsMDIChild) and
(MDIChildCount = 0) then begin
// do work
end;
end;
WM_MDIDESTROY
메시지가 MDI 클라이언트 창으로 보내 캐치 :
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FOldClientWndProc: TFarProc;
procedure NewClientWndProc(var Message: TMessage);
end;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
if FormStyle = fsMDIForm then
begin
HandleNeeded;
FOldClientWndProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC,
Integer(MakeObjectInstance(NewClientWndProc)));
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLong(ClientHandle, GWL_WNDPROC, Integer(FOldClientWndProc));
end;
procedure TForm1.NewClientWndProc(var Message: TMessage);
begin
if Message.Msg = WM_MDIDESTROY then
if MDIChildCount = 1 then
// do work
with Message do
Result := CallWindowProc(FOldClientWndProc, ClientHandle, Msg, WParam,
LParam);
end;
당신은 MainForm이 (가) 작성하는 각 MDI 자식에 OnClose
또는 OnDestroy
이벤트 핸들러를 할당 할 수 있습니다. MDI 클라이언트가 닫히거나 파기 될 때마다 처리기는 더 이상 MDI 자식 폼이 아직 열려 있는지 확인하고 그렇지 않은 경우 수행 할 작업을 수행 할 수 있습니다.
procedure TMainForm.ChildClosed(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
// the child being closed is still in the MDIChild list as it has not been freed yet...
if MDIChildCount = 1 then
begin
// do work
end;
end;
또는 :
const
APPWM_CHECK_MDI_CHILDREN = WM_APP + 1;
procedure TMainForm.ChildDestroyed(Sender: TObject);
begin
PostMessage(Handle, APPWM_CHECK_MDI_CHILDREN, 0, 0);
end;
procedure TMainForm.WndProc(var Message: TMessage);
begin
if Message.Msg = APPWM_CHECK_MDI_CHILDREN then
begin
if MDIChildCount = 0 then
begin
// do work
end;
Exit;
end;
inherited;
end;
1 니스! 내 것보다 낫다. ;-) – NGLN
@NGLN - 고마워! 당신이 아이가 이것을 할 때와 그 것을 알 필요가 있기 때문에 당신의 것이 더 강력합니다. :) –
NGLN, Sertac Akyus 그리고 Remy Lebeau. 답변 해 주셔서 감사합니다. 모두 훌륭합니다. 너는 아주 좋다. 이 상황에서 최고의 코드는 Sertac Akyuz였습니다. 더 간단하고 내 문제를 해결했습니다. NGLN과 Remy, 나는 미래의 상황을 위해 당신의 코드를 저장했다. 감사. – Delphiman