Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no horizontal scroll bar?

Status
Not open for further replies.

scott27349

Technical User
Feb 15, 2002
3
US
im writting this program im reading out of a book, when i run the program it is supposed to have a vertical scroll bar and a horazontal scroll bar, but the horazontal scroll bar doesnt show up when i run it. i think my main problem is im reading a book that was wrote in visual c++ version 5, and im using msv c++ 6.if someone can look at this code and tell me if i need to use a differant class with version 6, and what the differances are from version 5 and 6. do i need to buy a book on version 6? or can i just modify the 5 classes? heres the code, and thanks for any input
// ex04cView.cpp : implementation of the CEx04cView class
//

#include "stdafx.h"
#include "ex04c.h"

#include "ex04cDoc.h"
#include "ex04cView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEx04cView

IMPLEMENT_DYNCREATE(CEx04cView, CScrollView)

BEGIN_MESSAGE_MAP(CEx04cView, CScrollView)
//{{AFX_MSG_MAP(CEx04cView)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx04cView construction/destruction

CEx04cView::CEx04cView() : m_rectEllipse(0, 0, 4000, -4000)
{
m_nColor = GRAY_BRUSH;
}

CEx04cView::~CEx04cView()
{
}

BOOL CEx04cView::preCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CScrollView::preCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx04cView drawing

void CEx04cView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse);
}

void CEx04cView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal(20000, 30000); // 20 by 30 cm
CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50);
SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine);
}

/////////////////////////////////////////////////////////////////////////////
// CEx04cView printing

BOOL CEx04cView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CEx04cView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CEx04cView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEx04cView diagnostics

#ifdef _DEBUG
void CEx04cView::AssertValid() const
{
CScrollView::AssertValid();
}

void CEx04cView:ump(CDumpContext& dc) const
{
CScrollView:ump(dc);
}

CEx04cDoc* CEx04cView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx04cDoc)));
return (CEx04cDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEx04cView message handlers

void CEx04cView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar) {
case VK_HOME:
OnVScroll(SB_TOP, 0, NULL);
OnHScroll(SB_LEFT, 0, NULL);
break;
case VK_END:
OnVScroll(SB_BOTTOM, 0, NULL);
OnHScroll(SB_RIGHT, 0, NULL);
break;
case VK_UP:
OnVScroll(SB_LINEUP, 0, NULL);
break;
case VK_DOWN:
OnVScroll(SB_LINEDOWN, 0, NULL);
break;
case VK_PRIOR:
OnVScroll(SB_PAGEUP, 0, NULL);
break;
case VK_NEXT:
OnVScroll(SB_PAGEDOWN, 0, NULL);
break;
case VK_LEFT:
OnHScroll(SB_LINELEFT, 0, NULL);
break;
case VK_RIGHT:
OnHScroll(SB_LINERIGHT, 0, NULL);
break;
default:
break;
}
}

void CEx04cView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rectDevice = m_rectEllipse;
dc.LPtoDP(rectDevice);
if (rectDevice.PtInRect(point)) {
if (m_nColor == GRAY_BRUSH) {
m_nColor = WHITE_BRUSH;
}
else{
m_nColor = GRAY_BRUSH;
}
InvalidateRect(rectDevice);
}
}




----------------------------------------------------------------------------------
heres the header files
// ex04cView.h : interface of the CEx04cView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_EX04CVIEW_H__94911C0B_4FAD_11D0_8FCB_
00C04FC2A0C2__INCLUDED_)
#define AFX_EX04CVIEW_H__94911C0B_4FAD_11D0_8FCB_00C04FC2A
0C2__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

class CEx04cView : public CScrollView
{
protected: // create from serialization only
CEx04cView();
DECLARE_DYNCREATE(CEx04cView)

// Attributes
public:
CEx04cDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEx04cView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CEx04cView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CEx04cView)
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_nColor;
CRect m_rectEllipse;
};

#ifndef _DEBUG // debug version in ex04cView.cpp
inline CEx04cDoc* CEx04cView::GetDocument()
{ return (CEx04cDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_EX04CVIEW_H__94911C0B_4FAD_11D0_8FCB_
00C04FC2A0C2__INCLUDED_)



 
Okay, I'm not sure from looking at the code what's wrong, but with your permission, here are a few ideas for you to try.

First, check the OnInitialUpdate() function very carefully to make sure it exactly matches the example in the book.
Code:
void CEx04cView::OnInitialUpdate() 
{ 
  CScrollView::OnInitialUpdate(); 
  CSize sizeTotal(20000, 30000); // 20 by 30 cm 
  CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2); 
  CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50); 
  SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine); 
}
If you find that every letter, number, and word is exactly right, then you might want to try searching all the files in your project for the WS_VSCROLL flag. Although it won't match, it could look vaguely similar to this:
Code:
m_MyWnd.Create(m_hWnd, rcDefault, NULL,
	WS_VISIBLE | WS_VSCROLL );
Assuming you do find WS_VSCROLL, make sure WS_HSCROLL is also there. If it isn't, then you need to add it, as I'm doing here in my example (be sure to include | between each of the style descriptors, which is the uppercase key located next to the right shift key... at least on my keyboard):
Code:
m_MyWnd.Create(m_hWnd, rcDefault, NULL,
	WS_VISIBLE | WS_VSCROLL | WS_HSCROLL );
Now, if the WS_HSCROLL style flag already exists in your code, then it's possible that the horizontal dimension of the object you're viewing should be increased to be larger than the window. Go back to the OnInitialUpdate() function and tinker with changing the sizes...

If none of that works, then I'm fresh out of ideas. ;-)
 
i feel like an idiot, i prolly am an idiot.there was nothing wrong with the code here, when i ran the program and no horizontal scroll bar showed up, it was because i had the window streched too wide, therefore not needing the scroll bar option, just like a everyday windows program. i drug the window over and it poped up,duh, somebody tell me they have made a stupid mystake like this so i want feel like a complete idiot. took me two days to figure out what was wrong with it lol
thanks
scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top