Google Search

Saturday, January 29, 2011

Tree View Creation 600459– Visual Programming Anna University lab manual download fourth semester


 Tree View Creation 600459– Visual Programming Anna University lab manual download fourth semester

Aim:
            To write a Visual C++ program for creating a Tree View Control using win32 application.

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. 

Algorithm:

  1. Start the Process
  2. Create an object for an class which inherits CWinApp
  3. The object access InitInstance() function
  4. Create a pointer object for the class which inherits CFrameWindow by allocating the memory to the object
  5. Show the created window using SW_SHOWNORMAL
  6. Stop the process
Source Code:
#include<afxwin.h>
#include<afxcmn.h>
class myframe:public CFrameWnd
{
private:
            CTreeCtrl tree;
public:
            myframe()
            {
                        Create(0,"Tree view control");
            }
            int OnCreate(LPCREATESTRUCT I)
            {
                        HTREEITEM lang,opersys,c,cpp,java;
                        CFrameWnd::OnCreate(I);
                        tree.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS,CRect(30,30,300,350),this,1);
                        lang=tree.InsertItem("Computer languages",TVI_ROOT,TVI_SORT);
                        c=tree.InsertItem("C",lang,TVI_SORT);
                        tree.InsertItem("TC",c);
                        tree.InsertItem("QC",c);
                        tree.InsertItem("MSC",c);
                        cpp=tree.InsertItem("c++",lang,TVI_SORT);
                        tree.InsertItem("VC++",cpp);
                        tree.InsertItem("Borland c++",cpp);
                        java=tree.InsertItem("java",lang,TVI_SORT);
                        tree.InsertItem("VJ++",java);
                        tree.InsertItem("Symantec cafe",java);
                        tree.InsertItem("Sun JDK",java);
                        opersys=tree.InsertItem("operating systems",TVI_ROOT,TVI_SORT);
                        tree.InsertItem("win 3.1",opersys);
                        tree.InsertItem("win 95",opersys);
                        tree.InsertItem("win NT",opersys);
                        return 0;
            }
            int OnNotify(WPARAM w,LPARAM I,LRESULT *r)
            {
                        HTREEITEM h;
                        CString str;
                        CWnd::OnNotify(w,I,r);
                        NM_TREEVIEW *p=(NM_TREEVIEW *)I;
                        if(p->hdr.code==TVN_SELCHANGED)
                        {
                                    h=tree.GetSelectedItem();
                                    str=tree.GetItemText(h);
                                    MessageBox(str,"you have selected");
                        }
                        return 1;
            }
            DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
            int InitInstance()
            {
                        myframe *p;
                        p=new myframe;
                        p->ShowWindow(3);
                        m_pMainWnd=p;
                        return 1;
            }
};
myapp a;


0 comments:

Post a Comment