Search code examples
wxwidgets

How to activate frame manually in wxWidgets?


I have wxWidget application. And somewhere on my MainFrame I create new frame and call Show on it. But, if an user will do this action again, I don't want to create new frame. I want to activate previous one. I store pointer to created frame, but I don't know how to send activation coomand to him? I tried to send ActivatedEvent in createdFrame->ProcessEvents, but no sense.

Is it possible to sent activate command to a frame wxWidgets?


Solution

  • To grab the focus for a window, call the the method SetFocus()

    wxFrame * pFrame = new wxFrame( ... );
    
    ...
    
    pFrame->SetFocus();
    

    http://docs.wxwidgets.org/stable/wx_wxwindow.html#wxwindowsetfocus

    I wonder why you want to do this? It is a bit strange! Normally, people leave it up the the OS do this, when the user clicks on the window. In fact, the wxFrame hardly ever gets the focus, because there is very little ( nothing? ) it can do with it. What usually happens is that one of the widgets contained by the frame get the focus - for example a text control so the user can start typing into it.

    Maybe this is what you really want to do? In which case the procedure goes like this: