Strange things with kill focus
- kolo
- Earned some good credits
- Posts: 120
- Joined: Tue Jun 21, 2005 1:19 pm
- Location: Russia, Cheboksary
- Contact:
Strange things with kill focus
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 ))
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:
__________________________
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
------------------------------------------------------------
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)
{
}
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
------------------------------------------------------------
-
- Super wx Problem Solver
- Posts: 424
- Joined: Tue Jul 12, 2005 8:44 pm
- Location: Alabama, USA
According to the docs,
-Scott
andwxFocusEvent
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.
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.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!
-Scott
-
- Knows some wx things
- Posts: 34
- Joined: Sat Dec 02, 2006 12:59 pm
- Contact:
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...
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...