windows programming final
TRANSCRIPT
-
8/9/2019 Windows Programming Final
1/22
Windows Programming
-
8/9/2019 Windows Programming Final
2/22
Presentation Outline
Windows environment
A History of windows
Aspects of windows
Dynamic linking
Windows Programming Models
API
First windows ProgramThe Messagebox function
-
8/9/2019 Windows Programming Final
3/22
The Windows Environment
A History of Windows
Windows was announced by Microsoft Corporation inNovember 1983 and was released two years later inNovember 1985 (market release)
Windows 2.0 was released in November 1987Overlapping windows with many interfaces- keyboard ,
display.
Windows /386- Virtual 86 mode direct access- hardware
Windows 3.0 was introduced on May 22, 1990
16-bit protected-mode operation
shell programs
gain a foothold in the home and the office.
-
8/9/2019 Windows Programming Final
4/22
A History of Windows continued
Microsoft Windows version 3.1 was released inApril 1992
1. outline fonts to Windows
2.multimedia (sound and music),3.Object Linking and Embedding (OLE),
and
standardized common dialog
32 bit architecture Windows NT, introduced in July 1993
Windows 95 was introduced in August 1995
Windows 98 was released in June 1998
hardware support, and a closer integration
-
8/9/2019 Windows Programming Final
5/22
Aspects of Windows
Windows possesses GUI- "visual interface" - "graphicalwindowing environment.
The program occupies a windowusually a rectangular area onthe screen.
Each window identified - caption bar.Most program functions -initiated through the program's
menus.User - view the display of information- scroll bars.Dialog boxes-the user enters additional information.
Graphical user interface- Video display- for user input usekeyboard, objects(icons- controls-edit, scrollbar etc) source ofinput.
User directly interacts with the objects on the display. A graphical interface not only is more attractive in appearance
but also can impart a high level of information to the user
-
8/9/2019 Windows Programming Final
6/22
Aspects of Windows
All applications have the same fundamentallook and feel.. for ex.
One dialog box - that used to open a file, -almost every Windows program- almostlooks the same - always invoked from thesame menu option.
consistent user interface -menus have the samekeyboard and mouse interface because Windowshandles this job.
-
8/9/2019 Windows Programming Final
7/22
Aspects of Windows
Windows 98 and Windows NT - 32-bitpreemptive multitasking and multithreadinggraphical operating systems.
Each program occupies a window on the screen. The usercan move the windows around on the screen, change theirsizes, switch between different programs, and transferdata from one program to another.
Under Windows NT and Windows 98, multitasking is
preemptive and programs themselves can split intomultiple threads of execution that seem to runconcurrently.
-
8/9/2019 Windows Programming Final
8/22
Aspects of Windows (4)
Dynamic Link Library:
Programs running in Windows can shareroutines that are located in other files called"dynamic-link libraries."
Collection of Routines in any language packed & used for another program
-
8/9/2019 Windows Programming Final
9/22
Aspects of Windows
GDI- Graphical User Interface Program -Windows not directly access
hardware Windows virtualizes display hardware.
The program does not need to determine
what type of device is attached to the system.
-
8/9/2019 Windows Programming Final
10/22
Windows Programming OptionsAPI: Application Programming Interface:
An API encompasses all the function calls that
an application program can make of an
operating system, as well as definitions of
associated data types and structures.
To a programmer, an operating system is
defined by its API.
-
8/9/2019 Windows Programming Final
11/22
API
API
16 bit API
32 bit API
Windows NT and Windows 98 are bothconsidered to support the Win32API.
1.0 through 3.1 of Windows Win 16API
Win 32- supports the Win16API to ensurecompatibility with old applications and the Win32
API to run new applications
-
8/9/2019 Windows Programming Final
12/22
API
API
Kernel- Process Loading, context
switch,File I/O, Memory management
User-Window, menu, dialog box etc
GDI graphical output, images
-
8/9/2019 Windows Programming Final
13/22
API
In Windows NT, Win16 function calls gothrough a translation layer and areconverted to Win32 function calls that are
then processed by the operating system. In Windows 95 and Windows 98, the
process is opposite that: Win32 functioncalls go through a translation layer and
are converted to Win16 function calls tobe processed by the operating system.
-
8/9/2019 Windows Programming Final
14/22
Hungarian Notation
Prefix Data Typeb BOOL
c orch char
clr COLORREF
cx, cy Horizontal or vertical distance
dw DWORDh Handle
l LONG
n int
p Pointer
sz Zero-terminated stringw WORD
wnd CWnd
str CString
m_ class member variable
Note:Prefixes can be
combined:
pszName
m_nAge
-
8/9/2019 Windows Programming Final
15/22
Your First Windows Program
/*-------------------------------------------------------------
HelloMsg.c -- Displays "Hello, Windows 98!" in a messagebox
--------------------------------------------------------------*/
#include int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT
("HelloMsg"), 0) ;return 0 ;
}
-
8/9/2019 Windows Programming Final
16/22
The Header Files
HELLOMSG.C begins with a preprocessor directive that you'll find atthe top of virtually every Windows program written in C:
#include
WINDOWS.H - master include file - includes other Windows headerfiles,
some of which also include other header files.
The most important and most basic of these header files are:
WINDEF.H Basic type definitions.
WINBASE.H Kernel functions.
WINUSER.H User interface functions.
WINGDI.H Graphics device interface functions.
These header files define all the Windows data types, functioncalls, data
structures, and constant identifiers.
-
8/9/2019 Windows Programming Final
17/22
Program Entry Point
The entry point to a Windows program isWinMain, which always appears like this:
int WINAPI WinMain
( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
-
8/9/2019 Windows Programming Final
18/22
Program Entry Point
The WinMain function is declared asreturning an int. The WINAPI identifier isdefined in WINDEF.H with the statement:
#define WINAPI __stdcall This statement specifies a calling
convention that involves how machinecode is generated to place function call
arguments on the stack. Most Windowsfunction calls are declared as WINAPI.
-
8/9/2019 Windows Programming Final
19/22
Program Entry Point
The first parameter to WinMain is called an"instance handle." - simply a number that anapplication uses to identify the program.
The second parameter to WinMain is alwaysNULL (defined as 0).
The third parameter to WinMain is the commandline used to run the program.
The fourth parameter to WinMain indicates how
the program should be initially displayedeithernormally or maximized to fill the window, orminimized to be displayed in the task list bar.
-
8/9/2019 Windows Programming Final
20/22
The MessageBoxFunction
The MessageBoxfunction is designed to displayshort messages. The little window thatMessageBoxdisplays is actually considered to bea dialog box, although not one with a lot ofversatility.
The first argument to MessageBoxis normally awindow handle.
The second argument is the text string thatappears in the body of the message box, and
the third argument is the text string that
appears in the caption bar of the message box. In HELLMSG.C, each of these text strings is
enclosed in a TEXT macro.
-
8/9/2019 Windows Programming Final
21/22
The MessageBoxFunction
The fourth argument to MessageBoxcan be acombination of constants beginning with theprefix MB_ that are defined in WINUSER.H.
You can pick one constant from the first set toindicate what buttons you wish to appear in thedialog box:#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
-
8/9/2019 Windows Programming Final
22/22
ProgramFile new-New dialog box, pick the Projects tab
Select Win32 ApplicationType the workspace in your SubDir.
dialog box labeled Win32 Application-appears-choose empty project press FinishProject workspace is created
File new (file tab) select C++ Source File.Type the file Run the program
-