我用toolbar2000的TTBToolWindow控件作了一个控制栏,mdi子窗口为一dbgrid控件,当控制栏的edit窗口拥有焦点时,mdi子窗口的dbgrid控件无法得到焦点,怎么解决?

解决方案 »

  1.   

    How to control focus in a MDI application? 
    Product:Delphi all versions 
    Uploader: Fernando Silva 
    Question/Problem/Abstract:
    How to control focus in a MDI application? 
    Answer: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. 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:   procedure TMainForm.ComboBox1Click(Sender: TObject); 
      begin 
        { ... other actions } 
        if Assigned( ActiveMDIChild ) then 
        with ActiveMDIChild do 
        sendmessage( handle, wm_mdiactivate, 0, handle ); 
      end; 谁有更好的办法