slapak
asked on
Auto scroll in CFormView
I have some controls in CFormView, and when I tabbed to those which out of the visible area, I can't see the caret or the active control. How can I make auto scroll depending on the caret's position or the active control position. I would like a global method as posible i.e. avoiding treating each control.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All right, but it works only if I don't have radio button or other CButton derivatives. What can I do in this case?
To add support for other that edit controls, you need to look for aditional notification values in the WM_COMMAND handler.
NOTE: You need to enable the notify window flag for every control for this to work!
Button: BN_SETFOCUS
Edit: EN_SETFOCUS
ListBox: LBN_SETFOCUS
ComboBox: CBN_SETFOCUS
The new common controls send WM_NOTIFY messages to its parent, so
we need to handle them a little different.
Insert the decleration of the handler in the views class header:
void OnSetFocusNotify( NMHDR * pNotifyStruct, LRESULT * result );
Insert this line above END_MESSAGE_MAP for the views class:
ON_NOTIFY_RANGE(NM_SETFOCU S, 0, 0xffff, OnSetFocusNotify)
Insert the handler code in the views cpp-file:
void CXxxxView::OnSetFocusNotif y( NMHDR * pNotifyStruct, LRESULT * result )
{
CWnd* pControl = CWnd::FromHandle(pNotifySt ruct->hwnd From);
ASSERT_VALID(pControl);
CRect rcControl;
pControl->GetWindowRect(&r cControl);
ScreenToClient(&rcControl) ;
[ insert code to scroll here ]
}
NOTE: You need to enable the notify window flag for every control for this to work!
Button: BN_SETFOCUS
Edit: EN_SETFOCUS
ListBox: LBN_SETFOCUS
ComboBox: CBN_SETFOCUS
The new common controls send WM_NOTIFY messages to its parent, so
we need to handle them a little different.
Insert the decleration of the handler in the views class header:
void OnSetFocusNotify( NMHDR * pNotifyStruct, LRESULT * result );
Insert this line above END_MESSAGE_MAP for the views class:
ON_NOTIFY_RANGE(NM_SETFOCU
Insert the handler code in the views cpp-file:
void CXxxxView::OnSetFocusNotif
{
CWnd* pControl = CWnd::FromHandle(pNotifySt
ASSERT_VALID(pControl);
CRect rcControl;
pControl->GetWindowRect(&r
ScreenToClient(&rcControl)
[ insert code to scroll here ]
}
As a formview is derived from CScrollView, a better way to scroll the view would be to call ScrollToPosition() and GetDeviceScrollPosition() to get the current scroll position instead of using SetScrollInfo() and ScrollWindowEx().