How to save the points in a rectangle to variables?

I need some help.

I am gonna save the points(x,y) to each corner in the rectangles I draw to variables.

How?

Here my code:

void CMFCOppgaveView::OnLButtonDown(UINT nFlags, CPoint point)
{
leftdown = point;

}

void CMFCOppgaveView::OnLButtonUp(UINT nFlags, CPoint point)
{
leftup = point;
Invalidate(false);


}

void CMFCOppgaveView::OnPaint()
{
CPaintDC dc(this);
rect = CRect(leftdown,leftup);
dc.Rectangle (rect);

rect2 = CRect(leftdown,leftup);
dc.Rectangle (rect2);



}
[635 byte] By [norwaymfc] at [2007-11-19 7:32:01]
# 1 Re: How to save the points in a rectangle to variables?
Create class member variables for your points...
VictorN at 2007-11-11 0:27:08 >
# 2 Re: How to save the points in a rectangle to variables?
You would better save the rectangles, not the points.

But I think already gstercken had an answer for you:
http://www.dev-archive.com/forum/showpost.php?p=1128993&postcount=6
szz at 2007-11-11 0:28:19 >
# 3 Re: How to save the points in a rectangle to variables?
I not any good at Mfc, so I dont understand all. Sorry for that.

But do you have an example who I can use?

Should I save the rectangles in OnPaint()?
norwaymfc at 2007-11-11 0:29:14 >
# 4 Re: How to save the points in a rectangle to variables?
I not any good at Mfc, so I dont understand all. Sorry for that.Well, what is it that you don't understand? Just ask - or better, look it up un MSDN. A very good introduction to MFC is "Programming Windows with MFC" by Jeff Prosise.

But do you have an example who I can use?Take a look at the MSDN sample DRAWCLI (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_drawcli.asp).

Should I save the rectangles in OnPaint()?No, you should only draw them in OnPaint. Actually, I wonder why you are using OnPaint() at all - in a CView derived class, you should use OnDraw() instead.
gstercken at 2007-11-11 0:30:20 >
# 5 Re: How to save the points in a rectangle to variables?
+ I think the best place to save rectangles would be in the OnLButtonUp right before Invalidate().
szz at 2007-11-11 0:31:16 >
# 6 Re: How to save the points in a rectangle to variables?
Ok, I have saved the points in rect_info, but how can I save all the rectangles I draw?

the code:

void CMFCOppgaveView::OnLButtonUp(UINT nFlags, CPoint point)
{
leftup = point;
CPoint rect_info;
rect_info = leftdown,leftup;


Invalidate(false);


}
norwaymfc at 2007-11-11 0:32:16 >
# 7 Re: How to save the points in a rectangle to variables?
You can use CArray(I think it's easier than CList)... So:

*declare a class member variable(preferably in your Doc class, but you can do it in your View class also-it's easier to access the array)
CArray<CRect, CRect> array;
*now you have to add your rengtangles, like I said before in OnLButtonUp:

array.Add(CRect(leftup, leftdown));
*in OnPaint (or OnDraw) you simply draw the rectangles with a for loop:

int length = array.GetSize(); //get the size of the array
for(int i=0;i<length;i++)
dc.Rectangle(array.GetAt(i));
szz at 2007-11-11 0:33:16 >
# 8 Re: How to save the points in a rectangle to variables?
Ok, I have saved the points in rect_info, but how can I save all the rectangles I draw?Why are you asking everything twice? I already told you in this thread ( http://www.dev-archive.com/forum/showthread.php?t=335864) how you could do that with a list.
gstercken at 2007-11-11 0:34:16 >
# 9 Re: How to save the points in a rectangle to variables?
I get errors:

h:\studier\brukergrensesnitt\obligatorisk\MFCOppgaveView.h(21): error C2146: syntax error : missing ';' before identifier 'array'

Why?

I try to declare the array...in the view.h
norwaymfc at 2007-11-11 0:35:24 >
# 10 Re: How to save the points in a rectangle to variables?
and this:

h:\studier\brukergrensesnitt\obligatorisk\MFCOppgaveView.h(21): error C2501: 'CMFCOppgaveView::CArray' : missing storage-class or type specifiers
norwaymfc at 2007-11-11 0:36:25 >
# 11 Re: How to save the points in a rectangle to variables?
You must include this header file:
#include <afxtempl.h>

*NOTE: you should do this in StdAfx.h, right after other includes.
szz at 2007-11-11 0:37:22 >
# 12 Re: How to save the points in a rectangle to variables?
Thats ok! Thanks...but how can I get the data out?
maybe this:

dc.TextOut (array.GetData());
norwaymfc at 2007-11-11 0:38:20 >
# 13 Re: How to save the points in a rectangle to variables?
Since the [ ] operator is defined, you can access elements in the "original" mode (array[7], which will be a CRect object) or you can use GetAt(), like I already posted before.
szz at 2007-11-11 0:39:25 >
# 14 Re: How to save the points in a rectangle to variables?
Ok, but nothing is happening, exept I can draw rectangles.

How can I write the points to the screen?

I use the code you typed...
norwaymfc at 2007-11-11 0:40:31 >
# 15 Re: How to save the points in a rectangle to variables?
I don't really understand what you mean by "How can I write the points to the screen?" ...
szz at 2007-11-11 0:41:24 >
# 16 Re: How to save the points in a rectangle to variables?
I mean that I will write the points out.

Eks.

The points to rectangle1 is: 100,170

For example on the statusbar or the bottom of the view
norwaymfc at 2007-11-11 0:42:23 >
# 17 Re: How to save the points in a rectangle to variables?
Oh, I see.

You have to convert point coordonates to strings.
For example this will write on the view the upper-left points' coordonates of the first rectangle:

CString sztr;
sztr.Format("(%d,%d)", array.GetAt(0).left, array.GetAt(0).top);
dc.TextOut(0, 0, sztr);
szz at 2007-11-11 0:43:32 >
# 18 Re: How to save the points in a rectangle to variables?
I need help.
I've start to learn how to write c++ on Borlandc++5.02.
now I want to arrange variables into a pyramid shape.
I really don't have any clue about it at all.
Thank you you guys in advance.
butlerthai at 2007-11-11 0:44:34 >
# 19 Re: How to save the points in a rectangle to variables?
I need help.
I've start to learn how to write c++ on Borlandc++5.02.
now I want to arrange variables into a pyramid shape.
I really don't have any clue about it at all.
Thank you you guys in advance.

What it is exactly what you don't know?
C syntax or the algorithm?
szz at 2007-11-11 0:45:32 >
# 20 Re: How to save the points in a rectangle to variables?
Thats was nice!!

With this code: Are the points on EVERY rectangles saved in the array?

int length = array.GetSize();
for(int i=0;i<length;i++)
dc.Rectangle(array.GetAt(i));

And if I will display the points to every rectangle I draw, can I do this?

convert.Format("(%d,%d)", array.GetAt(i).left, array.GetAt(i).top);
dc.TextOut(0, 0, convert);
norwaymfc at 2007-11-11 0:46:31 >
# 21 Re: How to save the points in a rectangle to variables?
Set variable from 1-9 if the variables is not 1-9 keep doing it, if it's right make it comeout like this :
if the variable is 3 1
121
12321

if the variable is 9

1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321

this is my code it's c++ anyway

thank you again :)

# include<stdio.h>
# include<conio.h>

void main()
{
int i,j,k,l;

do
{
printf("please input number between 1 and 9\n");
scanf("%d",&i);
}
while ( (i < 1) || (i > 9) );

printf("\n");
for (j=1;j<=i;j++)
{
printf("%d\n",j);
for (l=i-j;l>0;l--)
{
printf(" ");
for (k=1;k<=i;k++)
{
printf("%d",k);
}
}
}
getch();
}
butlerthai at 2007-11-11 0:47:37 >
# 22 Re: How to save the points in a rectangle to variables?
I need help.
I've start to learn how to write c++ on Borlandc++5.02.
now I want to arrange variables into a pyramid shape.
I really don't have any clue about it at all.Sorry, but how does your problem relate to the subject of this thread? Create a new thread for it (preferrably in the Non Visual C++ Issues (http://www.dev-archive.com/forum/forumdisplay.php?f=9) forum). Also, please use code tags when posing code.
gstercken at 2007-11-11 0:48:34 >