Cs1802 Visual Programming: Unit I: Windows Programming
Cs1802 Visual Programming: Unit I: Windows Programming
Cs1802 Visual Programming: Unit I: Windows Programming
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.
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)
IBM PC – 1981
6
Windows Programming
History of Windows:
7
Windows Programming
History of Windows:
• OS - Lisa
Windows
8
Windows Programming
History of Windows:
Windows1.0
• Nov 1985.
9
Windows Programming
History of Windows:
Windows2.0
• Nov 1987.
10
Windows Programming
History of Windows:
Windows2.0
Windows/386
Windows/286
Windows3.0
12
Windows Programming
History of Windows:
13
Windows Programming
History of Windows:
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:
16
Windows Programming
History of Windows:
• performance improvements.
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) .
•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:
21
Windows Programming
Dynamic Linking:
• All the Windows functions that an application may use are declared in
header files.
23
Windows Programming
Dynamic Linking:
24
Windows Programming
Dynamic Linking:
25
Windows Programming
Dynamic Linking:
• 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:
It has
• an include statement,
• a return statement.
27
Simple Windows Program
First Windows Program:
For Example,
#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 C run-time library function printf has been replaced with the
Windows API function MessageBox.
30
Simple Windows Program
The Header Files:
#include <windows.h>
The most important and most basic of these header files are:
These header files define all the Windows data types, function
calls, data structures, and constant identifiers.
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:
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 -
36
Simple Windows Program
Program Entry Point:
WinMain Parameters:
Second parameter -
• It could then skip certain chores and move some data from the
previous instance into its own data area.
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:
39
Simple Windows Program
MessageBox Function:
Parameters:
40
Simple Windows Program
MessageBox Function:
Parameters:
• 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:
42
Simple Windows Program
Compile, Link and Run:
Will get a message box asking you if you want to build the
program.
43
Simple Windows Program
Compile, Link and Run:
44
Simple Windows Program
Compile, Link and Run:
Import Libraries:
45
Simple Windows Program
Compile, Link and Run:
Import Libraries:
Configuration Files:
In the Visual C++ Developer Studio, compile and link the program
in different configurations.
Configuration Files:
47