From: Luigino on 1 Feb 2010 09:50 Since I'm trying to slide graphic from right to left so I decide to set the origin of coordinates to the right-bottom corner of the client so the graphic would be like all "negative" doing this: CClientDC dc(this); CRect rc; GetClientRect(&rc); dc.SetMapMode(MM_ANISOTROPIC); dc.SetViewportOrg(rc.right, rc.bottom); dc.SetWindowExt(rc.right, rc.bottom); dc.SetViewportExt(-(rc.right), -(rc.bottom)); so if I am right, now the graphic area coordinates starts from right- bottom corner going to left-bottom corner and right-top corner. so I set an array of POINT where I have: {x=-10,y=-20;x=-9,y=-13;x=-8,y=-17;x=-7,y=-7;x=-6,y=-9;...x=-1,y=-11;x=0,y=0} and with PolyLine it should draw in the "negative" area I set right after SetMapMode...but it's like clear, is there something I missed or made wrong around what I said right before?... Thanks Ciao Luigi
From: Luigino on 2 Feb 2010 09:48 Hello again to all... I figured out about to set correctly coordinates so graphic would slide from right to left. But when I resize the window, it repaints but it doesn't scale at all!... I mean the array has values and the CDC should do the rest of hard stuff about scaling as you, Stephen, said... In fact I see vertical and horizontal lines are redrawn but the graphic (using PolyLine function) draws same thing as it was before resizing the window... I have to say this class control is a CWnd based so I have OnPaint() event where I call an own OnDraw()... I settled in the creation function: CPaintDC dc(this); CRect rc; ::GetClientDC(this->m_hWnd, &rc); dc.SetBkColor(RGB(0,0,0)); dc.SetMapMode(MM_ANISOTROPIC); <----- so CDC would do the hard stuff dc.SetWindowOrg(rc.BottomRight()); <----- having origin point at bottom-right corner dc.SetViewportOrg(0, 0); dc.SetViewportExt(-1, -1); <----- those three should make representing values as positive dc.SetWindowExt(1, 1); when in reality they are negative and in the OnPaint() I call again CPaintDC dc(this); because the method doesn't pass any CDC parameter... and inside I implemented: dc.SetViewportExt(-1, -1); dc.SetWindowExt(1, 1); so it should supposed to re-scale the client DC to redraw correctly the graphic everytime I resize itself.... Since I'm using also CMemDC, declared in OnDraw event simply as: CMemDC mDC(pDC); to prevent flickering, I have a class which creates a DC and when variable destroys it applies bitblt, so since the class has GetBkColor to fill rect and I settled as above the background as BLACK, when it paints, its WHITE instead... Any idea?... Thanks all! Ciao, Luigi
From: Stephen Myers on 2 Feb 2010 10:35 Luigino wrote: > Hello again to all... > > I figured out about to set correctly coordinates so graphic would > slide from right to left. But when I resize the window, it repaints > but it doesn't scale at all!... I mean the array has values and the > CDC should do the rest of hard stuff about scaling as you, Stephen, > said... > In fact I see vertical and horizontal lines are redrawn but the > graphic (using PolyLine function) draws same thing as it was before > resizing the window... > > I have to say this class control is a CWnd based so I have OnPaint() > event where I call an own OnDraw()... > I settled in the creation function: > > CPaintDC dc(this); > CRect rc; > ::GetClientDC(this->m_hWnd, &rc); > dc.SetBkColor(RGB(0,0,0)); > dc.SetMapMode(MM_ANISOTROPIC); <----- so CDC would do the hard stuff > dc.SetWindowOrg(rc.BottomRight()); <----- having origin point at > bottom-right corner > dc.SetViewportOrg(0, 0); > dc.SetViewportExt(-1, -1); <----- those three > should make representing values as positive > dc.SetWindowExt(1, 1); when in > reality they are negative > > and in the OnPaint() I call again CPaintDC dc(this); because the > method doesn't pass any CDC parameter... > and inside I implemented: > > dc.SetViewportExt(-1, -1); > dc.SetWindowExt(1, 1); > > so it should supposed to re-scale the client DC to redraw correctly > the graphic everytime I resize itself.... > Since I'm using also CMemDC, declared in OnDraw event simply as: > CMemDC mDC(pDC); to prevent flickering, I have a class which creates a > DC and when variable destroys it applies bitblt, so since the class > has GetBkColor to fill rect and I settled as above the background as > BLACK, when it paints, its WHITE instead... > > Any idea?... > Thanks all! > Ciao, Luigi You are scaling the wrong device context, at the wrong time. Each time OnPaint gets called expect a new DC. Anything you do to the CPaintDC goes away when the method exits. The only thing you should do to the CPaintDC Create mDC. All the scaling (SetWindow, SetMapMode, SetViewport) should be applied to mDC, in OnPaint(). All drawing should be on mDC as well. Almost all drawing functions are available as part of the CDC class. ::GetClientRect(hDC,&rc) should be dc.GetClientRect(rc). Using the global functions that require a handle will work but the MFC methods are much prefered. That's a big part of why you're using MFC to start with. I would have to see the CMemDC class in order to offer an opinion on it. Again, I would expect to do ALL drawing on mDC. If you want to do the memory DC creation and bitblt, that makes sense. I don't see where you can do a GetBkColor and get anything useful. I assume that CMemDC is based on CDC Creates a compatible DC Creates a compatible bitmap sized properly Also, take a careful look at Dr Newcomer's posts. He gives an very good explanation of what not to do. Steve
From: Luigino on 4 Feb 2010 06:08 Hello Joe and Stephen, maybe I am a bit lost about those OnDraw and OnPaint things... so I modified the code to put everything only in the OnPaint so the behaviour about DC should be correct BUT when I set MM_ANISOTROPIC and new origin to bottom right in the OnPaint as you said it doesn't make the graphic sliding from right to left... Here I paste the full code of this test app (the CMemDC mDC(&dc) is an external class): In the .H file I have: #ifdef MYDLL_BUILD #define MYDLL_IO _declspec(dllexport) //conditional on MYLIB_BUILD #else #define MYDLL_IO _declspec(dllimport) #endif class MYDLL_IO CMyDLL : public CWnd { DECLARE_DYNCREATE(CMyDLL) // matrix of POINT for each element to represent typedef vector<POINT> m_fPoints; // array representing points values for each single source typedef vector<m_fPoints> m_Points; // array representing list of sources having their POINT values public: CMyDLL(CWnd *parent, CWnd *parentcontrol, CRect parentrect, int nparentID); virtual ~CMyDLL(); public: void set_MinMax(int minvalue, int maxvalue, int maxsizearray); void AddElement(UINT nX, UINT nY, const char * description, double value); protected: BOOL scrollState; UINT iTimerVal; UINT nElapse; BOOL bSetDraw; m_Points mPoints; // matrix of sources representing POINT values int mSourceMaxSizeArray; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMyDLL) protected: virtual void PreSubclassWindow(); //}}AFX_VIRTUAL protected: BOOL EnableTimer(BOOL tmrstate); int OnCreate(LPCREATESTRUCT lpCreateStruct); public: static BOOL RegisterWindowClass(); protected: //{{AFX_MSG(CMyDLL) afx_msg void OnPaint(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnTimer(UINT TimerVal); afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; In the .CPP file I have: #ifdef _DEBUG #define new DEBUG_NEW #define GDI_FLUSH() GdiFlush() #else #define GDI_FLUSH() #endif #define CMYDLL_CLASSNAME _T("MFCMyDLLCtrlTest") // Window class name #define IDT_TIMER_0 WM_USER + 1000 IMPLEMENT_DYNAMIC(CMyDLL, CWnd) CMyDLL::CMyDLL(CWnd *parent, CWnd *parentcontrol, CRect parentrect, int nparentID) { RegisterWindowClass(); scrollState = TRUE; gridOffset = 0; bSetDraw = TRUE; nElapse = 1000; iTimerVal = 0; // Initializing graph's DC... if( !Create(_T("MFCMyDLLCtrlTest "), NULL, WS_CHILD| WS_VISIBLE, parentrect, parent, nparentID) ) { MessageBox(_T("Unable to create object!"), _T("Alert!"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); } SetWindowPos(parentcontrol, 0, 0, 0, 0, SWP_NOSIZE| SWP_NOMOVE); } CMyDLL::~ CMyDLL () { DestroyWindow(); } // Register the window class if it has not already been registered. BOOL C CMyDLL::RegisterWindowClass() { WNDCLASS wndcls; HINSTANCE hInst = AfxGetInstanceHandle(); if (!(::GetClassInfo(hInst, CMYDLL_CLASSNAME, &wndcls))) { // otherwise we need to register a new class wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.cbClsExtra = wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; wndcls.hCursor = AfxGetApp()- >LoadStandardCursor(IDC_ARROW); wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); wndcls.lpszMenuName = NULL; wndcls.lpszClassName = CACHART_CLASSNAME; if (!AfxRegisterClass(&wndcls)) { AfxThrowResourceException(); return FALSE; } } return TRUE; } BEGIN_MESSAGE_MAP(CMyDLL, CWnd) //{{AFX_MSG_MAP(CMyDLL) ON_WM_PAINT() ON_WM_CREATE() ON_WM_ERASEBKGND() ON_WM_SIZE() ON_WM_WINDOWPOSCHANGED() ON_WM_TIMER() ON_MESSAGE(WM_ENTERSIZEMOVE, OnEnterSizeMove) ON_MESSAGE(WM_EXITSIZEMOVE, OnExitSizeMove) //}}AFX_MSG_MAP END_MESSAGE_MAP() int CMyDLL::OnCreate(LPCREATESTRUCT lpCreateStruct) { int ret = CWnd::OnCreate(lpCreateStruct); EnableTimer(scrollState); return ret; } //{{AFX_MSG(CMyDLL) - message handlers void CMyDLL::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); int save = dc.SaveDC(); //dc.FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); dc.SetBkColor(RGB(0,0,0)); dc.SetMapMode(MM_ANISOTROPIC); dc.SetWindowOrg(rect.BottomRight()); dc.SetViewportOrg(0, 0); dc.SetViewportExt(-1, -1); dc.SetWindowExt(1, 1); if(bSetDraw) { CMemDC mDC(&dc); // ********** Background *********** // Grid if (bActivateGrid) { CPen qLinePen(PS_SOLID, 1, RGB(0,139,0)); mDC->SelectObject(&qLinePen); // Grid - Horizontal lines mDC->MoveTo(1, 0); mDC->LineTo(rect.Width(), 0); int height = rect.Height(); int maxlines = height / (int)12.5; for (int i=1;i<=maxlines;i++){ int y_axis = (int)((double)i * 12.5); if (y_axis <= rect.Height()) { mDC->MoveTo(1, y_axis); mDC->LineTo(rect.Width(), y_axis); } } // Grid - Vertical lines mDC->MoveTo(0, 0); mDC->LineTo(0, rect.Height()); int width = rect.Width(); maxlines = width / (int)12.5; for (int i=1;i<=maxlines;i++){ int x_axis = (int)(((double)i * 12.5) - gridOffset); if (x_axis <= rect.Width()) { mDC->MoveTo(x_axis, 1); mDC->LineTo(x_axis, rect.Height()); } } qLinePen.DeleteObject(); } // *********** graphic component *********** // based on choice of graph type CPen qPolylinePen(PS_SOLID, 1, RGB(0, 255, 0)); switch (iGraphType) { case GRAPH_BARS: break; case GRAPH_LINES: { if (mPoints.capacity() == 1) { mDC- >SelectObject(qPolylinePen); m_fPoints* pointsline = &mPoints[0]; mDC->Polyline(&(*pointsline) [0], (int)pointsline->size()); //mDC->PolyPolyline() qPolylinePen.DeleteObject(); } } break; default: break; } GDI_FLUSH(); } dc.RestoreDC(save); } BOOL CMyDLL::OnEraseBkgnd(CDC* pDC) { return FALSE; } void CMyDLL::OnTimer(UINT TimerVal) { // ****** processing event ****** if (TimerVal == IDT_TIMER_0) { gridOffset++; if (gridOffset > 12.5) gridOffset = 0.0; Invalidate(); // to call OnDraw()/OnPaint() UpdateWindow(); } // call base class handler CWnd::OnTimer(TimerVal); } void CMyDLL::OnWindowPosChanged(WINDOWPOS* lpwndpos) { CWnd::OnWindowPosChanged(lpwndpos); } void CMyDLL::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class // In our case this is not needed - yet - so just drop through to // the base class // Get Size of Display area CWnd::PreSubclassWindow(); } void CMyDLL::set_MinMax(int minvalue, int maxvalue, int maxsizearray) { iMinRange = minvalue; iMaxRange = maxvalue; mSourceMaxSizeArray = maxsizearray; // getting max size array of each source which has to be fixed mPoints.resize(1); mPoints[0].resize(mSourceMaxSizeArray); CRect rc; GetClientRect(&rc); int iPointOfOrigin = rc.Width(); for (int i=mPoints[0].size()-1;i>0;i--) // initializing this first source to initial values { // which are consecutive integer values for X-axis mPoints[0].at(i).x = iPointOfOrigin--; // and bottom screen value for Y-axis mPoints[0].at(i).y = 0; } } BOOL CMyDLL::EnableTimer(BOOL tmrstate) { // *************************************************************************** // if enabled it's a realtime task manager, otherwise it'd be a graphical // representation of values passed from external source // *************************************************************************** if (tmrstate) { iTimerVal = SetTimer(IDT_TIMER_0, nElapse, 0); if (iTimerVal == 0) { MessageBox(_T("Unable to obtain timer!"), _T("IDT_TIMER_0"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); return FALSE; } } else { if (iTimerVal > 0) { if (!KillTimer(IDT_TIMER_0)) { // message MessageBox(_T("Unable to stop timer!"), _T("IDT_TIMER_0"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); return FALSE; } } } return TRUE; } void CMyDLL::AddElement(UINT nX, UINT nY, const char * description, double value) { // add in value format because CPoint depends from resize... int i; CRect rc; ::GetClientRect(this->m_hWnd, &rc); if (nY+1 > mElements.size()) // check if I am adding a new source { mPoints.resize(nY +1); // setting the array to max size defined mPoints[nY].resize(mSourceMaxSizeArray); int iPointOfOrigin = 0; for (i=mPoints[nY].size()-1;i>0;i--) // initializing this first source to initial values { // which are consecutive integer values for X-axis mPoints[nY].at(i).x = iPointOfOrigin++; // and bottom screen value for Y-axis mPoints[nY].at(i).y = 0; } } // Now I add element value to the source if (scrollState) { // SHIFT-LEFT the array of POINTs to add new value rotate(mPoints[nY].begin(), mPoints[nY].begin()+1, mPoints[nY].end()); mPoints[nY].at(mPoints[nY].size() - 1).y = (LONG) ( (double)rand() / (RAND_MAX + 1) * (rc.bottom - 1) + 1 ); int iPointOfOrigin = rc.Width(); for (i=mPoints[nY].size()-1;i>0;i--) mPoints[nY].at(i).x = iPointOfOrigin--; } if (nY > mGraphElements.capacity()) { GraphElement single_element; single_element.description = description; single_element.color = mGraphColors.at(nY); mGraphElements.push_back(single_element); } Invalidate(); UpdateWindow(); } Thanks.... Ciao Luigi
From: Luigino on 4 Feb 2010 06:08
Hello Joe and Stephen, maybe I am a bit lost about those OnDraw and OnPaint things... so I modified the code to put everything only in the OnPaint so the behaviour about DC should be correct BUT when I set MM_ANISOTROPIC and new origin to bottom right in the OnPaint as you said it doesn't make the graphic sliding from right to left... Here I paste the full code of this test app (the CMemDC mDC(&dc) is an external class): In the .H file I have: #ifdef MYDLL_BUILD #define MYDLL_IO _declspec(dllexport) //conditional on MYLIB_BUILD #else #define MYDLL_IO _declspec(dllimport) #endif class MYDLL_IO CMyDLL : public CWnd { DECLARE_DYNCREATE(CMyDLL) // matrix of POINT for each element to represent typedef vector<POINT> m_fPoints; // array representing points values for each single source typedef vector<m_fPoints> m_Points; // array representing list of sources having their POINT values public: CMyDLL(CWnd *parent, CWnd *parentcontrol, CRect parentrect, int nparentID); virtual ~CMyDLL(); public: void set_MinMax(int minvalue, int maxvalue, int maxsizearray); void AddElement(UINT nX, UINT nY, const char * description, double value); protected: BOOL scrollState; UINT iTimerVal; UINT nElapse; BOOL bSetDraw; m_Points mPoints; // matrix of sources representing POINT values int mSourceMaxSizeArray; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMyDLL) protected: virtual void PreSubclassWindow(); //}}AFX_VIRTUAL protected: BOOL EnableTimer(BOOL tmrstate); int OnCreate(LPCREATESTRUCT lpCreateStruct); public: static BOOL RegisterWindowClass(); protected: //{{AFX_MSG(CMyDLL) afx_msg void OnPaint(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnTimer(UINT TimerVal); afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; In the .CPP file I have: #ifdef _DEBUG #define new DEBUG_NEW #define GDI_FLUSH() GdiFlush() #else #define GDI_FLUSH() #endif #define CMYDLL_CLASSNAME _T("MFCMyDLLCtrlTest") // Window class name #define IDT_TIMER_0 WM_USER + 1000 IMPLEMENT_DYNAMIC(CMyDLL, CWnd) CMyDLL::CMyDLL(CWnd *parent, CWnd *parentcontrol, CRect parentrect, int nparentID) { RegisterWindowClass(); scrollState = TRUE; gridOffset = 0; bSetDraw = TRUE; nElapse = 1000; iTimerVal = 0; // Initializing graph's DC... if( !Create(_T("MFCMyDLLCtrlTest "), NULL, WS_CHILD| WS_VISIBLE, parentrect, parent, nparentID) ) { MessageBox(_T("Unable to create object!"), _T("Alert!"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); } SetWindowPos(parentcontrol, 0, 0, 0, 0, SWP_NOSIZE| SWP_NOMOVE); } CMyDLL::~ CMyDLL () { DestroyWindow(); } // Register the window class if it has not already been registered. BOOL C CMyDLL::RegisterWindowClass() { WNDCLASS wndcls; HINSTANCE hInst = AfxGetInstanceHandle(); if (!(::GetClassInfo(hInst, CMYDLL_CLASSNAME, &wndcls))) { // otherwise we need to register a new class wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.cbClsExtra = wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; wndcls.hCursor = AfxGetApp()- >LoadStandardCursor(IDC_ARROW); wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); wndcls.lpszMenuName = NULL; wndcls.lpszClassName = CACHART_CLASSNAME; if (!AfxRegisterClass(&wndcls)) { AfxThrowResourceException(); return FALSE; } } return TRUE; } BEGIN_MESSAGE_MAP(CMyDLL, CWnd) //{{AFX_MSG_MAP(CMyDLL) ON_WM_PAINT() ON_WM_CREATE() ON_WM_ERASEBKGND() ON_WM_SIZE() ON_WM_WINDOWPOSCHANGED() ON_WM_TIMER() ON_MESSAGE(WM_ENTERSIZEMOVE, OnEnterSizeMove) ON_MESSAGE(WM_EXITSIZEMOVE, OnExitSizeMove) //}}AFX_MSG_MAP END_MESSAGE_MAP() int CMyDLL::OnCreate(LPCREATESTRUCT lpCreateStruct) { int ret = CWnd::OnCreate(lpCreateStruct); EnableTimer(scrollState); return ret; } //{{AFX_MSG(CMyDLL) - message handlers void CMyDLL::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); int save = dc.SaveDC(); //dc.FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); dc.SetBkColor(RGB(0,0,0)); dc.SetMapMode(MM_ANISOTROPIC); dc.SetWindowOrg(rect.BottomRight()); dc.SetViewportOrg(0, 0); dc.SetViewportExt(-1, -1); dc.SetWindowExt(1, 1); if(bSetDraw) { CMemDC mDC(&dc); // ********** Background *********** // Grid if (bActivateGrid) { CPen qLinePen(PS_SOLID, 1, RGB(0,139,0)); mDC->SelectObject(&qLinePen); // Grid - Horizontal lines mDC->MoveTo(1, 0); mDC->LineTo(rect.Width(), 0); int height = rect.Height(); int maxlines = height / (int)12.5; for (int i=1;i<=maxlines;i++){ int y_axis = (int)((double)i * 12.5); if (y_axis <= rect.Height()) { mDC->MoveTo(1, y_axis); mDC->LineTo(rect.Width(), y_axis); } } // Grid - Vertical lines mDC->MoveTo(0, 0); mDC->LineTo(0, rect.Height()); int width = rect.Width(); maxlines = width / (int)12.5; for (int i=1;i<=maxlines;i++){ int x_axis = (int)(((double)i * 12.5) - gridOffset); if (x_axis <= rect.Width()) { mDC->MoveTo(x_axis, 1); mDC->LineTo(x_axis, rect.Height()); } } qLinePen.DeleteObject(); } // *********** graphic component *********** // based on choice of graph type CPen qPolylinePen(PS_SOLID, 1, RGB(0, 255, 0)); switch (iGraphType) { case GRAPH_BARS: break; case GRAPH_LINES: { if (mPoints.capacity() == 1) { mDC- >SelectObject(qPolylinePen); m_fPoints* pointsline = &mPoints[0]; mDC->Polyline(&(*pointsline) [0], (int)pointsline->size()); //mDC->PolyPolyline() qPolylinePen.DeleteObject(); } } break; default: break; } GDI_FLUSH(); } dc.RestoreDC(save); } BOOL CMyDLL::OnEraseBkgnd(CDC* pDC) { return FALSE; } void CMyDLL::OnTimer(UINT TimerVal) { // ****** processing event ****** if (TimerVal == IDT_TIMER_0) { gridOffset++; if (gridOffset > 12.5) gridOffset = 0.0; Invalidate(); // to call OnDraw()/OnPaint() UpdateWindow(); } // call base class handler CWnd::OnTimer(TimerVal); } void CMyDLL::OnWindowPosChanged(WINDOWPOS* lpwndpos) { CWnd::OnWindowPosChanged(lpwndpos); } void CMyDLL::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class // In our case this is not needed - yet - so just drop through to // the base class // Get Size of Display area CWnd::PreSubclassWindow(); } void CMyDLL::set_MinMax(int minvalue, int maxvalue, int maxsizearray) { iMinRange = minvalue; iMaxRange = maxvalue; mSourceMaxSizeArray = maxsizearray; // getting max size array of each source which has to be fixed mPoints.resize(1); mPoints[0].resize(mSourceMaxSizeArray); CRect rc; GetClientRect(&rc); int iPointOfOrigin = rc.Width(); for (int i=mPoints[0].size()-1;i>0;i--) // initializing this first source to initial values { // which are consecutive integer values for X-axis mPoints[0].at(i).x = iPointOfOrigin--; // and bottom screen value for Y-axis mPoints[0].at(i).y = 0; } } BOOL CMyDLL::EnableTimer(BOOL tmrstate) { // *************************************************************************** // if enabled it's a realtime task manager, otherwise it'd be a graphical // representation of values passed from external source // *************************************************************************** if (tmrstate) { iTimerVal = SetTimer(IDT_TIMER_0, nElapse, 0); if (iTimerVal == 0) { MessageBox(_T("Unable to obtain timer!"), _T("IDT_TIMER_0"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); return FALSE; } } else { if (iTimerVal > 0) { if (!KillTimer(IDT_TIMER_0)) { // message MessageBox(_T("Unable to stop timer!"), _T("IDT_TIMER_0"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL); return FALSE; } } } return TRUE; } void CMyDLL::AddElement(UINT nX, UINT nY, const char * description, double value) { // add in value format because CPoint depends from resize... int i; CRect rc; ::GetClientRect(this->m_hWnd, &rc); if (nY+1 > mElements.size()) // check if I am adding a new source { mPoints.resize(nY +1); // setting the array to max size defined mPoints[nY].resize(mSourceMaxSizeArray); int iPointOfOrigin = 0; for (i=mPoints[nY].size()-1;i>0;i--) // initializing this first source to initial values { // which are consecutive integer values for X-axis mPoints[nY].at(i).x = iPointOfOrigin++; // and bottom screen value for Y-axis mPoints[nY].at(i).y = 0; } } // Now I add element value to the source if (scrollState) { // SHIFT-LEFT the array of POINTs to add new value rotate(mPoints[nY].begin(), mPoints[nY].begin()+1, mPoints[nY].end()); mPoints[nY].at(mPoints[nY].size() - 1).y = (LONG) ( (double)rand() / (RAND_MAX + 1) * (rc.bottom - 1) + 1 ); int iPointOfOrigin = rc.Width(); for (i=mPoints[nY].size()-1;i>0;i--) mPoints[nY].at(i).x = iPointOfOrigin--; } if (nY > mGraphElements.capacity()) { GraphElement single_element; single_element.description = description; single_element.color = mGraphColors.at(nY); mGraphElements.push_back(single_element); } Invalidate(); UpdateWindow(); } Thanks.... Ciao Luigi |