Author: Jonas Bilinkevicius
Status: MDI-application. MDI window and one child window. MDI window owns a TPanel
component, which owns any component which can get focus (TEdit for example). Child
window owns a TDBGrid component.
Problem: After running this simple test application, the focus is set on child
window's first focusable component - TDBGrid. After switching focus to TEdit
component owned by MDI window, there is no more possibility to switch focus back to
TDBGrid component owned by child window. TDBGrid component is immune to any mouse
events. Why? It looks like a child window is thinking about still having focus.
Answer:
This is one of the many shortcomings of the Windows MDI framework, it has never
been designed to cope with controls outside the MDI children that can take the
focus. You can trick it by sending a WM_MDIACTIVATE message to the active MDI
child, here demonstrated by an OnClick handler for a combobox on the toolbar:
1 procedure TMainForm.ComboBox1Click(Sender: TObject);
2 begin3 { ... other actions }4 if Assigned(ActiveMDIChild) then5 with ActiveMDIChild do6 sendmessage(handle, WM_MDIACTIVATE, 0, handle);
7 end;