CFormView SetFocus

Category: visual studio vc

Question

sgrm123 on Thu, 11 Oct 2018 13:49:25


Hi,

I have  a CFormView in MFC MDI application. This formview has controls. I am posting message to this formview from a dockable pane. After receiving this message, If I click on the view where controls are not placed, If I call GetFocus() in OnLButtonDown of that view class , it gives the window handle of first control of in the dialog of that view, not the view's window handle.

What I need to do to get the view's window handle?

Replies

Guido Franzke on Thu, 11 Oct 2018 13:55:20


Hello,

try GetActiveView.

Regards, Guido

sgrm123 on Thu, 11 Oct 2018 14:01:14


Hello,

try GetActiveView.

Regards, Guido

The active view is the same view only. I am not going/moving to any other view and as you said I checked GetActiveView and it is giving the same view handle only but GetFocus() gives the window handle of first control of in the dialog of that view, not the view's window handle

Guido Franzke on Fri, 12 Oct 2018 06:54:24


Hello,

try GetActiveView.

Regards, Guido

The active view is the same view only. I am not going/moving to any other view and as you said I checked GetActiveView and it is giving the same view handle only but GetFocus() gives the window handle of first control of in the dialog of that view, not the view's window handle

You can get the window handle of any control with GetSafeHwnd. GetActiveView gets the CFormView and then you can GetSafeHwnd.

sgrm123 on Fri, 12 Oct 2018 07:01:37


Hello,

try GetActiveView.

Regards, Guido

The active view is the same view only. I am not going/moving to any other view and as you said I checked GetActiveView and it is giving the same view handle only but GetFocus() gives the window handle of first control of in the dialog of that view, not the view's window handle


You can get the window handle of any control with GetSafeHwnd. GetActiveView gets the CFormView and then you can GetSafeHwnd.
Sorry I know about GetSafeHwnd(). The problem is getfocus() not  returns cformview's cwnd*.

Guido Franzke on Fri, 12 Oct 2018 07:07:28


The problem is getfocus() not  returns cformview's cwnd*.
Yes, GetFocus returns the CWnd of the control that has the focus. In CFormView this is the first control in the tab order or the control which already has the focus by activating it with the mouse or keyboard.
GetFocus will not give the CWnd of the CForumView.