Computing.Net > Forums > Programming > MFC :) mhm thats right

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

MFC :) mhm thats right

Reply to Message Icon

Name: gimmpy225
Date: November 30, 2004 at 20:20:39 Pacific
OS: windows xp pro
CPU/Ram: amd 64 2600
Comment:

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 functions

BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}

/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions

BEGIN_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



Sponsored Link
Ads by Google

Response Number 1
Name: gimmpy225
Date: December 1, 2004 at 21:58:23 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More


VBS through Internet Expl... java network programming



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: MFC :) mhm thats right

batch right click? www.computing.net/answers/programming/batch-right-click/15657.html

Classes in C++ www.computing.net/answers/programming/classes-in-c/11619.html

batch search f. and go to that dir www.computing.net/answers/programming/batch-search-f-and-go-to-that-dir/15567.html