Visual C++ Program for the Implementation of ActiveX Controls | CS1255 - Visual Programming Laboratory


AIM:
To write a Visual C++ Program for the Implementation of ActiveX Controls in CS1255 - Visual Programming Lab.

SOURCE CODE:
CalendarView.cpp: implementation of the CCalendarView class
#include "stdafx.h"
#include "Calendar.h"
#include "CalendarDoc.h"
#include "CalendarView.h"
#include "ACXDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCalendarView
IMPLEMENT_DYNCREATE(CCalendarView, CView)
BEGIN_MESSAGE_MAP(CCalendarView, CView)
    //{{AFX_MSG_MAP(CCalendarView)
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)

    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalendarView construction/destruction

CCalendarView::CCalendarView()
{
    // TODO: add construction code here
}
CCalendarView::~CCalendarView()
{
}

BOOL CCalendarView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCalendarView drawing

void CCalendarView::OnDraw(CDC* pDC)
{
    CCalendarDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CCalendarView printing

BOOL CCalendarView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // default preparation
    return DoPreparePrinting(pInfo);
}

void CCalendarView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add extra initialization before printing
}

void CCalendarView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CCalendarView diagnostics

#ifdef _DEBUG
void CCalendarView::AssertValid() const
{
    CView::AssertValid();
}

void CCalendarView::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}

CCalendarDoc* CCalendarView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCalendarDoc)));
    return (CCalendarDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCalendarView message handlers

void CCalendarView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ACXDLG d;
d.m_Backcolor=RGB(206,206,240);
COleDateTime today = COleDateTime::GetCurrentTime();
d.m_varValue=COleDateTime(today.GetYear(),today.GetMonth(),today.GetDay(),0,0,0);
if(d.DoModal()==IDOK)
{
COleDateTime date(d.m_varValue);
AfxMessageBox(date.Format("%B, %d,%y"));
}   
CView::OnLButtonDown(nFlags, point);
}

ACXDLG.cpp: implementation file
#include "stdafx.h"
#include "Calendar.h"
#include "ACXDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ACXDLG dialog

ACXDLG::ACXDLG(CWnd* pParent /*=NULL*/)
    : CDialog(ACXDLG::IDD, pParent)
{
    //{{AFX_DATA_INIT(ACXDLG)
    m_d = 0;
    m_m = 0;
    m_y = 0;
    //}}AFX_DATA_INIT
    m_Backcolor=0x8000000F;
}

void ACXDLG::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(ACXDLG)
    DDX_Control(pDX, IDC_Calendar1, m_calendar);
    DDX_Text(pDX, IDC_EDIT1, m_d);
    DDX_Text(pDX, IDC_EDIT2, m_m);
    DDX_Text(pDX, IDC_EDIT3, m_y);
    //}}AFX_DATA_MAP
   DDX_OCColor(pDX, IDC_Calendar1,DISPID_BACKCOLOR,m_Backcolor);
}

BEGIN_MESSAGE_MAP(ACXDLG, CDialog)
    //{{AFX_MSG_MAP(ACXDLG)
    ON_BN_CLICKED(IDC_BUTTON1, OnSetdate)
    ON_BN_CLICKED(IDC_BUTTON2, Onnextweek)
    ON_BN_CLICKED(IDC_BUTTON3, Onnextday)
    ON_BN_CLICKED(IDC_BUTTON4, Onnextmonth)
    ON_BN_CLICKED(IDC_BUTTON5, Onnextyear)
    ON_BN_CLICKED(IDC_BUTTON6, Onpreviousday)
    ON_BN_CLICKED(IDC_BUTTON7, Onpreviousweek)
    ON_BN_CLICKED(IDC_BUTTON8, Onpreviousmonth)
    ON_BN_CLICKED(IDC_BUTTON9, Onpreviousyear)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ACXDLG message handlers

void ACXDLG::OnSetdate()
{
    // TODO: Add your control notification handler code here
    CDataExchange ds(this,TRUE);
    DDX_Text(&ds, IDC_EDIT1, m_d);
    DDX_Text(&ds, IDC_EDIT2, m_m);
    DDX_Text(&ds, IDC_EDIT3, m_y);
    m_calendar.SetDay(m_d);
    m_calendar.SetMonth(m_m);
    m_calendar.SetYear(m_y);
}

BEGIN_EVENTSINK_MAP(ACXDLG, CDialog)
    //{{AFX_EVENTSINK_MAP(ACXDLG)
    ON_EVENT(ACXDLG, IDC_Calendar1, 3 /* NewMonth */, OnNewMonthCalendar1, VTS_NONE)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void ACXDLG::OnNewMonthCalendar1()
{
    // TODO: Add your control notification handler code here
 }

void ACXDLG::Onnextweek()
{
    // TODO: Add your control notification handler code here
    m_calendar.NextWeek();
 }

void ACXDLG::Onnextday()
{
    // TODO: Add your control notification handler code here
    m_calendar.NextDay();
}

void ACXDLG::Onnextmonth()
{
    // TODO: Add your control notification handler code here
    m_calendar.NextMonth();
}

void ACXDLG::Onnextyear()
{
    // TODO: Add your control notification handler code here
    m_calendar.NextYear();  
}

void ACXDLG::Onpreviousday()
{
    // TODO: Add your control notification handler code here
    m_calendar.PreviousDay();
}

void ACXDLG::Onpreviousweek()
{
    // TODO: Add your control notification handler code here
    m_calendar.PreviousWeek();   
}

void ACXDLG::Onpreviousmonth()
{
    // TODO: Add your control notification handler code here
    m_calendar.PreviousMonth();   
}

void ACXDLG::Onpreviousyear()
{
    // TODO: Add your control notification handler code here
    m_calendar.PreviousYear(); 
}

ACXDLG.h:

//{{AFX_INCLUDES()
#include "calendar.h"
//}}AFX_INCLUDES
#if !defined(AFX_DLG_H__6DCD5F92_6E06_42A6_95CA_55657A3AC35B__INCLUDED_)
#define AFX_DLG_H__6DCD5F92_6E06_42A6_95CA_55657A3AC35B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ACXDLG.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// ACXDLG dialog

class ACXDLG : public CDialog
{
// Construction
public:
    ACXDLG(CWnd* pParent = NULL);   // standard constructor


// Dialog Data
    //{{AFX_DATA(ACXDLG)
    enum { IDD = IDD_DIALOG1 };
    CCalendar    m_calendar;
    short    m_d;
    short    m_m;
    short    m_y;
   
    //}}AFX_DATA
    COleVariant m_varValue;
    unsigned long m_Backcolor;


// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(ACXDLG)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:

    // Generated message map functions
    //{{AFX_MSG(ACXDLG)
    afx_msg void OnSetdate();
    afx_msg void OnNewMonthCalendar1();
    afx_msg void Onnextweek();
    afx_msg void Onnextday();
    afx_msg void Onnextmonth();
    afx_msg void Onnextyear();
    afx_msg void Onpreviousday();
    afx_msg void Onpreviousweek();
    afx_msg void Onpreviousmonth();
    afx_msg void Onpreviousyear();
    DECLARE_EVENTSINK_MAP()
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLG_H__6DCD5F92_6E06_42A6_95CA_55657A3AC35B__INCLUDED_)

OUTPUT:
Previous
Next Post »

Still not found what you are looking for? Try again here.