Window focus (URGENT)

Hi,

I have a frame window with a CListView and a CEdit control in a toolbar.
Upon pressing the up- and down keys, there is supposed to be some action in the CEdit control.
I am handling this in PreTranslateMessage of my MainFrame.
The problem is that when the ClistView has the focus and a line is selected, using the up and down keys also changes the CEdit. So, I need to add a criteria in the PreTanslateMessage

(if (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_DOWN) && .....)

to allow changes in the CEdit only if it has the input focus. I tried GetFocus but this allways return a CWnd* if ANY window has the focus.
I wonder how I can find out that this special window has the focus.

Radu
[758 byte] By [Radu] at [2007-11-18 1:35:49]
# 1 Re: Window focus (URGENT)
You can compare the m_hWnd-Members. Something like:

CWnd *pWnd = GetFocus();
if (pWnd->m_hWnd == m_Edit.m_hWnd)
{ // Focus is hWnd
}

should work.
martho at 2007-11-10 8:53:48 >
# 2 Re: Window focus (URGENT)
Hi,

thanks for your reply. Unfortunately it doesn't work. The m_hWnd's are never equal.
Radu at 2007-11-10 8:54:59 >
# 3 Re: Window focus (URGENT)
I'm very unsure, but try to compare pointer to CWnd objects:
if (GetFocus() == &m_Edit)
deesan at 2007-11-10 8:55:56 >
# 4 Re: Window focus (URGENT)
thanks but nope.

or maybe I could check if the cursor is in the CEdit. but how?
Radu at 2007-11-10 8:57:01 >
# 5 Re: Window focus (URGENT)
This is strange, my code works here without a problem. Have a look at the pWnd->m_hWnd you are getting back from GetFocus() and use Spy++ to see, which window is it when the focus is inside your edit.
martho at 2007-11-10 8:58:00 >
# 6 Re: Window focus (URGENT)
Hi,

the problem is solved.
if I use martho's method but with the API version of GetFocus it works.

HWND curWnd = ::GetFocus();

if (curWnd == m_Edit.m_hWnd)
{ // Focus is hWnd
}

I think it is maybe because curWnd must be of type HWND!?
Radu at 2007-11-10 8:58:58 >