From: Stephen Myers on
Luigino wrote:
> Hello Steve,
>
>> I would try to separate the data collection and storage from the display
>> of the data. Sort of like the MFC document/view. Collect each data
>> point and store it in a vector (or deque) as a CPoint(). The x value
>> being time and y your measurement. I'd then let the CDC drawing methods
>> do the manipulations required to get from your data point to the
>> window's canvas.
>
> I'm trying to let CDC doing the hard stuff as you suggested.... just
> only a thing I would ask: Is there a way to assign the POINT.x the
> current time as LONG since time functions are most string functions
> and time_t is the time elapsed since 1970?...
>
> Thanks
> Ciao
> Luigi
I normally use GetTickCount() for this sort of thing. Save off an
initial time and then record future times as offsets. This gives
reasonable resolution and is easy to access.

// Initialization
m_BaseTime = GetTickCount();

....
// capture data
timeX = GetTickCount() - m_BaseTime;


This assumes that for the data acquisition, times don't need more than
10s of millisecond resolution.

Steve
From: Luigino on
I'm still keeping trying to solve...

Actually I've made this, in the OnInitDialog (it's a CDialog form) I
coded:

CRect rc;
GetClientRect(&rc);
time_t t;

for (int i=0; i<=rect.right; i++) {
POINT singlepoint;
t = time(NULL);
singlepoint.x = t;
singlepoint.y = (LONG)((double)rand() / RAND
CDC* pDC = GetWindowDC();
pDC->SetBkColor(RGB(0,0,0));
pDC->SetMapMode(MM_ANISOTROPIC);
t =
From: Luigino on
HI Steve,
I'm still keeping trying to solve...

Actually I've made this, in the OnInitDialog (it's a CDialog form) I
coded:

CRect rc;
GetClientRect(&rc);
time_t t;

for (int i=0; i<=rect.right; i++) {
POINT singlepoint;
t = time(NULL);
singlepoint.x = t;
singlepoint.y = (LONG)((double)rand() / (RAND_MAX + 1)*
(rect.bottom-1)+1);
myQueuePoints.push_back(singlepoint);
}

CDC* pDC = GetWindowDC();
pDC->SetBkColor(RGB(0,0,0));
pDC->SetMapMode(MM_ANISOTROPIC);
t = time(NULL);
HDC hdc = ::GetDC(m_hWnd);
SetWindowExtEx(hdc, t, rect.bottom, NULL);


and in the OnDraw(CDC* pDC) I implemented:

CMemDC mDC(pDC); <--- is an header of Keith Rule to prevent
flickering..
CRect rect;
GetClientRect(&rect);
mDC->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject
(BLACK_BRUSH)));
CPen qPen(PS_SOLID, 1, RGB(0,0,0));
mDC->SelectObject(qPen);
mDC->PolyLine(&myQueuePoints[0], myQueuePoints.size());
qPen.DeleteObject();

thought I have scaled correctly but it doesn't show anything... (in
the OnEraseBkgnd event I changed the return to FALSE)... maybe am I
missing something about SetWindowExtEx or similia?....

Thanks a lot
Ciao, Luigi
From: Stephen Myers on
Luigino wrote:
> HI Steve,
> I'm still keeping trying to solve...
>
> Actually I've made this, in the OnInitDialog (it's a CDialog form) I
> coded:
>
> CRect rc;
> GetClientRect(&rc);
> time_t t;
//
//
m_BaseTime = GetTickCount();
>
// unless rect is related to your data acquisition, don't use it here.
> for (int i=0; i<=rect.right; i++) {
> POINT singlepoint;
> t = time(NULL);
> singlepoint.x = t;
// t is likely a constant here. This loop is not long enough for t to
change.
> singlepoint.y = (LONG)((double)rand() / (RAND_MAX + 1)*
> (rect.bottom-1)+1);
> myQueuePoints.push_back(singlepoint);
> }
>
> CDC* pDC = GetWindowDC();
> pDC->SetBkColor(RGB(0,0,0));
> pDC->SetMapMode(MM_ANISOTROPIC);
> t = time(NULL);
> HDC hdc = ::GetDC(m_hWnd);
> SetWindowExtEx(hdc, t, rect.bottom, NULL);
// do the SetWindowExt() in the OnDraw, on mDC
>
>
> and in the OnDraw(CDC* pDC) I implemented:
>
> CMemDC mDC(pDC); <--- is an header of Keith Rule to prevent
> flickering..
//
// I would expect SetWindowExtEx() on mDC here
//
> CRect rect;
> GetClientRect(&rect);
> mDC->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject
> (BLACK_BRUSH)));
> CPen qPen(PS_SOLID, 1, RGB(0,0,0));
> mDC->SelectObject(qPen);
> mDC->PolyLine(&myQueuePoints[0], myQueuePoints.size());
> qPen.DeleteObject();

You need to do a bitblt() to get the bitmapped data from mDC into pDC's
bitmap
>
> thought I have scaled correctly but it doesn't show anything... (in
> the OnEraseBkgnd event I changed the return to FALSE)... maybe am I
> missing something about SetWindowExtEx or similia?....
>
> Thanks a lot
> Ciao, Luigi
From: Joseph M. Newcomer on
See below...
On Fri, 29 Jan 2010 07:45:27 -0800 (PST), Luigino <npuleio(a)rocketmail.com> wrote:

>HI Steve,
>I'm still keeping trying to solve...
>
>Actually I've made this, in the OnInitDialog (it's a CDialog form) I
>coded:
>
>CRect rc;
>GetClientRect(&rc);
>time_t t;
>
>for (int i=0; i<=rect.right; i++) {
> POINT singlepoint;
> t = time(NULL);
> singlepoint.x = t;
> singlepoint.y = (LONG)((double)rand() / (RAND_MAX + 1)*
>(rect.bottom-1)+1);
> myQueuePoints.push_back(singlepoint);
>}
>
>CDC* pDC = GetWindowDC();
****
There is something deeply suspicious here about getting a window DC. Then, having gotten
the DC, you set mapping modes, set other parameters, and of course, the DC is never going
to be accessed again, so why bother? And, oh yes, you have now leaked a DC, since you
never free it, so it sits there, being completely useless. You only want a Window DC if
you are drawing the entire window, including borders, captions, etc.

Get rid of ALL of this DC-related code; it has no business being here. It does nothing,
and serves no purpose.
****
>pDC->SetBkColor(RGB(0,0,0));
>pDC->SetMapMode(MM_ANISOTROPIC);
>t = time(NULL);
>HDC hdc = ::GetDC(m_hWnd);
***
This code is even worse. Why in the world would you call ::GetDC for anything? Let alone
call it in OnIntDialog, where it does nothing useful? And you've leaked another DC, that
will never be seen again. So whatever settings you do affect this DC, and this DC alone,
and it is never, ever seen again by anyone!

If you were to need a DC to a specific window, for example, for a rubber-band line or to
compute some other parameter such as a text size, you would do
CClientDC dc(this);
There are almost no GDI calls that you will need that work with raw GDI. Due to an
unfortunately oversight which has not been rectified in nearly 20 years, SetGraphicsMode
is one of them.

But generally assume under normal conditions that writing ::GetDC, or calling CWnd::GetDC,
is a programming error.
****
>SetWindowExtEx(hdc, t, rect.bottom, NULL);
****
And what possible relationship does the rectangle at OnInitDialog time have to the
rectangle at drawing time? You do not want to compute these parameters until you have the
actual window to draw into. In some misguided attempt at "optimization" you may think
this saves some time, but it saves no time of any consequence whatsoever. Get rid of this
code as well.
****
>
>
>and in the OnDraw(CDC* pDC) I implemented:
>
>CMemDC mDC(pDC); <--- is an header of Keith Rule to prevent
>flickering..
>CRect rect;
>GetClientRect(&rect);
>mDC->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject
>(BLACK_BRUSH)));
>CPen qPen(PS_SOLID, 1, RGB(0,0,0));
>mDC->SelectObject(qPen);
>mDC->PolyLine(&myQueuePoints[0], myQueuePoints.size());
>qPen.DeleteObject();
>
>thought I have scaled correctly but it doesn't show anything... (in
>the OnEraseBkgnd event I changed the return to FALSE)... maybe am I
>missing something about SetWindowExtEx or similia?....
****
You have not set the mapping mode or the window extent or viewport extent. These must be
done not to some randomly-chosen and never-seen-again DC in OnInitDialog/OnInitialUpdate,
but to the CDC* that is passed into OnDraw! Fix you code so you have the correct
coordinate system at the point where you are drawing.

In addition to this, your idea of keeping screen resolution in the Registry is complete
nonsense. The screen resolution could change at any time, without warning. You shouldn't
need it at all in this case, because you should be scaling to the actual data, but if you
need it, use CDC::GetDeviceCaps. And I don't think any display in the last 10 years had
72dpi (this was low-resolution VGA, not seen since the late 1980s; 640x480 at 72dpi was an
8.8*6.6, or an 11" diagonal screen area, not seen in modern programming; most modern
screens are either 96dpi or 100dpi). But the resolution doesn't matter. What you should
be tracking is the max/min of the data, and the GetClientRect of the area you are drawing
in as determined in the OnDraw/OnPaint handler the instant before you start drawing.
Screen resolution does not matter at all in this case.
joe
****
>
>Thanks a lot
>Ciao, Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm