2005. október 27., csütörtök
How to check if a MDI child has been created or destroyed
Problem/Question/Abstract:
I have to write a kind of task list of all MDI child windows which are opened in the application. For this reason I tried to use the WM_PARENTNOTIFY to get an event, if a MDI child is created or destroyed. But I don't receive a message when the child windows are created or destroyed.
Answer:
Try the following:
const
WM_AddWin = WM_User + 300;
WM_DelWin = WM_User + 301;
type
TForm1
{ ... }
private
procedure OnAddWindow(var msg: TMessage); message WM_AddWin;
procedure OnDelWindow(var msg: TMessage); message WM_DelWin;
public
end;
procedure TForm1.OnAddWindow(var msg: TMessage);
begin
List.Add(Strpas(Pointer(msg.lparam)));
end;
procedure TForm1.OnDelWindow(var msg: TMessage);
begin
List.delete(List.indexof(Strpas(Pointer(msg.lparam))));
end;
procedure OnChildFormCreate(Sender: TObject);
begin
PostMessage(TForm(Owner).handle, WM_AddWin, 0, Integer(PChar('ChildFormname')));
end;
procedure OnChildFormDestroy;
begin
PostMessage(TForm(Owner).handle, WM_DelWin, 0, Integer(PChar('ChildFormname')));
end;
This will post a message to the owner of a child form to add it to the master list and delete it
when it dies.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése