Dynamic Controls 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

Dynamic Controls 600459– Visual Programming Anna University lab manual download fourth semester


Aim:

          To write a VC++ program to implement the dynamic controls

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 mapping create dynamically controls such as label, edit box and button

Algorithm:

1.      Start the process
2.      Initially control starts from object creation
3.      Next it calls the myapp class which in turn calls the constructor
4.      The constructor creates an Output:window
5.      Create name, address, phone and password using WS_VISIBLE, WS_CHILD & SS_CENTREIMAGE.
6.      Define respective message maps for the corresponding functions.
7.      Execute the program
8.      Stop the process

Source Code:

#include<afxwin.h>
#include<ctype.h>
#define EDIT_NUM 100
#define BUT_OK 103
class myedit:public CEdit
{
public:
            void OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)
            {
                        if(isdigit(nChar))
                                    CEdit::OnChar(nChar,nRepCnt,nFlags);
                        else
                                    ::MessageBeep(0);
            }
            DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myedit,CEdit)
ON_WM_CHAR()
END_MESSAGE_MAP()
class mywin:public CFrameWnd
{
private:
            myedit edit_num;
            CStatic label;
            CButton okbut;
public:
            mywin()
            {
                        Create(NULL,"Edit box");
            }
            int OnCreate(LPCREATESTRUCT lp)
            {
                        RECT rect;
                        rect.top=10;
                        rect.left=10;
                        rect.right=130;
                        rect.bottom=30;
                        label.Create("Enter numbers",WS_CHILD|WS_VISIBLE|WS_BORDER,rect,this);
                        rect.top=10;
                        rect.left=131;
                        rect.right=250;
                        rect.bottom=30;
            edit_num.Create(WS_CHILD|WS_VISIBLE|WS_BORDER,rect,this,EDIT_NUM);
                        edit_num.LimitText(10);
                        rect.top=40;
                        rect.left=110;
                        rect.right=150;
                        rect.bottom=60;
            okbut.Create("&OK",WS_CHILD|WS_VISIBLE|WS_BORDER|BS_PUSHBUTTON,rect,this,BUT_OK);
                        edit_num.SetFocus();
                        return 0;
            }
            void OnButOk()
            {
                        char buff[25];
                        edit_num.GetWindowText(buff,25);
                        MessageBox(buff,"Data retrieved");
            }
            DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(mywin,CFrameWnd)
ON_COMMAND(BUT_OK,OnButOk)
ON_WM_CREATE()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
            BOOL InitInstance()
            {
                        mywin *p;
                        p=new mywin();
                        m_pMainWnd=p;
                        p->ShowWindow(SW_SHOWNORMAL);
                        return true;
            }
};
myapp A;

No comments:

Post a Comment