Chapter 18: Progress-Based Controls Visual C++ and MFC Fundamentals
class CMainFrame : public CFrameWnd
{
public:
CMainFrame()
{
// Create the window's frame
Create(NULL, "Windows Application",
WS_OVERLAPPEDWINDOW |
WS_VSCROLL | WS_HSCROLL,
CRect(120, 100, 420, 320));
}
};
Suppose you created your application using AppWizard. If you created a CView-based
application, to add a vertical scroll bar, in your CView::PreCreateWindow() event, add
the WS_VSCROLL style to the CREATESTRUCT object. Here is an example:
BOOL CFrame3View::PreCreateWindow(CREATESTRUCT& cs)
{
// Keep the existing styles but add the WS_VSCROLL value
cs.style |= WS_VSCROLL;
return CView::PreCreateWindow(cs);
}
In the same way, you can add only the WS_HSCROLL value to get only the horizontal
scroll bar:
BOOL CFrame3View::PreCreateWindow(CREATESTRUCT& cs)
{
// Keep the existing styles but add the WS_VSCROLL value
cs.style |= WS_HSCROLL;
return CView::PreCreateWindow(cs);
}
If you want both scroll bars, combine both the WS_VSCROLL and the WS_HSCROLL
values:
BOOL CFrame3View::PreCreateWindow(CREATESTRUCT& cs)
{
// Keep the existing styles but add the WS_VSCROLL value