You are on page 1of 6

Assignment No.

7
Assignment Name: Develop a program to create and use Active X object.

Class: BCA III Roll No. :

Date : Seat No. :

Steps :
1. 2. 3. 4. 5. 6. Select Project | Add to Project | Components and controls from the Visual C++ Menu. In the components and control gallery dialog navigate to the Registered ActiveX controls Folder. Select the control you want to register, such as Microsoft FlexGrid Control and click the Insert Button. Click OK on the message box asking whether you want to insert this component in your project. On the confirm classes dialog, click the OK button to add the C++ classes specified. Click the close button on the components and controls gallery dialog to finish adding controls to your project. The FlexGrid control should have been added to the control palette for your dialog window.

7.

Coding:

void CActiveXDlg::LoadData() { int liCount; CString lsAmount; srand((unsigned)time(NULL)); for (liCount = m_ctlFGrid.GetFixedRows(); liCount < m_ctlFGrid.GetRows(); liCount++) { m_ctlFGrid.SetTextArray(GenID(liCount, 0), RandomStringValue(0)); m_ctlFGrid.SetTextArray(GenID(liCount, 1), RandomStringValue(1));

m_ctlFGrid.SetTextArray(GenID(liCount, 2), RandomStringValue(2)); lsAmount.Format(%5d.00, rand()); m_ctlFGrid.SetTextArray(GenID(liCount, 3), lsAmount); } m_ctlFGrid.SetMergeCol(0, TRUE); m_ctlFGrid.SetMergeCol(1, TRUE); m_ctlFGrid.SetMergeCol(2, TRUE);

DoSort(); }

int CActiveXDlg::GenID(int m_iRow, int m_iCol) { int liCols = m_ctlFGrid.GetCols(); return (m_iCol + liCols * m_iRow); } CString CActiveXDlg::RandomStringValue(int m_iColumn) { CString lsStr; int liCase; switch (m_iColumn) { case 0: liCase = (rand() % 5); switch (liCase) { case 0: lsStr = Northwest;

break; case 1: lsStr = Southwest; break; case 2: lsStr = Midwest; break; case 3: lsStr = Northeast; break; default: lsStr = Southeast; break; } break; case 1: liCase = (rand() % 5); switch (liCase)

{ case 0: lsStr = Dodads; break; case 1: lsStr = Thingamajigs; break; case 2: lsStr = Whatchamacallits;

break; case 3: lsStr = Round Tuits; break; default: lsStr = Widgets; break; } break; case 2: liCase = (rand() % 4); switch (liCase) { case 0: lsStr = Dore; break; case 1: lsStr = Harvey; break; case 2: lsStr = Pogo; break; default:

lsStr = Nyra; break; } break;

} return lsStr; } void CActiveXDlg::DoSort() { m_ctlFGrid.SetCol(0); m_ctlFGrid.SetColSel((m_ctlFGrid.GetCols() - 1)); m_ctlFGrid.SetSort(1); }

BOOL CActiveXDlg::OnInitDialog() { CDialog::OnInitDialog(); LoadData(); }

void CActiveXDlg::OnMouseDownMsfgrid(short Button, short Shift, long x, long y) { If (m_ctlFGrid.GetMouseRow() != 0) { m_iMouseCol = 0; return; } m_iMouseCol = m_ctlFGrid.GetMouseCol(); } void CActiveXDlg::OnMouseUpMsfgrid(short Button, short Shift, long x, long y) { if (m_iMouseCol == 0)

return;

m_ctlFGrid.SetRedraw(FALSE); m_ctlFGrid.SetColPosition(m_iMouseCol, m_ctlFGrid.GetMouseCol()); DoSort(); m_ctlFGrid.SetRedraw(TRUE); }

Output:

You might also like