Strange things with kill focus

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
kolo
Earned some good credits
Earned some good credits
Posts: 120
Joined: Tue Jun 21, 2005 1:19 pm
Location: Russia, Cheboksary
Contact:

Strange things with kill focus

Post by kolo » Thu Oct 20, 2005 1:16 pm

I need to control then my window lose focus. For doing that I write OnKillFocus() method in window class. But this method call then the window get the focus. For check this I write OnSetFocus(). At first call OnSetFocus and after OnKillFocus method. Is anybody has idea, what may be wrong?
only MSW & MSVS ))

cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg » Thu Oct 20, 2005 3:07 pm

I'm not totally sure I understand you problem but there are two focus events you can catch. They are:

EVT_SET_FOCUS(func)
EVT_KILL_FOCUS(func)

You can find more details if you look at wxFocusEvent in the docs.

Example:
__________________________

Code: Select all

BEGIN_EVENT_TABLE(MyForm, wxFrame)
    EVT_SET_FOCUS( MyForm::OnFocus )
    EVT_KILL_FOCUS( MyForm::OnBlur )
END_EVENT_TABLE()

///
/// Fires when frame gets focus
///
void MyForm::OnFocus(wxFocusEvent &event)
{
}

///
/// Fires when frame looses focus
///
void MyForm::OnBlur(wxFocusEvent &event)
{
}
HTH

Chris


------------------------------------------------------------
Chinook Developer Studio
*Free multiplatform IDE for BSD.Linux.Solaris.Windows*
http://www.degarrah.com/products/chinook/index.php

Zephyr Automated Test Runner
*Cross platform automated functional and regression testing*
http://www.degarrah.com/products/zephyr/index.php
------------------------------------------------------------

toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Post by toxicBunny » Thu Oct 20, 2005 9:37 pm

According to the docs,
wxFocusEvent
A focus event is sent when a window's focus changes. The window losing focus receives a "kill focus'' event while the window gaining it gets a "set focus'' one.

Notice that the set focus event happens both when the user gives focus to the window (whether using the mouse or keyboard) and when it is done from the program itself using SetFocus.
and
wxFocusEvent::GetWindow
Returns the window associated with this event, that is the window which had the focus before for the wxEVT_SET_FOCUS event and the window which is going to receive focus for the wxEVT_KILL_FOCUS one.

Warning: the window pointer may be NULL!
Check to see which window is receiving or losing focus. Is this occurring while debugging the application? I've seen messages like this when a break point is reached and the debugger gets the focus. Also, the pointer may be NULL as mentioned above indicating that some unknown window lost the focus as your frame received it.

-Scott

extreme_definitions
Knows some wx things
Knows some wx things
Posts: 34
Joined: Sat Dec 02, 2006 12:59 pm
Contact:

Post by extreme_definitions » Mon Dec 25, 2006 1:51 pm

I'm not getting exactly what you want to say.... But, If you want to call the focus events that ppl above have mentioned, you need to connect to them.

For e.g., if you want your control / window, which is indirectly inherited from wxWindow to connect to a focus event..... use this in the constructor.

this->Connect(ID_WINDOW, wxEVT_SET_FOCUS, wxFocusEventHandler(FINRELID_OptionsWindow::OnSetFocus));

where ID_WINDOW is the identifier of the window. The OnSetFocus function takes a wxFocusEvent argument. There, u can use the FindFocus or SetFocus functions...

Post Reply