Development of Windows Applications Lab Manual: Vii Sem B.E. Department of Computer Science & Engineering (2009)
Development of Windows Applications Lab Manual: Vii Sem B.E. Department of Computer Science & Engineering (2009)
CODE: CSE 413
DEVELOPMENT OF WINDOWS
APPLICATIONS LAB MANUAL
VII SEM B.E.
Department of Computer Science & Engineering
10pt. CREDIT SYSTEM
(2009)
Prepared by Approved by
(P. C. Siddalingaswamy) (Head of the Department)
Manipal Institute of Technology
Manipal University
Manipal ‐ 576104
INSTRUCTIONS TO STUDENTS
1. Students should be regular and come prepared for the lab practice.
2. In case a student misses a class, it is his/her responsibility to complete that
missed program(s).
3. Students should bring the observation book, lab manual, prescribed textbook and
class notes.
4. They should implement the given program individually.
5. While writing the VC++ code students should see that their programs would meet
the following criteria:
• Programs should be interactive with appropriate prompt messages, error
messages if any, and descriptive messages for outputs.
• Programs should perform input validation (Data type, range error, etc.) and
give appropriate error messages and suggest corrective actions.
• Comments should be used to give the statement of the problem and every
function should indicate the purpose of the function, inputs and outputs
• Statements within the program should be properly indented
• Use meaningful names for variables and functions.
• Make use of Constants and type definitions wherever needed.
6. Once the program(s) get executed, they should show the program and results to
the instructors and copy the same in their observation book.
7. Questions for End semester exam need not necessarily be limited to the questions
in the manual, but could involve some variations and / or combinations of the
questions.
LAB 01 : GETTING STARTED WITH WINDOWS PROGRAMMING
Objective of this lab is to make you understand the special features provided by
Microsoft Developer Studio to handle different file types and to use different tools to
write windows programs. In this lab, take a whirlwind tour through Visual C++. You’ll
see how to get the best from the Developer Studio, and learn a little bit about the MFC
libraries. Take some time to play with Visual C++ before continuing. See how it works
and get a feel for it. Intentionally write some bogus code to make sure you understand
how to navigate from error to error. Tap F1 to see the MSDN help for your errors. Look
through the online documentation and understand how it works so that you can get
help with the environment as you move through the classes. Lastly build an application
using the AppWizard.
1. Create a simple “Hello World” Win32 console application.
2. Create a simple “Hello World” Win32 application. (Display hello world in a
message box).
3. Create a simple “Hello world” windows program using MFC AppWizard.
4. Add one or two simple event handlers to the program in Q3. Eg. On left
mouse down display a message box.
5. Note down the details of important classes (refer to MSDN help) of MFC
application in the observation copy.
LAB 02: WINDOWS EVENT DRIVEN ORIENTED PROGRAMMING
Objective of this lab is to make you understand how windows events are handled. Also
to make you familiar with the ClassWizard. At the end of the lab you must know
various ClassWizard methods. And also the importance of OnDraw() method.
1. Create a windows program using MFC AppWizard to display a message box
wherever user clicks mouse button.
2. Create a windows program using MFC AppWizard to
Read characters from the keyboard.
Record a character in Document.
Display the stored data.
Display the stored data in the center of window.(HINT: find the size of the
window and size of the text to be displayed)
3. Alter the above program by adding caret to a window.
4. Create a MDI application and note down the changes in the program from
that of SDI application. ( Use MSDN help).
LAB 03: GRAPHICS DEVICE INTERFACE
With the exception of special system or driverlevel programs, Windows applications
will always display information to the user in the application's window. In this lab
you’ll know how to get the painting done? When you handle the CView::OnDraw()
function, you're passed a pointer to a CDC object, which is the wrapper for a Windows
device context (or DC for short) data structure. The device context contains
everything Windows needs to communicate with the device driver responsible for a
graphic output device. Among a few other things, it remembers what font, color, pen,
bitmap, pattern, orientation and mapping mode you're using to draw.
1. Write a simple application to draw line, circle, ellipse, rectangle and fill them
with colours. (Use CBrush)
2. Create a MFC application for freehand drawing (Use CPen).
3. Create an application to plot a 2D graph of population (in crores) against
various states of India. Use appropriate colours and fonts.(Use CFont)
4. Write a application to animate the objects drawn. (Eg. Clock)
Lab 04: CONTINUATION OF GDI
1. Write a program to add Menu items to the application.
2. Create an interactive Paint brush application using four drop down menu
items and sub items as follows. On selecting the particular menus the user
must be able to draw the figure properly.
Shapes Pen thickness Pen color Fill color
Ellipse 1 Red Green
Free hand 2 Yellow Blue
Line 3
Rectangle
3. Create a Metafile application to record the drawing activity.
4. Create bitmaps using BitBlt function. (Refer MSDN)
Lab 05: DEMONSTRATION OF MODAL DIALOG BOXES
A modal dialog requires the user to respond before the application continues; other
windows in the application are effectively disabled, and the user must dismiss the
dialog box before they can return focus to the application itself. A modeless dialog
allows the user to do other work with the application. The user can activate the other
windows of the application and later return to the dialog as they see fit. Of course, if a
subsequent modal dialog is created, it disables any modeless dialogs, along with any
other windows in the application. MFC provides a class called CDialog for basic dialog
operations. This class derives from CWnd, which in turn is derived from CCmdTarget,
so MFC knows that the dialogs are command targets which can send and receive
messages, and that they are also windows that have titles, borders and styles. CDialog
isn't an incredibly useful class on its own; you'll normally derive your own class from
CDialog to manage a particular dialog box template in your application.
1. Create a simple application to demonstrate use of check boxes, Radio
buttons, list boxes and combo boxes as follows.
2. Create a simple calculator application with modal dialog box, 3 edit boxes
and 2 buttons as follows.
3. Create a dialog based application that includes the following controls. Add
suitable items in the controls. On dragging the track bar or clicking on spin
button control show the progress in progress bar and at the same time
display the value in the edit box. On selecting any items in list box, list control
box or combo box, display that item in the edit box.
LAB 06: DEMONSTRATION OF MODALESS DIALOG BOXES
1. Create and destroy a simple modeless dialog box. The modeless dialog box
must be created on clicking left mouse button on the client area.
2. Create a simple modal dialog with one list box, New button and Exit button.
On clicking New button create a modeless dialog box with one edit box, Add
button and Exit button. On entering name in the edit box and clicking Add
button add the item in the list box of parent dialog. Make sure the at any
given time only one instance of modeless dialog is opened by
disabling/enabling New button.
3. Create a SDI application with a menu item Settings. On clicking Settings open
a modeless dialog box with appropriate controls to hold the information
about a student( Use combo, List, Edit, Radio Buttons…….). On exiting the
modeless dialog box print the information added on the client area.
4. Create a dialog based application and draw circle on the dialog. Use OnPaint
handler to create Device context to draw objects on dialog.
LAB 07: DEMONSTRATE THE USE OF MENU AND STATUS BAR
A frame window is responsible for one or two more things than just making sure your
application has a menu and a sizable frame. It also serves as an anchor for your
window's toolbar and status bar. As yet, we haven't examined these classes, but since
they're so often paired with a frame window, let's have a look at what they do. If your
application has a status bar or a toolbar, you'll find code in your main frame window
which creates instances of CStatusBar or CToolBar. As you might guess, CStatusBar
creates a status bar and CToolBar handles a toolbar. In most applications, the creation
of these windows is handled in the OnCreate() member of the application's frame
window.
1. Add a new menu item to a program file menu called PrintWelcome. On
selecting this display a text welcome on the client area.
2. Create few menus in the application. On selecting the menu item, make it
inactive by graying them out. Modify the program by checking the menu
items, add submenus, accelerator keys, status bar, tool bar buttons.
3. Create a application to display the mouse coordinates in the status bar as the
mouse is moved on the client area.
4. Create a property sheet application. (Refer Text book)
LAB 08: SINGLE DOCUMENT INTERFACE
Keeping in line with the document/view architecture, your server should use its
document object to contain and manage any data that the object needs to hold. Since
users will expect the content of your object to be persistent across invocations of the
code, you should implement serialization in your document to make sure anything that
should be is indeed persistent.
1. Create a writer program that accept and display keystrokes.
2. Modify the above program to write a string of text that user types in to disk
and read it back in again on demand. Update the menu items as required.
3. Implement the SDI with serialization application to store and retrieve the
information from the secondary memory.
LAB 09: MULTITHREADED PROGRAMMING
Almost all good multithreaded programs are attempts at maximizing the time for
which a process is allowed to execute. If your application ever spends time waiting for
input, output, or other events outside the direct context of the process itself, it can
probably benefit from a multithreaded architecture. The time your application spends
waiting for network I/O to complete could be used to update the user interface,
perform more processing, or even begin another I/O operation. The idea of having
multiple threads here is that one thread waits on the I/O while another gets some real
work done. Synchronization objects are a very important aspect of thread
programming; it's crucial that you understand them. Synchronization objects are a
collection of systemsupplied objects that allow threads to communicate with one
another. There are four such objects in Windows: critical sections, semaphores,
mutexes, and events.
1. Demonstrate the creation of threads in win32 console application. Use
CreateThread( ).
2. Demonstrate the Creation threads and other synchronizing objects in the
MFC application. Use AfxBeginThread( ).
3. Demonstrate the use of Timers in MFC application using car and truck
program. (Refer the class notes)
4. Create a Multithreaded SDI application as follows. Every time clicking on the
client area create different threads. Each thread creates a small ball and it
keeps bouncing inside the client area.
5. Implement the following examples discussed in the textbook
Ex12B (Page 277) and Ex12C (Page 279).
LAB 10 : CREATING ACTIVE X CONTROLS
MFC contains a great deal of code to implement ActiveX controls and the various
standards and interfaces they require, making things easier for you as a control
developer. You just need to add the code for the unique features of your user interface,
as well as the generic features you want your control to implement. This is in keeping
with the whole MFC philosophy of wrapping popular parts of Windows while actually
implementing generic functionality for the really ugly parts of the system, allowing
you, as a developer, to run off and develop whatever features you want.
1. Draw a small rectangle and divide it into 4 sections, when user clicks on one
of the sections, shade that section with black.
Create a new Dialog based application and insert a control of above program
in this application.
2. Try to derive an ActiveX control from preexisting standard control like
button.
3. Implement the following examples discussed in the textbook.
a. ActiveX control dialog container. (Page 176).
b. Web browser ActiveX control (Page 187).
LAB 11: DATABASE MANAGEMENT WITH ODBC
1. Create a hotel management data base system, with MS Access as backend and
VC++ as front end.
2. Create the student registration database discussed in the text book. (Page
905).
LAB 12: Lab Exam
REFERENCES
1. “Programming Microsoft Visual C++ Fifth Edn.”, by David J. Kruglinski.
2. “Microsoft Visual C++”, by Steve Holzner.
3. MSDN online help.