Author: Jonas Bilinkevicius
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:
1 const2 WM_AddWin = WM_User + 300;
3 WM_DelWin = WM_User + 301;
4 5 type6 TForm1
7 { ... }8 private9 10 procedure OnAddWindow(var msg: TMessage); message WM_AddWin;
11 procedure OnDelWindow(var msg: TMessage); message WM_DelWin;
12 public13 end;
14 15 procedure TForm1.OnAddWindow(var msg: TMessage);
16 begin17 List.Add(Strpas(Pointer(msg.lparam)));
18 end;
19 20 procedure TForm1.OnDelWindow(var msg: TMessage);
21 begin22 List.delete(List.indexof(Strpas(Pointer(msg.lparam))));
23 end;
24 25 procedure OnChildFormCreate(Sender: TObject);
26 begin27 PostMessage(TForm(Owner).handle, WM_AddWin, 0, Integer(PChar('ChildFormname')));
28 end;
29 30 procedure OnChildFormDestroy;
31 begin32 PostMessage(TForm(Owner).handle, WM_DelWin, 0, Integer(PChar('ChildFormname')));
33 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.