Cs1802 Visual Programming: Unit I: Windows Programming

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 47

CS1802 VISUAL PROGRAMMING

UNIT I: WINDOWS PROGRAMMING


Windows environment – a simple windows program – windows and messages – creating the
window – displaying the window – message loop – the window procedure – message
processing – text output – painting and repainting – introduction to GDI – device context –
basic drawing – child window controls.

UNIT II : VISUAL C++ PROGRAMMIN-INTRODUCTION


Application Framework – MFC library – Visual C++ Components – Event Handling –
Mapping modes – colors – fonts – modal and modeless dialog – windows common controls –
bitmaps.
UNIT III: THE DOCUMENT AND VIEWARCHITECTURE
Menus – Keyboard accelerators – rich edit control – toolbars – status bars – reusable frame
window base class – separating document from its view – reading and writing SDI and MDI
documents – splitter window and multiple views – creating DLLs – dialog based applications

1
CS1802 VISUAL PROGRAMMING
UNIT IV : ACTIVEX AND OBJECT LINKING AND
EMBEDDING (OLE)
ActiveX controls Vs. Ordinary Windows Controls – Installing ActiveX controls – Calendar
Control – ActiveX control container programming – create ActiveX control at runtime –
Component Object Model (COM) – containment and aggregation Vs. inheritance – OLE drag
and drop – OLE embedded component and containers – sample applications.

UNIT-V : ADVANCED CONCEPTS


Database Management with Microsoft ODBC – Structured Query Language – MFC ODBC
classes – sample database applications – filter and sort strings – DAO concepts – displaying
database records in scrolling view – Threading – VC++ Networking issues – Winsock –
WinInet – building a web client – Internet Information Server – ISAPI server extension – chat
application – playing and multimedia (sound and video) files

2
CS1802 VISUAL PROGRAMMING

TEXT BOOKS
1. Charles Petzold, “Windows Programming”, Microsoft press, 1996.
2. David J.Kruglinski, George Shepherd and Scot Wingo,
“Programming Visual C++”, Microsoft press, 1999.
REFERENCES
1. Steve Holtzner, “Visual C++ 6 Programming”, Wiley Dreamtech
India Pvt. Ltd., 2003.

3
UNIT – I

Windows Programming

4
Windows Programming
Windows 
•Windows is GUI operating systems developed by Microsoft
•Each version of Windows includes a graphical user interface, with a desktop that allows users
to view files and folders in windows
•Windows has been the most widely used operating system for personal computers (PCs)

Versions of Windows or History of Windows


•Microsoft Windows is designed for both home computing and professional purposes. Past
versions of Windows home editions include :
•Windows 3.0 (1990)
•Windows 3.1 (1992)
•Windows 95 (1995)
•Windows 98 (1998)
•Windows XP (2001)
•Windows Vista (2006)
•Windows 7 (2008)
•Windows 8 (2010)
5
•The current version is Windows 10 ,released in 2013
Windows Programming
History of Windows:

 IBM PC – 1981

OS – MSDOS ( Microsoft Disk Operating System)

– MS DOS was minimal operating system.

– For the user, it provided a command-line interface to


commands such as DIR and TYPE and loaded
application programs into memory for execution.

6
Windows Programming
History of Windows:

• For the application programmer, MS-DOS offered little more


than a set of function calls for doing file input/output (I/O).

• For other tasks—in particular, writing text and sometimes


graphics to the video display—applications accessed the
hardware of the PC directly.

7
Windows Programming
History of Windows:

 Apple Computer – Jan 1983

• OS - Lisa

• set a standard for graphical environments with


Macintosh in Jan 1984.

 Windows

• announced by Microsoft corporation in Nov 1983 (post-Lisa but


pre-Macintosh)

8
Windows Programming
History of Windows:

 Windows1.0

• Nov 1985.

• with several updates to support the international market.

• with additional drivers for additional video displays and


printers.

9
Windows Programming
History of Windows:

 Windows2.0

• Nov 1987.

• with several changes to the user interface.

• also enhancements to the keyboard and mouse interface,


particularly for menus and dialog boxes.

10
Windows Programming
History of Windows:

 Windows2.0

• requires only Intel 8086 or 8088 microprocessor running in


"real mode" to access 1 megabyte (MB) of memory.

 Windows/386

• released shortly after Windows 2.0


• used the "virtual 86" mode of the Intel 386 microprocessor to
window
• multitask many DOS programs that directly accessed
hardware. 11
Windows Programming
History of Windows:

 Windows/286

• Windows 2.1 was renamed Windows/286.

 Windows3.0

• May 22, 1990.

• Windows/286 and Windows/386 versions were merged into


one product with this release.

12
Windows Programming
History of Windows:

 Windows3.1 – April 1992

• several significant features included the TrueType font


technology, multimedia (sound and music), Object Linking and
Embedding (OLE), and standardized common dialog boxes.

• ran only in protected mode.

• required a 286 or 386 processor with at least 1 MB of memory.

13
Windows Programming
History of Windows:

 WindowsNT – July 1993

• was the first version of Windows to support the 32-bit mode of


the Intel 386, 486, and Pentium microprocessors.

• Programs that run under Windows NT have access to a 32-bit


flat address space and use a 32-bit instruction set.

• required a 286 or 386 processor with at least 1 MB of was also


designed to be portable to non-Intel processors.

• it runs on several RISC-based workstations. 14


Difference Between RISC and CISC
RISC CISC
It is a Reduced Instruction Set Computer. It is a Complex Instruction Set Computer.
RISC has simple decoding of instruction. CISC has complex decoding of instruction.

It is a hard wired unit of programming in the Microprogramming unit in CISC Processor.


RISC Processor.
It emphasizes on software to optimize the It emphasizes on hardware to optimize the
instruction set. instruction set.
Uses of the pipeline are simple in RISC Uses of the pipeline are difficult in CISC.

It uses a limited number of instruction that It uses a large number of instruction that
requires less time to execute the requires more time to execute the
instructions. instructions.
RISC has more transistors on memory CISC has transistors to store complex
registers. instructions.
The execution time of RISC is very short. The execution time of CISC is longer.15
Windows Programming
History of Windows:

 Windows95 – Aug 1995

• also supported the 32-bit programming mode of the Intel 386


and later microprocessors.

• Adv - requiring fewer hardware resources.

• Dis adv - lacked some of the features of Windows NT, such as


high security and portability to RISC machines.

16
Windows Programming
History of Windows:

 Windows95 – June 1998

• has a number of enhancements such as,

• performance improvements.

• better hardware support.


• a closer integration with the Internet and the World Wide

Web.

17
Windows Programming
Windows System 32
•The Windows System32 directory is often located in either C:WindowsSystem32 or
C:Winntsystem32. Often, many Microsoft Windows error messages will contain the
system32 directory because many of the system files Windows uses to run are stored
in this directory.

WIN API
•The Windows application programming interface (API) lets you develop desktop
and server applications that run successfully on all versions of Windows.
•The Windows API can be used in all Windows-based desktop applications, and the
same functions are generally supported on 32-bit and 64-bit Windows.

18
Windows Programming
Windows Fundamentals
•Windows applications can be developed using a procedure-oriented approach in
either C or C++.
•Windows gives the ability to develop graphics user interface(GUI) .

The Windows Environment


•Windows is a graphics-based multitasking operating system.
•Programs developed for this environment have a consistent look and command
structure.
•To the user, this makes learning each successive Windows application easier.
•To help in the development of Windows applications, Windows provides numerous
built-in functions that allow for easy implementation of menus, scroll bars, dialog
boxes, icons that represent a user-friendly interface.
• Windows permits the application to work in a hardware-independent manner.
19
Windows Programming
The Windows Environment Install

•To write a Windows program in C or C++, you must install the Microsoft Windows
Software Development Kit (SDK) or a development environment that includes the Windows
SDK, such as Microsoft Visual C++. 
•The Windows SDK Contains the headers and libraries necessary to compile and link your
application.
•The Windows SDK also contains command-line tools for building Windows applications,
including the Visual C++ compiler and linker. Although you can compile and build
Windows programs with the command-line tools.

20
Windows Programming
Dynamic Linking:

 Windows provides function calls that an application needs to


implement its user interface and display text and graphics on the
video display.

 These functions are implemented in dynamic-link libraries, or


DLLs. These are files with the extension .DLL or sometimes .EXE.

 They are located in


Win98 - \WINDOWS\SYSTEM
WinNT - \WINNT\SYSTEM and \WINNT\SYSTEM32

21
Windows Programming
Dynamic Linking:

 In the early days, Windows was implemented in just three


dynamic-link libraries.
 These represented the three main subsystems of Windows, which
were referred to as Kernel, User, and GDI.

• Kernel - handles memory management, file I/O and tasking.


• User - refers to the user interface, and implements all the
windowing logic.
• GDI - is the Graphics Device Interface, which allows a
program to display text and graphics on the screen
and printer. 22
Windows Programming
Dynamic Linking:

 Windows98 supports several thousand function calls that


applications can use.

 Each function has a descriptive name, such as CreateWindow.

• This function creates a window for the program.

• All the Windows functions that an application may use are declared in

header files.

23
Windows Programming
Dynamic Linking:

 When you run a Windows program,

• it interfaces to Windows through a process called "dynamic


linking“.

• A Windows .EXE file contains references to the various


dynamic-link libraries.

24
Windows Programming
Dynamic Linking:

 When a Windows program is loaded into memory,

• the calls in the program are resolved to point to the entries of


the DLL functions.

• DLL functions are also loaded into memory if not already


there.

25
Windows Programming
Dynamic Linking:

 When link a Windows program to produce an executable file,

• must link with special "import libraries" provided with


programming environment.

• These import libraries contain the dynamic-link library names


and reference information for all the Windows function calls.

• The linker uses this information to construct the table in the .EXE
file that Windows uses to resolve calls to Windows functions
when loading the program. 26
Simple Windows Program
First Windows Program:

 The Windows program has exactly the same components as the


character-mode version.

 It has

• an include statement,

• a program entry point,

• a function call, and

• a return statement.
27
Simple Windows Program
First Windows Program:

For Example,

 To display "Hello Welcome!!!” in a message box.

#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT ("Hello Welcome!!!"), TEXT
("HelloMsg"), 0) ;
return 0 ;
} 28
•Windows.h : This is the header file for windows program.
•WINAPI: This is Windows Application Programming Interface(WINAPI) to tell the
compiler that this program contain graphical components than console components.
•WinMain:  This is the main function of all windows programs.This function takes
four parameters.It is same as main() function in simple C/C++ programs.
•HINSTANCE: This is Handle to Instance.As you know what is the meaning of
instance in Object-Oriented programming. It is the number used as object.In this
program the object of program is handled by itself.There may be many instances of one
program.This handles only new comer instance. Next parameter hPrevInstance handles
previous instance.
•PSTR: This is Pointer to String parameter.It is same as char* but meaning is
different.This parameter is same as command line argument(args) in Object-Oriented
programming language.
•MessageBox : This method display a message box.
•TEXT : This function is same as char* in C/C++ but in windows it is
PCWSTR(Pointer to Character Wide String).
•MB_OK : This is #define function for adding only OK button to messagebox. 

29
Simple Windows Program
First Windows Program:

 The header file STDIO.H has been replaced with WINDOWS.H.

 The entry point main has been replaced with WinMain.

 The C run-time library function printf has been replaced with the
Windows API function MessageBox.

 However, there is much in the program that is new, including


several strange-looking uppercase identifiers.

30
Simple Windows Program
The Header Files:

 #include <windows.h>

WINDOWS.H is a master include file that includes other


Windows header files.

 The most important and most basic of these header files are:

• WINDEF.H -  Basic type definitions.


• WINNT.H -  Type definitions for Unicode support.
• WINBASE.H -  Kernel functions.
• WINUSER.H   - User interface functions.
• WINGDI.H   - Graphics device interface functions.
31
Simple Windows Program
The Header Files:

 These header files define all the Windows data types, function
calls, data structures, and constant identifiers.

 They are an important part of Windows documentation.

 It is convenient to use the Find In Files option from the Edit menu
in the Visual C++ Developer Studio to search through these
header files.

 It can also open the header files in the Developer Studio and
examine them directly.

32
Simple Windows Program
Program Entry Point:

 Just as the entry point to a C program is the function main, the


entry point to a Windows program is WinMain, which always
appears like this:

 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE


hPrevInstance, PSTR szCmdLine, int iCmdShow)

 This entry point is documented in,

/Platform SDK/User Interface


Services/Windowing/Windows/Window Reference/Window
Functions. 33
Simple Windows Program
Program Entry Point:

 It is declared in WINBASE.H like so (line breaks and all):

int
WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
);
 LPSTR & PSTR are two data types defined in WINNT.H as pointers
to character strings.
 The LP prefix stands for "long pointer“.
34
Simple Windows Program
Prefix Data Type Hungarian
b BOOL Notation
c or ch char
clr COLORREF Note:
cx, cy Horizontal or vertical distance Prefixes can be
dw DWORD combined:
h Handle pszName
l LONG m_nAge
n int
p Pointer
sz Zero-terminated string
w WORD
wnd CWnd
str CString
m_ class member variable
35
Simple Windows Program
Program Entry Point:

WinMain Parameters:

 First parameter -

• It is something called an "instance handle“.

• In Windows programming, a handle is simply a number that an


application uses to identify something.

• In this case, the handle uniquely identifies the program.

36
Simple Windows Program
Program Entry Point:

WinMain Parameters:

 Second parameter -

• A program could determine if other instances of itself were


running by checking the hPrevInstance parameter.

• It could then skip certain chores and move some data from the
previous instance into its own data area.

• In the 32-bit versions of Windows, this concept has been


abandoned. The second parameter to WinMain is always NULL
(defined as 0). 37
Simple Windows Program
Program Entry Point:

WinMain Parameters:

 Third parameter -
• is the command line used to run the program.
• Some Windows applications use this to load a file into memory
when the program is started.

 Fourth parameter –
• indicates how the program should be initially displayed—either
normally or maximized to fill the window, or minimized to be
displayed in the task list bar.
38
Simple Windows Program
MessageBox Function:

 It is designed to display short messages.

 The little window that MessageBox displays is actually considered


to be a dialog box, although not one with a lot of versatility.
For example,

MessageBox (NULL, TEXT ("Hello, Windows 98!"),


TEXT("HelloMsg"), 0) ;

39
Simple Windows Program
MessageBox Function:

Parameters:

 First Parameter - is normally a window handle.

 Second Parameter - is the text string that appears in the body


of the message box.

 Third Parameter - is the text string that appears in the caption


bar of the message box.

40
Simple Windows Program
MessageBox Function:

Parameters:

 Fourth Parameter - can be a combination of constants


beginning with the prefix MB_ that are
defined in WINUSER.H.

• can pick one constant from the first set to indicate what buttons you
wish to appear in the dialog box:

41
Simple Windows Program
MessageBox Function:

Buttons:

#define MB_OK 0x00000000L


#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L

 Note: When set the fourth argument to 0, only the OK button


appears in the message box.

42
Simple Windows Program
Compile, Link and Run:

 When ready to compile HELLOMSG, select Build Hellomsg.exe


from the Build menu, or press F7, or select the Build icon from the
Build toolbar.

 Alternatively, select Execute Hellomsg.exe from the Build menu,


or press Ctrl+F5, or click the Execute Program icon from the Build
toolbar.

 Will get a message box asking you if you want to build the
program.

43
Simple Windows Program
Compile, Link and Run:

 During the compile stage,


• the compiler generates an .OBJ (object) file from the C source
code file.

 During the link stage,


• the linker combines the .OBJ file with .LIB (library) files to
create the .EXE (executable) file.

• can see a list of these library files by selecting Settings from


the Project tab and clicking the Link tab.

44
Simple Windows Program
Compile, Link and Run:

Import Libraries:

 In particular, KERNEL32.LIB, USER32.LIB, and GDI32.LIB.

 These are "import libraries" for the three major Windows


subsystems.

 They contain the dynamic-link library names and reference


information that is bound into the .EXE file.

45
Simple Windows Program
Compile, Link and Run:

Import Libraries:

 Windows uses this information to resolve calls from the program


to functions in the KERNEL32.DLL, USER32.DLL and GDI32.DLL
dynamic-link libraries.

Configuration Files:

 In the Visual C++ Developer Studio, compile and link the program
in different configurations.

 By default, these are called Debug and Release. 46


Simple Windows Program
Compile, Link and Run:

Configuration Files:

 The executable files are stored in subdirectories of these names.

 In the Debug configuration, information is added to the .EXE file


that assists in debugging the program and in tracing through the
program source code.

47

You might also like