Dr.N.N.C.E MCA / IV VP LAB-LM 1 MC9246-VISUAL PROGRAMMING LAB LABORATORY MANUAL FOR IV SEMESTER MCA (FOR PRIVATE CIRCULATION ONLY) ANNA UNIVERSITY ,CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Dr. NAVALAR NEDUNCHEZHIYAN COLLEGE OF ENGINEERING THOLUDUR – 606303,CUDDALORE DISTRICT
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Private Sub Lbl_Message_DblClick() MsgBox (" this is a label to show the events and messages") End Sub
Private Sub txt_Address_LostFocus() Lbl_Message.Caption = "txt_Address_LostFocus event" End Sub
Private Sub Txt_Name_Change() Lbl_Message.Caption = "No. of letters in name :" & Len(txt_name.Text) End Sub
Private Sub txt_RegNo_GotFocus() Lbl_Message.Caption = "txt_RegNo_GotFocus event" End Sub
d) Output
e) Result:
`Thus the program has been executed successfully.
VIVA - QUESTIONS
1. What are the different types of text editing tools?
Edit control and Windows rich edit common control
The MFC library supports this versatility with the CEditView and CRichEditView
classes.
2.How one can create a new Toolbar? (A.U.May-2010) (A.U. May-2012)
To create toolbar, select toolbar from the Resource tab of the workspace pane and double
click on IDR_MAINFRAME. Now, the toolbar dialog window appears. Double click on the blank
tool and drag a control from the tools control and drop it in the toolbar drawing area. Now view
the ID of the tool from the properties dialog of the tool created.
Dr.N.N.C.E MCA / IV VP LAB-LM
8
Exercise Number: 2
Title of the Exercise : Programs on usage of data types - variant, Control arrays
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To create an application with the data types, variants, and array using VB. FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step
no.
Details of the step
1 Start →programs Microsoft Visual Studio6.0→Microsoft Visual Basic.
2 Visual basic can be opened.
3 Select File→New→standard.exe , then give the project name and then
choose empty project button and finally give finish→OK.
4 Design the form.
5 Type the coding.
6 Build and test the application
c) Program:
Private Sub Form_Load( ) Me.WindowState=2 End Sub
Private Sub Option1_Click( ) If Option1.Value=True Then Text3.Text=Val(Text1.Text]+Val(Text2.Text) End Sub
Private Sub Option2_Click( ) If Option1.Value=True Then Text3.Text=Val(Text1.Text]-Val(Text2.Text)
Dr.N.N.C.E MCA / IV VP LAB-LM
9
End Sub
Private Sub Option3_Click( ) If Option1.Value=True Then Text3.Text=Val(Text1.Text]*Val(Text2.Text) End Sub
Private Sub Option4_Click( ) If Option1.Value=True Then Text3.Text=Val(Text1.Text]/Val(Text2.Text) End Sub
d) Output
e) Result:
`
Thus the program has been executed successfully.
VIVA - QUESTIONS
1. How one can assign the tool tips in a toolbar? i. To create a ToolTip, you simply add the tip text to the end of the menu
prompt, preceded by a newline (\n) character. The resource editor lets you edit the prompt string while you are editing the toolbar images. Just double-click in the left panel.
2. Explain the status bar definitions. ii. The status bar window neither accepts user input nor generates command
messages. The status bar supports two types of text panes—message line panes and status indicator panes.
iii. The static indicators array that AppWizard generates in the MainFrm.cpp file defines the panes for the application's status bar. The CStatusBar::SetIndicators member function, called in the application's derived frame class, configures the status bar according to the contents of the indicators array.
Dr.N.N.C.E MCA / IV VP LAB-LM
10
Exercise Number: 3
Title of the Exercise : Simple applications using file system controls
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To Create an application for file system controls using VB. FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step
no.
Details of the step
1 Start →programs Microsoft Visual Studio6.0→Microsoft Visual Basic.
2 Visual basic can be opened.
3 Select File→New→standard.exe , then give the project name and then choose empty
project button and finally give finish→OK.
4 Design the form.
5 Type the coding.
6 Build and test the application
c) Program:
Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub cmd_ListAllDrives_Click() ' Scan the contents of the DriveListBox control List1.Clear List1.AddItem "LIST OF DRIVES" For i = 0 To Drive1.ListCount - 1 List1.AddItem Drive1.List(i)
Dr.N.N.C.E MCA / IV VP LAB-LM
11
Next End Sub Private Sub cmd_ListAllFiles_Click() ' Scan the contents of the FileListBox control List1.Clear List1.AddItem "LIST OF FILES" For i = 0 To File1.ListCount - 1 List1.AddItem File1.List(i) Next End Sub Private Sub cmd_ListAllSubFolders_Click() ' Scan the contents of the DirListBox control List1.Clear List1.AddItem "LIST OF SUBFOLDERS" For i = 0 To Dir1.ListCount - 1 List1.AddItem Dir1.List(i) Next End Sub Private Sub cmd_ListAllParentFolders_Click() List1.Clear List1.AddItem "LIST OF PARENT FOLDERS" pDepth = -1 While Dir1.List(pDepth) <> "" List1.AddItem Dir1.List(pDepth) pDepth = pDepth - 1 Wend List1.AddItem "The current folder is nested " & _ -pDepth + 1 & " folders deep" End Sub
d) Output
Dr.N.N.C.E MCA / IV VP LAB-LM
12
e) Result:
Thus the program has been executed successfully.
VIVA - QUESTIONS
1. Explain the CFormView class.
iv. A CFormView object receives notification messages directly from its
controls, and it receives command messages from the application
framework. This application framework command-processing ability clearly
separates CFormView from CDialog, and it makes controlling the view from
the frame's main menu or toolbar easy.
v. The CFormView class is derived from CView (actually, from CScrollView)
and not from CDialog. You can't, therefore, assume that CDialog member
functions are supported. CFormView does not have virtual OnInitDialog,
OnOK, and OnCancel functions.
2.Define TRACE macro.
vi. TRACE statements are active whenever the constant _DEBUG is defined
(when you select the Debug target and when the afxTraceEnabled variable
is set to TRUE). TRACE statements work like C language printf statements,
but they're completely disabled in the release version of the program. Here's
a typical TRACE statement:
vii. int nCount = 9;
viii. CString strDesc("total");
ix. TRACE("Count = %d, Description = %s\n", nCount, strDesc);
3.What do you mean by serialization?
x. The idea is that objects can be persistent, which means they can be saved on
disk when a program exits and then can be restored when the program is
restarted. This process of saving and restoring objects is called serialization.
Title of the Exercise : Database applications using data control
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To Create an database using data control and implement it in an application using
VB.
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step
no.
Details of the step
1 Start →programs Microsoft Visual Studio6.0→Microsoft Visual Basic.
2 Visual basic can be opened.
3 Select File→New→standard.exe , then give the project name and then
choose empty project button and finally give finish→OK.
4 Design the form.
5 Type the coding.
6 Build and test the application
c) Program:
Dim db As Database Dim rs As Recordset Dim rs1 As Recordset Dim sql As String Private Sub Cmd_Delete_Click() Set rs1 = db.OpenRecordset("select count(*) from student1 where rollno=" & _ Val(Txt_ROllNo.Text)) If Txt_ROllNo.Text = "" Then MsgBox "enter a valid roll number" Exit Sub
Dr.N.N.C.E MCA / IV VP LAB-LM
14
End If If rs1(0) = 0 Then MsgBox ("there are no records with this roll number") Exit Sub End If db.Execute ("delete from student1 where rollno=" & _ Val(Txt_ROllNo.Text)) MsgBox ("record deleted") End Sub Private Sub Cmd_Edit_Click() Clear_Controls Cmd_Edit.Enabled = False End Sub Private Sub cmd_Exit_Click() Unload Me End Sub Private Sub Cmd_Save_Click() If Cmd_Insert.Enabled = False Then sql = " insert into student1 values(" & _ CInt(Txt_ROllNo.Text) & ",'" & _ Txt_Name.Text & "','" & _ Txt_Address.Text & "'," & _ CDbl(Txt_MobileNumber.Text) & ")" MsgBox sql db.Execute (sql) MsgBox ("record inserted") Cmd_Insert.Enabled = True End If If Cmd_Edit.Enabled = False Then sql = "update student1 set name='" & Txt_Name.Text & " ',address='" & _ Txt_Address.Text & "',mobilenumber=" & _ CDbl(Txt_MobileNumber.Text) & " where (RollNO= " & _ CInt(Txt_ROllNo.Text) & ")" MsgBox sql db.Execute (sql) MsgBox ("record updated") Cmd_Edit.Enabled = True End If End Sub Private Sub Form_Load() Set db = OpenDatabase("D:\pavan\VbLabManual\Prg1\mca1.mdb", True) Set rs = db.OpenRecordset("student1", dbOpenDynaset) rs.MoveFirst
Dr.N.N.C.E MCA / IV VP LAB-LM
15
'Show_Data End Sub Private Sub Cmd_First_Click() rs.MoveFirst Show_Data End Sub Private Sub Cmd_Last_Click() rs.MoveLast Show_Data End Sub Private Sub Cmd_Next_Click() rs.MoveNext Show_Data End Sub Private Sub Cmd_Previous_Click() rs.MovePrevious Show_Data End Sub Private Sub Cmd_Insert_Click() Clear_Controls Cmd_Insert.Enabled = False Txt_ROllNo.SetFocus End Sub Private Sub Show_Data() If rs.EOF Then rs.MoveLast End If If rs.BOF Then rs.MoveFirst End If Txt_ROllNo.Text = rs(0) Txt_Name.Text = rs(1) Txt_Address.Text = rs(2) Txt_MobileNumber.Text = rs(3) End Sub Private Sub Clear_Controls() Txt_ROllNo.Text = "" Txt_Name.Text = "" Txt_Address.Text = "" Txt_MobileNumber.Text = "" End Sub
Dr.N.N.C.E MCA / IV VP LAB-LM
16
d) Output
e) Result:
Thus the program has been executed successfully.
VIVA - QUESTIONS
1. What do you mean by SQL? Structured Query Language (SQL), a standard database access language with its own
grammar. In the SQL world, a database is a collection of tables that consist of rows and columns. Many DBMS products support SQL, and many programmers know SQL. 2. What Databases Can You Open with DAO? (A.U.APRIL 2007)
Opening an Access database (MDB file)—An MDB file is a self-contained database that includes query definitions, security information, indexes, relationships, and of course the actual data tables. You simply specify the MDB file's pathname.
Opening an ODBC data source directly—There's a significant limitation here. You can't open an ODBC data source that uses the Jet engine as a driver; you can use only data sources that have their own ODBC driver DLLs.
Attaching external tables to an Access database—This is actually the preferred way of using DAO to access ODBC data. First you use Access to attach the ODBC tables to an MDB file, and then you use DAO to open the MDB file as in the first option. You can also use Access to attach ISAM files to an MDB file.
Dr.N.N.C.E MCA / IV VP LAB-LM
17
Exercise Number: 5
Title of the Exercise : Windows Creation Program
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To Create a simple window using vc++ programming
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step Details of the step
1 Start →programs Microsoft Visual Studio6.0→Microsoft Visual C++6.0.
2 Visual C++ Window will be opened.
3 Select File→New→Win32 Application, then give the project name and
then choose empty project button and finally give finish→OK.
4 Again go to File→New→C++ Source File→File Name→OK.
The WINAPI identifier is defined in WINDEF.H with the statement:
#define WINAPI __stdcall
Dr.N.N.C.E MCA / IV VP LAB-LM
20
This statement specifies a calling convention that involves how machine code is
generated to place function call arguments on the stack. Most Windows function calls are
declared as WINAPI.
2.What is use of Message Box function?
The Message Box function is used to display short messages. The little window
that Message Box displays is actually considered to be a dialog box.
3. What are the function calls used in windows programming?
LoadIcon Loads an icon for use by a program.
LoadCursor Loads a mouse cursor for use by a program.
GetStockObject Obtains a graphic object, in this case a brush used for painting the
window's background. RegisterClass Registers a window class for the program's
window. \
MessageBox Displays a message box.
CreateWindow Creates a window based on a window class.
4. What is a Handle? What is its advantage?
A handle is simply a number (usually 32 bits in size) that refers to an object. The handles in
Windows are similar to file handles used in conventional C or MS-DOS programming. A program
almost always obtains a handle by calling a Windows function. The program uses the handle in
ther Windows functions to refer to the object. The actual value of the handle is unimportant to your
program, but the Windows module that gives your program the handle knows how to use it to
reference the object.
5. How will you display the window? (APRIL 2007) i. After the CreateWindow call returns, the window has been created internally
in Windows. Then call the following 2 functions,
a.ShowWindow (hwnd, iCmdShow); The first argument is the handle to the window just created by CreateWindow.
Win Main. The second argument is the iCmdShow value passed as a parameter to .
ii. The ShowWindow function puts the window on the display. If the second argument to ShowWindow is SW_SHOWNORMAL, the client area of the window is erased with the background brush specified in the window class. The function call
b. UpdateWindow (hwnd); i. It causes the client area to be painted.
Dr.N.N.C.E MCA / IV VP LAB-LM
21
Exercise Number: 6
Title of the Exercise : Keyboard and Mouse Event
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To write a program for Keyboard and mouse event using Win 32 Application.
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step no.
Details of the step
1 Create a project named key mouse from File->New and select Win32Application
2 Create a c++ file from File->New then select C++ Source File and give the File name
as key mouse
3 Define the WNDCLASS structure and Register it using RegisterClass( )
4 Create the window using Create Window function with specifying parameters
5 Extract the message from the message queue and dispatch it to the procedure using
Get Message & Dispatch Message respectively
6
The window message WM_LBUTTONDOWN, WM_LBUTTONUP,
WM_MOUSEMOVE is generated when the mouse is clicked, released, and moved
respectively and its status information are stored in flag variables
7
The line is drawn between (x1,y1) and (x2,y2) using MoveToEx() and LineToEx(),
here (x1,y1) is the current mouse co-ordinates after mouse move the current mouse
co-ordinates stored in (x2,y2) then the next step it is assigned to (x1,y1).
8 Build and Execute from Build->Build keymouse.exe then Build->Execute
VIVA QUESTION AND ANSWER 1. Why we need Visual C++?( A.U.May-2010) The Visual C++ tools reduce coding drudgery Graphical User Interface Using MFC, which simplify and speed development of windows applications.
It includes sophisticated resource editors to design complex dialog boxes, menus, toolbars, images and many other elements of modern windows applications.
2. What are the applications used in AppWizard? (A.U. May-2012) a. Single Document Interface b. Multiple Document Interface c. Dialog Based
3. How one can add a new menu item in a dialog window? To create a new menu bar by using resource editor, give the name as “newmenu”.Open
the dialog window, then select the dialog property window. Now select the menu property, choose “newmenu” option.we can construct a CMenu object, use the CMenu::LoadMenu function to load the menu from the resource, and call the CWnd::SetMenu function to attach the new menu to the frame window.
Dr.N.N.C.E MCA / IV VP LAB-LM
32
Exercise Number: 8
Title of the Exercise : MDI Application
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To create a MDI application to display a rectangle and apply pattern brush in it.
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step no. Details of the step
1 Create a project named MDI from File->New and select MFCAppWizard(exe) and the next step select Multiple documents and the next step uncheck the ActiveXControl support and finish it.
2 Use the Class Wizard to add WM_PAINT message to the View class, to do select MDIView in both class name and Object IDs in the Class Wizard then double click WM_PAINT message in the Messages field
3 Edit the code for OnPaint message handler function
4 Build and execute the program, click File->New, a new document is opened.
A DLL is a file on disk (usually with a DLL extension) consisting of global data,
compiled functions, and resources, which become part of your process. It is compiled to load at
a preferred base address, and if there's no conflict with other DLLs, the file gets mapped to the
same virtual address in your process.
The DLL has various exported functions, and the client program (the program that
loaded the DLL in the first place) imports those functions. Windows matches up the imports
and exports when it loads the DLL.
2. How the Client Program Finds a DLL.
If we link explicitly with LoadLibrary, you can specify the DLL's full pathname. If we
don't specify the pathname, or if you link implicitly, Windows follows this search sequence to
locate your DLL:
The directory containing the EXE file
The process's current directory
The Windows system directory
The Windows directory
The directories listed in the path environment variable
Here's a trap you can easily fall into. We build a DLL as one project, copy the DLL file
to the system directory, and then run the DLL from a client program. Next we rebuild the DLL
with some changes, but we forget to copy the DLL file to the system directory. The next time
we run the client program, it loads the old version of the DLL.
3. What are the different types of DLL?
AppWizard lets you build two kinds of DLLs with MFC library support:
a. extension DLLs and
b. regular DLLs.
4. Explain the extension DLL?
An extension DLL dynamically links to the code in the DLL version of the MFC library. An
extension DLL supports a C++ interface. When we build an MFC regular DLL, you can choose
to statically link or dynamically link to the MFC library. If we choose static linking, our DLL
will include a copy of all the MFC library code it needs and will thus be self-contained.
Dr.N.N.C.E MCA / IV VP LAB-LM
47
Exercise Number: 14 Title of the Exercise : DATA ACCESS THROUGH ODBC Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To create a MFC Application for Database to store, retrieve, update student information like name, roll no, dept, mark1, mark2, and mark3 using ODBC.
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step no. Details of the step
CREATING DATABASE
1 Create a database for the project in MSAccess from File->New and crea
blank database and save it then do the following
i. On the dialog appears in the window double click the
create table in design view
ii. Now type the fields like as follows and save the table
Name Text
RollNo Number
Dept Text
Mark1 Number
Mark2 Number
Mark3 Number
The table is shown, now specify the input or data for the fields
ACCESSING THE DATA
1 Create a project name ODBC using File->New and select
MFCAppWizard(exe) and the second step select Single Document and the
3rd step “Database view without File support and click the data source on
Dr.N.N.C.E MCA / IV VP LAB-LM
48
the same dialog box and then
Select in ODBC database name that we created and click OK and then
table name will be displayed on the window and select it click ok
2 Now accept the next default steps and the last step the AppWizard will
creates five classes for the project and click finish
3 Now design the dialog window using controls as follows
4 On the client area design a mark list for the student using the controls and
set the IDs
control (Edit control) IDs
Name
RollNo
Dept
Mark1
Mark2
Mark3
IDC_NAME
IDC_ROLLNO
IDC_DEPT
IDC_MARK1
IDC_MARK2
IDC_MARK3
5 Add member variable for the classes from view->class Wizard and select
the member variable tab on the dialog and do the following
i. Select the control IDs and click Add variable then a dialog appears
ii. In the new dialog, select the Member variable Name and the
variable type using the combo box.
Similarly do the above step for other control IDs.
6 The Member variables and its types are follows after finishing the
previous step.
Dr.N.N.C.E MCA / IV VP LAB-LM
49
Control IDs Type Member
IDC_DEPT
IDC_MARK1
IDC_MARK2
IDC_MARK3
IDC_NAME
IDC_ROLLNO
CString
int
int
int
CString
int
m_Dept
m_Mark1
m_Mark2
m_mark3
m_Name
m_RollNo
7 Set the IDs for the buttons using its properties(right click)
Control IDs Caption
ID_CLEAR
ID_ADD
ID_DELETE
ID_UPDATE
Clear
Add
Delete
Update
8 Now double click the buttons then corresponding handler are generated
and then add the codes to the corresponding handler
CONNECTING DATABASE TO OUR PROJECT
1 To make a connection of vc++ to MsAccess by following the steps.
i) From settings-> controlpanel-> Administrative tools->ODBC then a
dialog will appears.
ii) Click the add button on the dialog box then a dialog box appears, in
that select ”access drive to Microsoft access (*.mdb)” and click ok.
iii) Then type a data source named and click select button and select the
database name mdb file and click ok and next boxes also click ok.
2 Now the connection to access data from database was established.
3 Build and execute the program.
4 In the output client window, using the next and previous record button.
We can see the record and also using the button we can insert, delete and
update the records.
c) Program:
// CODBCView.CPP
void CODBCView::OnClear()
{ m_pSet->SetFieldNull(NULL);
UpdateData(FALSE);
Dr.N.N.C.E MCA / IV VP LAB-LM
50
}
void CODBCView::OnAdd()
{ m_pSet->AddNew();
UpdateData(TRUE);
if(m_pSet->CanUpdate())
{ m_pSet->Update(); }
if(m_pSet->IsEOF())
{ m_pSet->MoveLast(); }
m_pSet->Requery();
UpdateData(FALSE); }
void CODBCView::OnDelete()
{ CRecordsetStatus stat;
try { m_pSet->Delete(); }
catch(CDBException* e)
{ AfxMessageBox(e->m_strError);
e->Delete();
m_pSet->MoveFirst();
UpdateData(FALSE);
return; }
m_pSet->GetStatus(stat);
if(stat.m_lCurrentRecord==0)
{ m_pSet->MoveFirst(); }
else
{ m_pSet->MoveNext(); }
UpdateData(FALSE);
}
void CODBCView::OnUpdate()
{ m_pSet->Edit();
UpdateData(TRUE);
if(m_pSet->CanUpdate())
{ m_pSet->Update();
} }
Dr.N.N.C.E MCA / IV VP LAB-LM
51
d) Output:
e) Result:
Thus the program has been executed successfully.
VIVA QUESTION AND ANSWER
1. Define ODBC?
The Microsoft Open Database Connectivity (ODBC) standard defines the rules of
SQL grammar and also the C-language programming interface to any SQL database. It's
now possible for a single compiled C or C++ program to access any DBMS that has an
ODBC driver.
2. Explain ODBC architecture.
ODBC's unique DLL-based architecture makes the system fully modular. A small
top-level DLL, ODBC32.DLL, defines the API. ODBC32.DLL loads database-specific
DLLs, known as drivers, during program execution.
3. What are the Recordset member functions? Open - Opens the recordset AddNew - Prepares to add a new record to the table Update - Completes an AddNew or Edit operation by saving the new or
edited 1. data in the data source
Delete - Deletes the current record from the recordset 4. What are the advantages of DBMS?
Use of standard file formats, Indexed file access, Data integrity safeguards, Multiuser access control.
Dr.N.N.C.E MCA / IV VP LAB-LM
52
Exercise Number: 15
Title of the Exercise : CREATING ACTIVEX CONTROL AND USING IT
Date of the Exercise :
OBJECTIVE (AIM) OF THE EXPERIMENT
• To create MFC Application for Active X Control Support.
FACILITIES REQUIRED AND PROCEDURE
a) Facilities Required:
S.No. Facilities required Quantity
1 System 1
2 O/S Windows XP
3 S/W name Microsoft Visual Studio 6.0
b) Procedure:
Step no. Details of the step
1 Create a project named ActiveXCtrl from File->New and select
MFCAppWizard (exe) and the next step select Single Document after that
accept the default values and finish it.
2 From the project menu select add to project->components and controls
open Registered ActiveX controls and select calendar controls 8.0, now
click the insert button.
3 The classwizard generates two classes for the project. The classes are
“CCalendar, COlefont” and click ok.
4 In the resource view tab on the workspace, right click on dialog and select
insert, a new dialog box appears.
5 In the dialog box, right click it and select the properties, change the ID as
“IDD_ACTIVEXDIALOG” and caption as “ActiveXDialog”.
6 Drag the calendar control from the control palette and place it into the
dialog box and design the dialog box as shown below.
Dr.N.N.C.E MCA / IV VP LAB-LM
53
7 By using the properties, change the ID and caption as follow
Control ID Caption
Calendar control
Selectdatebutton
Editcontrol
Editcontrol
Editcontrol
Nextweek button
IDC-
CALENDAR1
IDC-
SELECTDATE
IDC-DAY
IDC-MONTH
IDC-YEAR
IDC-NEXTWEEK
--
select date
--
--
--
nextweek
8 From the view classwizard, select “create a new class” and type the name
as CActiveXDialog and click ok.
9 In the classwizard from view menu, select the message maps and add the
message handler as follows, (double click the messages)
Object IDs Messages
CActiveXDialog
IDC_SELECTDATE
IDC_NEXTWEEK
IDC_CALENDAR1
ID_OK
WM_INITDIALOG
BN_CLICKED
BN_CLICKED
NewMonth
BN_CLICKED
10 Click on the classwizard from view menu and select member variable tab
and then add the member variable as follows. To add variable just select
the IDs and click add variable button.
IDs Member Category Variable
Dr.N.N.C.E MCA / IV VP LAB-LM
54
variable name Type
IDC_CALENDER
IDC_DAY
IDC_MONTH
IDC_YEAR
m_calender
m_sDay
m_sMonth
m_sYear
control
value
value
value
CCalendar
short
short
short
11 In the class view tab, on the workspace right click on CActiveXDialog
and choose add member variable as follows.
Variable Type Variable Name
unsigned long
COleVariant
m-BackColor
m-varValue
12 Open the ActiveXDialog.cpp file from the file view tab and open source
files and add the codes to it.
13 From the view ->ClassWizard, choose CActiveXCtrlView in class name
field and select CActiveXCtrlView in Object IDs and double click
WM_UTTONDOWN in the messages list box and click ok.
14 Open the AxtiveXCtrlView.cpp and add codes to OnLButtonDowm()
handler as follows and add #include “ActiveXDialog.h” at the top and