MFC (消息)-动态控件失去焦点的有关问题

MFC (消息)--动态控件失去焦点的问题
我在ListView中动态添加一个继承CIPAdressCtrl的控件,风格是WS_CHILD,在控件类中添加了ON_WM_KILLFOCUS消息映射,使用SetFieldFocus为它设置了焦点。
但是在实际调试中,如果将鼠标点击在控件以外的地方,不能响应控件的ONKillFocus处理方法。
网上各种查不到资料,求大神帮忙解惑啊。。。。。
------解决思路----------------------
CWnd::SetForegroundWindow
BOOL SetForegroundWindow( );

Return Value

Nonzero if the function is successful; otherwise 0.

Remarks

Puts the thread that created the window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The foreground window is the window with which the user is currently working. The foreground window applies only to top-level windows (frame windows or dialogs boxes). 

CWnd Overview 
------解决思路----------------------
  Class Members 
------解决思路----------------------
  Hierarchy Chart

See Also   CWnd::GetForegroundWindow

------解决思路----------------------
鼠标消息事件本来就是针对控件的,当鼠标在控件外时消息就给了外部窗口,如果需要你可以通过拦截消息试试
------解决思路----------------------
CWnd::SetCapture
CWnd* SetCapture( );

Return Value

A pointer to the window object that previously received all mouse input. It is NULL if there is no such window. The returned pointer may be temporary and should not be stored for later use.

Remarks

Causes all subsequent mouse input to be sent to the current CWnd object regardless of the position of the cursor. 

When CWnd no longer requires all mouse input, the application should call theReleaseCapture function so that other windows can receive mouse input.

CWnd Overview 
------解决思路----------------------
  Class Members 
------解决思路----------------------
  Hierarchy Chart

See Also   ::ReleaseCapture,::SetCapture, CWnd::GetCapture

------解决思路----------------------
引用:
Quote: 引用:

鼠标消息事件本来就是针对控件的,当鼠标在控件外时消息就给了外部窗口,如果需要你可以通过拦截消息试试

这个应该不需要拦截啊,我在空间外部点击,就相当于使这个控件丢失了焦点,MFC的处理机制不就是为新的窗体SetFocus的同时Kill 掉原来具有焦点的窗口的焦点么?

也许我对你的叙述理解错误,但点击控件外面,控件并不一定就失去焦点。
------解决思路----------------------
你希望点击控件之外的区域,控件就失去焦点吗?
------解决思路----------------------
获得焦点后,设置setcapture,点击鼠标后判断鼠标是否在控件内,不在里面则手动调用OnKillFocus,再ReleaseCapture
------解决思路----------------------
引用:
我在ListView中动态添加一个继承CIPAdressCtrl的控件,风格是WS_CHILD,在控件类中添加了ON_WM_KILLFOCUS消息映射,使用SetFieldFocus为它设置了焦点。
但是在实际调试中,如果将鼠标点击在控件以外的地方,不能响应控件的ONKillFocus处理方法。
网上各种查不到资料,求大神帮忙解惑啊。。。。。


你在被点击的控件的OnMouseDown中,SetFocus看看