CS 1253 VISUAL PROGRAMMING UNIT I WINDOWS PROGRAMMING

  • Slides: 48
Download presentation
CS 1253 VISUAL PROGRAMMING UNIT I WINDOWS PROGRAMMING Windows environment – a simple windows

CS 1253 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 1

CS 1253 VISUAL PROGRAMMING UNIT II VISUAL C++ PROGRAMMING – INTRODUCTION Application Framework –

CS 1253 VISUAL PROGRAMMING UNIT II VISUAL C++ PROGRAMMING – INTRODUCTION Application Framework – MFC library – Visual C++ Components – Event Handling – Mapping modes – colors – fonts – modal and modeless dialog – windows common controls – bitmaps 2

CS 1253 VISUAL PROGRAMMING UNIT III THE DOCUMENT AND VIEW ARCHITECTURE Menus – Keyboard

CS 1253 VISUAL PROGRAMMING UNIT III THE DOCUMENT AND VIEW ARCHITECTURE 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 3

CS 1253 VISUAL PROGRAMMING UNIT IV ACTIVEX AND OBJECT LINKING AND EMBEDDING (OLE) Active.

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

CS 1253 VISUAL PROGRAMMING UNIT-V ADVANCED CONCEPTS Database Management with Microsoft ODBC – Structured

CS 1253 VISUAL PROGRAMMING 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 – Win. Inet – building a web client – Internet Information Server – ISAPI server extension – chat application – playing and multimedia (sound and video) files 5

CS 1253 VISUAL PROGRAMMING TEXT BOOKS 1. Charles Petzold, “Windows Programming”, Microsoft press, 1996

CS 1253 VISUAL PROGRAMMING TEXT BOOKS 1. Charles Petzold, “Windows Programming”, Microsoft press, 1996 (Unit I – Chapter 1 -9) 2. David J. Kruglinski, George Shepherd and Scot Wingo, “Programming Visual C++”, Microsoft press, 1999 (Unit II – V) REFERENCES 1. Steve Holtzner, “Visual C++ 6 Programming”, Wiley Dreamtech India Pvt. Ltd. , 2003. 6

UNIT – I Windows Programming Text Book : Charles Petzold, “Windows Programming”, Microsoft press,

UNIT – I Windows Programming Text Book : Charles Petzold, “Windows Programming”, Microsoft press, 1996 (Unit I – Chapter 1 -9) 7

Windows Programming History of Windows: Ø IBM PC – 1981 OS – MSDOS (

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. 8

Windows Programming History of Windows: • For the application programmer, MS-DOS offered little more

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. 9

Windows Programming History of Windows: Ø Apple Computer – Jan 1983 • OS -

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) 10

Windows Programming History of Windows: Ø Windows 1. 0 • Nov 1985. • with

Windows Programming History of Windows: Ø Windows 1. 0 • Nov 1985. • with several updates to support the international market. • with additional drivers for additional video displays and printers. 11

Windows Programming History of Windows: Ø Windows 2. 0 • Nov 1987. • with

Windows Programming History of Windows: Ø Windows 2. 0 • Nov 1987. • with several changes to the user interface. • also enhancements to the keyboard and mouse interface, particularly for menus and dialog boxes. 12

Windows Programming History of Windows: Ø Windows 2. 0 • requires only Intel 8086

Windows Programming History of Windows: Ø Windows 2. 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. 13

Windows Programming History of Windows: Ø Windows/286 • Windows 2. 1 was renamed Windows/286.

Windows Programming History of Windows: Ø Windows/286 • Windows 2. 1 was renamed Windows/286. Ø Windows 3. 0 • May 22, 1990. • Windows/286 and Windows/386 versions were merged into one product with this release. 14

Windows Programming History of Windows: Ø Windows 3. 1 – April 1992 • several

Windows Programming History of Windows: Ø Windows 3. 1 – April 1992 • several significant features included the True. Type 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. 15

Windows Programming History of Windows: Ø Windows. NT – July 1993 • was the

Windows Programming History of Windows: Ø Windows. NT – 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. 16

Windows Programming History of Windows: Ø Windows 95 – Aug 1995 • also supported

Windows Programming History of Windows: Ø Windows 95 – 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. 17

Windows Programming History of Windows: Ø Windows 95 – June 1998 • has a

Windows Programming History of Windows: Ø Windows 95 – 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. 18

Windows Programming Dynamic Linking: Ø Windows provides function calls that an application needs to

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 Win 98 - WINDOWSSYSTEM Win. NT - WINNTSYSTEM and WINNTSYSTEM 32 19

Windows Programming Dynamic Linking: Ø In the early days, Windows was implemented in just

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. 20

Windows Programming Dynamic Linking: Ø Windows 98 supports several thousand function calls that applications

Windows Programming Dynamic Linking: Ø Windows 98 supports several thousand function calls that applications can use. Ø Each function has a descriptive name, such as Create. Window. • This function creates a window for the program. • All the Windows functions that an application may use are declared in header files. 21

Windows Programming Dynamic Linking: Ø In Windows program, we use the Windows function calls

Windows Programming Dynamic Linking: Ø In Windows program, we use the Windows function calls same as C library functions like strlen. Ø Difference – • The machine code for C library functions is linked into program code. • whereas the code for Windows functions is located outside of the program in the DLLs. 22

Windows Programming Dynamic Linking: Ø When you run a Windows program, • it interfaces

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. 23

Windows Programming Dynamic Linking: Ø When a Windows program is loaded into memory, •

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. 24

Windows Programming Dynamic Linking: Ø When link a Windows program to produce an executable

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. 25

Simple Windows Program First Windows Program: Ø The Windows program has exactly the same

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. 26

Simple Windows Program First Windows Program: For Example, Ø To display "Hello Welcome!!!” in

Simple Windows Program First Windows Program: For Example, Ø To display "Hello Welcome!!!” in a message box. #include <windows. h> int WINAPI Win. Main (HINSTANCE h. Instance, HINSTANCE h. Prev. Instance, PSTR sz. Cmd. Line, int i. Cmd. Show) { Message. Box (NULL, TEXT ("Hello Welcome!!!"), TEXT ("Hello. Msg"), 0) ; return 0 ; } 27

Simple Windows Program First Windows Program: Ø The header file STDIO. H has been

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 Win. Main. Ø The C run-time library function printf has been replaced with the Windows API function Message. Box. Ø However, there is much in the program that is new, including several strange-looking uppercase identifiers. 28

Simple Windows Program The Header Files: Ø #include <windows. h> WINDOWS. H is a

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 WINNT. H WINBASE. H WINUSER. H WINGDI. H - Basic type definitions. - Type definitions for Unicode support. - Kernel functions. - User interface functions. - Graphics device interface functions. 29

Simple Windows Program The Header Files: Ø These header files define all the Windows

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. 30

Simple Windows Program Entry Point: Ø Just as the entry point to a C

Simple Windows Program Entry Point: Ø Just as the entry point to a C program is the function main, the entry point to a Windows program is Win. Main, which always appears like this: Ø int WINAPI Win. Main (HINSTANCE h. Instance, HINSTANCE h. Prev. Instance, PSTR sz. Cmd. Line, int i. Cmd. Show) Ø This entry point is documented in, /Platform SDK/User Interface Services/Windowing/Windows/Window Reference/Window Functions. 31

Simple Windows Program Entry Point: Ø It is declared in WINBASE. H like so

Simple Windows Program Entry Point: Ø It is declared in WINBASE. H like so (line breaks and all): int WINAPI Win. Main( HINSTANCE h. Instance, HINSTANCE h. Prev. Instance, LPSTR lp. Cmd. Line, int n. Show. Cmd ); v LPSTR & PSTR are two data types defined in WINNT. H as pointers to character strings. v The LP prefix stands for "long pointer“. 32

Simple Windows Program Prefix b c or ch clr cx, cy dw h l

Simple Windows Program Prefix b c or ch clr cx, cy dw h l n p sz w wnd str m_ Data Type BOOL char COLORREF Horizontal or vertical distance DWORD Handle LONG int Pointer Zero-terminated string WORD CWnd CString class member variable Hungarian Notation Note: Prefixes can be combined: psz. Name m_n. Age 33

Simple Windows Program Entry Point: Win. Main Parameters: Ø First parameter - • It

Simple Windows Program Entry Point: Win. Main 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. 34

Simple Windows Program Entry Point: Win. Main Parameters: Ø Second parameter - • A

Simple Windows Program Entry Point: Win. Main Parameters: Ø Second parameter - • A program could determine if other instances of itself were running by checking the h. Prev. Instance 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 Win. Main is always NULL (defined as 0). 35

Simple Windows Program Entry Point: Win. Main Parameters: Ø Third parameter - • is

Simple Windows Program Entry Point: Win. Main 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. 36

Simple Windows Program Message. Box Function: Ø It is designed to display short messages.

Simple Windows Program Message. Box Function: Ø It is designed to display short messages. Ø The little window that Message. Box displays is actually considered to be a dialog box, although not one with a lot of versatility. For example, Message. Box (NULL, TEXT ("Hello, Windows 98!"), TEXT("Hello. Msg"), 0) ; 37

Simple Windows Program Message. Box Function: Parameters: Ø First Parameter - is normally a

Simple Windows Program Message. Box 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. 38

Simple Windows Program Message. Box Function: Parameters: Ø Fourth Parameter - can be a

Simple Windows Program Message. Box 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: 39

Simple Windows Program Message. Box Function: Buttons: #define MB_OK 0 x 0000 L #define

Simple Windows Program Message. Box Function: Buttons: #define MB_OK 0 x 0000 L #define MB_OKCANCEL 0 x 00000001 L #define MB_ABORTRETRYIGNORE 0 x 00000002 L #define MB_YESNOCANCEL 0 x 00000003 L #define MB_YESNO 0 x 00000004 L #define MB_RETRYCANCEL 0 x 00000005 L v Note: When set the fourth argument to 0, only the OK button appears in the message box. 40

Simple Windows Program Message. Box Function: Buttons: Ø can use the OR (|) operator

Simple Windows Program Message. Box Function: Buttons: Ø can use the OR (|) operator to combine of the constants shown above with a constant that indicates which of the buttons is the default: #define MB_DEFBUTTON 1 0 x 0000 L #define MB_DEFBUTTON 2 0 x 00000100 L #define MB_DEFBUTTON 3 0 x 00000200 L #define MB_DEFBUTTON 4 0 x 00000300 L 41

Simple Windows Program Message. Box Function: Buttons: Ø can also use a constant that

Simple Windows Program Message. Box Function: Buttons: Ø can also use a constant that indicates the appearance of an icon in the message box: #define MB_ICONHAND 0 x 00000010 L #define MB_ICONQUESTION 0 x 00000020 L #define MB_ICONEXCLAMATION 0 x 00000030 L #define MB_ICONASTERISK 0 x 00000040 L 42

Simple Windows Program Message. Box Function: Buttons: Ø Some of these icons have alternate

Simple Windows Program Message. Box Function: Buttons: Ø Some of these icons have alternate names: #define MB_ICONWARNING MB_ICONEXCLAMATION #define MB_ICONERROR MB_ICONHAND #define MB_ICONINFORMATION MB_ICONASTERISK #define MB_ICONSTOP MB_ICONHAND 43

Simple Windows Program Compile, Link and Run: Ø When ready to compile HELLOMSG, select

Simple Windows Program Compile, Link and Run: Ø When ready to compile HELLOMSG, select Build Hellomsg. exe from the Build menu, or press F 7, or select the Build icon from the Build toolbar. Ø Alternatively, select Execute Hellomsg. exe from the Build menu, or press Ctrl+F 5, or click the Execute Program icon from the Build toolbar. Ø Will get a message box asking you if you want to build the program. 44

Simple Windows Program Compile, Link and Run: Ø During the compile stage, • the

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. 45

Simple Windows Program Compile, Link and Run: Import Libraries: Ø In particular, KERNEL 32.

Simple Windows Program Compile, Link and Run: Import Libraries: Ø In particular, KERNEL 32. LIB, USER 32. LIB, and GDI 32. 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. 46

Simple Windows Program Compile, Link and Run: Import Libraries: Ø Windows uses this information

Simple Windows Program Compile, Link and Run: Import Libraries: Ø Windows uses this information to resolve calls from the program to functions in the KERNEL 32. DLL, USER 32. DLL and GDI 32. 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. 47

Simple Windows Program Compile, Link and Run: Configuration Files: Ø The executable files are

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. 48