Graphical Device Interface 600459– Visual Programming Anna University lab manual download fourth semester - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, January 29, 2011

Graphical Device Interface 600459– Visual Programming Anna University lab manual download fourth semester

Graphical Device Interface 600459– Visual Programming Anna University lab manual download fourth semester


Aim:

            To write a Visual C++ program which uses the GDI tools

Logical Description:                                                                                                 

            The program starts with object creation. After initializing the instance, the user created window is assigned as main window. Using Show window option project user created window.  Using message map create a pen & brush. Using that pen & brush draw objects.


Algorithm:

  1. Start the Process
  2. Create an object for an myapp class. Invoke InitInstance function and create object for mywin to call the constructor mywin.
  3. A window is created by calling the create function which resides  inside the constructor
  4. Inside message map write the code for GDI objects like pen & brush .
  5. Show the created window using SW_SHOWNORMAL
  6. Stop the process

Source Code:

#include <afxwin.h>
class mywnd : public CFrameWnd
{
public:
     mywnd()
       {
            Create(0,"MFC");
       }
DECLARE_MESSAGE_MAP()
void OnLButtonDown(UINT f,CPoint p)
{
       CPen pen;
       CBrush brush;
       CClientDC dc(this);
       pen.CreatePen(PS_SOLID, 5,RGB(200,120,130));
       brush.CreateHatchBrush(HS_VERTICAL,RGB(50,50,130));
       dc.SelectObject(pen);
       dc.SelectObject(brush);
 dc.Rectangle(200,200,300,300);
}
 void OnRButtonDown(UINT f,CPoint p)
 {
     CPen pen;
     CBrush brush;
     CClientDC dc(this);
     pen.CreatePen(PS_SOLID, 5,RGB(123,134,130));
     brush.CreateHatchBrush(HS_HORIZONTAL,RGB(150,150,230));
     dc.SelectObject(pen);
     dc.SelectObject(brush);
     dc.Rectangle(50,50,200,200);
}
                                                                                                                                  
};
  

BEGIN_MESSAGE_MAP(mywnd,CFrameWnd)
   ON_WM_LBUTTONDOWN()
   ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()

   
class myapp : public CWinApp
{
public:
  BOOL InitInstance()
    {
       mywnd *p;
       p = new mywnd();
       m_pMainWnd = p;
       p->ShowWindow(SW_SHOWNORMAL);
       return true;
     }
};
myapp A;




No comments:

Post a Comment