Monday, April 1, 2013

visual c++(mfc) program to display the coordinates

visual c++(mfc) program to display the coordinates

#include<afxwin.h>
class myframe:public CFrameWnd
{
public:
          myframe();
          void OnLButtonDown(UINT,CPoint);
          DECLARE_MESSAGE_MAP()
};
         myframe::myframe()
          {
            Create(0,"my mfc",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VSCROLL|WS_HSCROLL,CRect(20,20,200,200));
          }
void myframe::OnLButtonDown(UINT n,CPoint p)
          {
              char s1[20],s2[20];
              CString s;
              CClientDC dc(this);
              s=strcat(itoa(p.x,s1,10),itoa(p.y,s2,10));
              dc.TextOut(p.x,p.y,s);
          }                          // visual c++(mfc) program to display the coordinates

BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
       virtual BOOL InitInstance()
       {
         m_pMainWnd=new myframe();
         m_pMainWnd->ShowWindow(1);
         m_pMainWnd->UpdateWindow();
         return TRUE;
       }
};
myapp app;

Coordinates (x, y) are used to give positions on a graph. The x-axis is across, the y-axis is vertical.


  • The point (0,0) is called the origin.
  • The horizontal axis is the x-axis.
  • The vertical axis is the y-axis
The x-axis is horizontal, and the y-axis is vertical.
One way to remember which axis is which is 'x is a cross so the x axis is across'.

Coordinates

Coordinates are written as two numbers, separated by a comma and contained within round brackets. For example, (2, 3), (5, 7) and (4, 4)
  • The first number refers to the x coordinate.
  • The second number refers to the y coordinate.
Coordinates are written alphabetically - so x comes before y (x, y). One way to remember is 'you go along the hallway before you go up the stairs'


Plotting coordinates

When describing coordinates, always count from the origin.
For example, to describe the position of point A, start at the origin and move two squares in the horizontal (x) direction. Then move three squares in the vertical (y) direction.

No comments:

Post a Comment