Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
welllll when i run this program and when i scroll up it leaves lines that shouldnt be there and stuff..... i was wondering why does it keep doing this?
heres the header file :
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();protected:
int m_nViewWidth; // Workspace width in pixels
int m_nViewHeight; // Workspace height in pixels
int m_nHScrollPos; // Horizontal scroll position
int m_nVScrollPos; // Vertical scroll position
int m_nHPageSize; // Horizontal page size
int m_nVPageSize; // Vertical page size
protected:
afx_msg void OnPaint ();
afx_msg void OnSize (UINT nType, int cx, int cy);
afx_msg void OnVScroll (UINT nCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP ()};
and heres the CPP file :#include <afxwin.h>
#include "Hello.h"
#include <math.h>CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functionsBOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functionsBEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
ON_WM_VSCROLL ()
ON_WM_CREATE ()
ON_WM_SIZE ()
END_MESSAGE_MAP ()CMainWindow::CMainWindow ()
{
Create (NULL, _T ("The Hello Application"), WS_OVERLAPPEDWINDOW | WS_VSCROLL);}
int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
CClientDC dc (this);
m_nViewHeight = 101;
return 0;
}
void CMainWindow::OnSize (UINT nType, int cx, int cy)
{
CFrameWnd::OnSize (nType, cx, cy);//
// Set the vertical scrolling parameters.
//
int nVScrollMax = 0;
m_nVPageSize = 0;nVScrollMax = 100;
m_nVPageSize = 25;
SCROLLINFO si;
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = nVScrollMax;
si.nPos = 0;
si.nPage = m_nVPageSize;SetScrollInfo (SB_VERT, &si, TRUE);
}
void CMainWindow::OnVScroll (UINT nCode, UINT nPos, CScrollBar* pScrollBar){
int SCROLL=0;
switch (nCode)
{
case SB_LINEUP:
SCROLL = -5;
break;case SB_LINEDOWN:
SCROLL = 5;
break;
case SB_PAGEUP:
SCROLL = -m_nVPageSize;
break;case SB_THUMBTRACK:
SCROLL = (int) nPos - m_nVScrollPos;
break;case SB_PAGEDOWN:
SCROLL = m_nVPageSize;
break;default: // Ignore other scroll bar messages
return;}
int nScrollPos = m_nVScrollPos + SCROLL;
int nMaxPos = m_nViewHeight - m_nVPageSize;if (nScrollPos < 0)
SCROLL = -m_nVScrollPos;
else if (nScrollPos > nMaxPos)
SCROLL = nMaxPos - m_nVScrollPos;
if (SCROLL != 0) {
m_nVScrollPos += SCROLL;
SetScrollPos (SB_VERT, m_nVScrollPos, TRUE);
ScrollWindow (0, -SCROLL);
}
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);dc.Rectangle(0,0,100,100);
}
and remember it needs to be run in a Win32 app. and include the MFC dll.:-D (visual c++)
GIMPS

Disregard this thread :)
I found out what the problem was, i needed to set the windows origin as it moved with the
dc.SetWindowOrg (m_nHScrollPos, m_nVScrollPos);
function in the OnPaint () message :)
Now i just gotta explain what all the code does and post it up at www.planetsourcecode.com :)
Also for anyone who learns form example this is a good site to go to, it has over 100,000,000 lines of code in like 14 different languages (programming) :)
Thank you anyone who attempted to help me solve this problem.
GIMPS

![]() |
VBS through Internet Expl...
|
java network programming
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |