Google Search

Saturday, January 29, 2011

ActiveX Control Dialog Container 600459– Visual Programming Anna University lab manual download fourth semester


ActiveX Control Dialog Container 600459– Visual Programming Anna University lab manual download fourth semester

Aim:

            To write a VC++ program to build an application that uses a Calendar control in a dialog using activeX.

Logical Description:

This project is to generate the calendar control in a dialog using ActiveX. An ActiveX control is a software module that plugs into your C++ program the same way a Windows control does. ActiveX Controls methods are like functions. A method has a symbolic name, a set of parameters, and a return value. The MSCal.ocx control is a popular Microsoft ActiveX Calendar control that's probably already installed and registered on your computer.

MFC and ClassWizard support ActiveX controls both in dialogs and as "child windows." Open the dialog, enter a date in the three edit controls, and then click the Select Date button. Click the Next Week button. Try moving the selected date directly to a new month, and observe the message box that is triggered by the NewMonth event. Watch for the final date in another message box when you click OK. Press the F1 key for help on the Calendar control.

Steps for building the calendar application:
1.      Verify that the Calendar control is registered.
If the control does not appear in the Visual C++ Gallery's Registered ActiveX Controls page, copy the files MSCal.ocx, MSCal.hlp, and MSCal.cnt to your system directory and register the control by running the REGCOMP program.
2.      Run AppWizard to produce \vcpp32\ ActiveX.
a.       Select Single Document in Step 1
b.      In step3, make sure the ActiveX Controls option is selected.
c.       Deselect Printing and Print Preview in step 4 of 6.
d.      In the AppWizard Step 3 dialog, make sure the ActiveX Controls option is selected.
  1. Install the Calendar control in the Calendar project.

a.       Choose Add To Project from Visual C++'s Project menu, and then choose Components And Controls.
b.      Choose Registered ActiveX Controls, and then choose Calendar Control 8.0.
Aim:

            To write a VC++ program to build an application that uses a Calendar control in a dialog using activeX.

Logical Description:

This project is to generate the calendar control in a dialog using ActiveX. An ActiveX control is a software module that plugs into your C++ program the same way a Windows control does. ActiveX Controls methods are like functions. A method has a symbolic name, a set of parameters, and a return value. The MSCal.ocx control is a popular Microsoft ActiveX Calendar control that's probably already installed and registered on your computer.

MFC and ClassWizard support ActiveX controls both in dialogs and as "child windows." Open the dialog, enter a date in the three edit controls, and then click the Select Date button. Click the Next Week button. Try moving the selected date directly to a new month, and observe the message box that is triggered by the NewMonth event. Watch for the final date in another message box when you click OK. Press the F1 key for help on the Calendar control.

Steps for building the calendar application:
1.      Verify that the Calendar control is registered.
If the control does not appear in the Visual C++ Gallery's Registered ActiveX Controls page, copy the files MSCal.ocx, MSCal.hlp, and MSCal.cnt to your system directory and register the control by running the REGCOMP program.
2.      Run AppWizard to produce \vcpp32\ ActiveX.
a.       Select Single Document in Step 1
b.      In step3, make sure the ActiveX Controls option is selected.
c.       Deselect Printing and Print Preview in step 4 of 6.
d.      In the AppWizard Step 3 dialog, make sure the ActiveX Controls option is selected.
  1. Install the Calendar control in the Calendar project.

a.       Choose Add To Project from Visual C++'s Project menu, and then choose Components And Controls.
b.      Choose Registered ActiveX Controls, and then choose Calendar Control 8.0.
4.      Edit the Calendar control class to handle help messages.
a.       Add Calendar.cpp to the following message map code:
BEGIN_MESSAGE_MAP(CCalendar, CWnd)
    ON_WM_HELPINFO()
END_MESSAGE_MAP()
b.      In the same file, add the OnHelpInfo function:
BOOL CCalendar::OnHelpInfo(HELPINFO* pHelpInfo) 
{    
    // Edit the following string for your system
    ::WinHelp(GetSafeHwnd(), 
             "c:\\winnt\\system32\\mscal.hlp",HELP_FINDER, 0);
    return FALSE;
}
c.       In Calendar.h, add the function prototype and declare the message map:
protected:
     afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
     DECLARE_MESSAGE_MAP()
The OnHelpInfo function is called if the user presses the F1 key when the Calendar control has the input focus. We have to add the message map code by hand because ClassWizard doesn't modify generated ActiveX classes.
5.      Use the dialog editor to create a new dialog resource.
    1. Choose Resource from Visual C++'s Insert menu, and then choose Dialog.
    2. The dialog editor assigns the ID IDD_DIALOG1 to the new dialog.
    3. Next change the ID to IDD_ACTIVEXDIALOG, change the dialog caption to ActiveX Dialog, and set the dialog's Context Help property (on the More Styles page).
    4. Accept the default OK and Cancel buttons with the IDs IDOK and IDCANCEL, and then add the other controls. 
      1. Make the Select Date button as the default button.
      2. Drag the Calendar control from the control palette.
      3. Then set an appropriate tab order.
      4. Assign control IDs as shown in the following table.
      Control
      ID
      Calendar control
      IDC_CALENDAR1
      Select Date button
      IDC_SELECTDATE
      Edit control
      IDC_DAY
      Edit control
      IDC_MONTH
      Edit control
      IDC_YEAR
      Next Week button
      IDC_NEXTWEEK
      5.      Use ClassWizard to create the CActiveXDialog class.
                                           a.            If you run ClassWizard directly from the dialog editor window, it will know that you want to create a CDialog-derived class based on the IDD_ACTIVEXDIALOG template.
                                          b.            Simply accept the default options, and name the class CActiveXDialog.
                                           c.            Click on the ClassWizard Message Maps tab, and then add the message handler functions shown in the table below.
                                          d.            To add a message handler function, click on an object ID, click on a message, and click the Add Function button.
                                           e.            If the Add Member Function dialog box appears, type the function name and click the OK button.
      Object ID
      Message
      Member Function
      CActiveXDialog
      WM_INITDIALOG
      OnInitDialog (virtual function)
      IDC_CALENDAR1
      NewMonth (event)
      OnNewMonthCalendar1
      IDC_SELECTDATE
      BN_CLICKED
      OnSelectDate
      IDC_NEXTWEEK
      BN_CLICKED
      OnNextWeek
      IDOK
      BN_CLICKED
      OnOK (virtual function)
       
      5.      Edit the CActiveXDialog class.
      1. Add the m_varValue and m_BackColor data members.
      2.  Edit the code for the five handler functions OnInitDialog, nNewMonthCalendar1, OnSelectDate, OnNextWeek, and OnOK.
      6.      Add the following boldface code in the ACTIVEXDIALOG.H
      Public:
                              COleVariant m_varValue;
                              unsigned long m_BackColor;
      Note: declare these 2 variables at the end of the Dialog Data section.

      7.      Edit the ACTIVEXDIALOG.CPP
      a.       Add the following boldface code.
      CActiveXDialog::CActiveXDialog(CWnd* pParent /*=NULL*/)
                                    : CDialog(CActiveXDialog::IDD, pParent)
      {
          // {{AFX_DATA_INIT (CActiveXDialog)
          m_sDay = 0;
          m_sMonth = 0;
          m_sYear = 0;
          //}}AFX_DATA_INIT
          m_BackColor = 0x8000000F;
      }
       
      void CActiveXDialog::DoDataExchange(CDataExchange* pDX)
      {
          CDialog::DoDataExchange(pDX);
          //{{AFX_DATA_MAP(CActiveXDialog)
          DDX_Control(pDX, IDC_CALENDAR1, m_calendar);
          DDX_Text(pDX, IDC_DAY, m_sDay);
          DDX_Text(pDX, IDC_MONTH, m_sMonth);
          DDX_Text(pDX, IDC_YEAR, m_sYear);
          //}}AFX_DATA_MAP
          DDX_OCColor(pDX, IDC_CALENDAR1, DISPID_BACKCOLOR, 
                                                                                     m_BackColor);
      }
      BOOL CActiveXDialog::OnInitDialog() 
      {
          CDialog::OnInitDialog();
          m_calendar.SetValue(m_varValue); // no DDX for VARIANTs
          return TRUE;  // return TRUE unless you set the focus to a control
                        // EXCEPTION: OCX Property Pages should return FALSE
       
      }
      void CActiveXDialog::OnNewMonthCalendar1() 
      {
      AfxMessageBox("EVENT:  CActiveXDialog::OnNewMonthCalendar1");
      }
      void CActiveXDialog::OnSelectDate() 
      {
          CDataExchange dx(this, TRUE);
          DDX_Text(&dx, IDC_DAY, m_sDay);
          DDX_Text(&dx, IDC_MONTH, m_sMonth);
          DDX_Text(&dx, IDC_YEAR, m_sYear);
          m_calendar.SetDay(m_sDay);
          m_calendar.SetMonth(m_sMonth);
          m_calendar.SetYear(m_sYear);
      }
      void CActiveXDialog::OnNextWeek() 
      {
          m_calendar.NextWeek();    
      }
       
      void CActiveXDialog::OnOK() 
      {    
          CDialog::OnOK();
          m_varValue = m_calendar.GetValue(); // no DDX for VARIANTs
      }
      8.      The OnSelectDate function is called when the user clicks the Select Date button. The function gets the day, month, and year values from the three edit controls and transfers them to the control's properties. ClassWizard can't add DDX code for the BackColor property, so you must add it by hand. In addition, there's no DDX code for VARIANT types, so you must add code to the OnInitDialog and OnOK functions to set and retrieve the date with the control's Value property.

      9.      Connect the dialog to the view.

      a.       Use ClassWizard to map the WM_LBUTTONDOWN message, and then edit the handler function as follows:

      void ActiveXView::OnLButtonDown(UINT nFlags, CPoint point) 
      {
          CActiveXDialog dlg;
          dlg.m_BackColor = RGB(255, 251, 240); // light yellow
          COleDateTime today = COleDateTime::GetCurrentTime();
          dlg.m_varValue = COleDateTime(today.GetYear(), today.GetMonth(),
                                        today.GetDay(), 0, 0, 0);
          if (dlg.DoModal() == IDOK) {
              COleDateTime date(dlg.m_varValue);
              AfxMessageBox(date.Format("%B %d, %Y"));
          }
      }
      The code sets the background color to light yellow and the date to today's date, displays the modal dialog, and reports the date returned by the Calendar control.
      ·         Then need to include the following in ActiveXView.cpp.
      #include “ActiveXDialog.h”
    5. Edit the virtual OnDraw function in the file ActiveXView.cpp.

    1. To prompt the user to press the left mouse button, replace the code in the view class OnDraw function with this single line:

                  pDC->TextOut(0, 0, "Press the left mouse button here




0 comments:

Post a Comment