How to Place Scroll Bars on an Object Derived from CControlBarID: Q132081
|
When you place scroll bars on an object derived from CControlBar, such as CDialogBar, the window messages must be handled in a special way as described in this article.
There are three categories of messages for which you can have handlers:
window messages, control notification messages, and command messages.
Control notification messages are WM_COMMAND messages sent from controls
and other child windows to their parent windows. For example, an edit
control can send its parent a WM_COMMAND message containing the EN_CHANGE
control notification code. Window messages include the messages with the
WM_ prefix, with the exception of WM_COMMAND. WM_VSCROLL is an example of
a window message sent by a control to its parent. Command messages
include WM_COMMAND messages sent from user-interface objects, such as
menus and toolbar buttons.
Control notification messages generated by controls in a CControlBar
derived object are routed to the parent view or frame window class of the
CControlBar object. However, window messages from controls are routed to
the object associated with the parent window of the control -- namely, the
CControlBar object itself. Therefore, handlers for controls that send
window messages cannot be placed in the frame or view object.
One of the controls that sends a window message is a CScrollBar control.
Therefore, when a CScrollBar control is placed on a an object derived from
CControlBar, such as CDialogBar, the window messages it generates cannot
be handled in the parent view or frame window classes, like other messages.
One way to handle window messages from a CScrollBar on a CDialogBar is to
derive from CDialogBar and include a handler in the derived class. Another
way is to derive from CDialogBar and route the window messages sent to this
object to the parent frame or the view window object.
BOOL CMyDlgBar :: Create(CWnd* pParentWnd, UINT nStyle)
{
// Associate the dialog template with the class:
return CDialogBar :: Create (pParentWnd,
IDD_DIALOG1,
nStyle,
IDD_DIALOG1);
}
NOTE: Create has only two parameters. This is so the Create
function can only be used for the dialog bar IDD_DIALOG1.
m_MyDlgBar.Create(this, CBRS_TOP );
///////////////////////////////////////////////////////////
// mydlgbar.cpp : implementation file
//
...
void CMyDlgBar::OnHScroll( UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar)
{
// Add code for processing WM_HSCROLL messages:
if (pScrollBar != NULL && pScrollBar->GetDlgCtrlID() == IDC_SCROLLBAR1)
{
TRACE0( "Received message from scroll bar : IDC_SCROLLBAR1\n");
}
CDialogBar::OnHScroll(nSBCode, nPos, pScrollBar);
}
///////////////////////////////////////////////////////////
// mydlgbar.cpp : implementation file
//
...
void CMyDlgBar::OnHScroll(UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar)
{
// Actual code to handle this message is in the parent
// frame or view object. Send the message to that object.
#ifdef _WIN32
GetOwner()->SendMessage(WM_HSCROLL,
(WPARAM)MAKELONG((WORD)nSBCode,(WORD)nPos),
(LPARAM)pScrollBar->m_hWnd);
#else
GetOwner()->SendMessage(WM_HSCROLL,
(WPARAM)mSBCode,
(LPARAM)MAKELONG(nPos, pScrollBar->m_hWnd));
#endif
CDialogBar::OnHScroll(nSBCode, nPos, pScrollBar);
}
Additional query words: kbinf 1.00 1.50 2.00 2.10 2.50 2.51 2.52 3.00 3.10 4.00 4.10
Keywords : kbcode kbMFC KbUIDesign kbVC
Version : 1.00 1.50 1.51 1.52 | 1.00 2.00
Platform : NT WINDOWS
Issue type :
Last Reviewed: August 2, 1999