1 / 48

CS1253 VISUAL PROGRAMMING

CS1253 VISUAL PROGRAMMING. UNIT I WINDOWS PROGRAMMING

brinly
Download Presentation

CS1253 VISUAL PROGRAMMING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1253 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

  2. CS1253 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

  3. CS1253 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

  4. CS1253 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

  5. CS1253 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 – WinInet – building a web client – Internet Information Server – ISAPI server extension – chat application – playing and multimedia (sound and video) files

  6. CS1253 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.

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

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

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

  10. Windows Programming History of Windows: • Apple Computer – Jan 1983 • OS - Lisa • set a standard for graphical environmentswith Macintosh in Jan 1984. • Windows • announced by Microsoft corporation in Nov 1983 (post-Lisa but pre-Macintosh)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  32. 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“.

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

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

  35. 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).

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

  37. 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) ;

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

  39. 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:

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

  41. Simple Windows Program MessageBox Function: Buttons: • can use the OR (|) operator to combine one of the constants shown above with a constant that indicates which of the buttons is the default: #define MB_DEFBUTTON1 0x00000000L #define MB_DEFBUTTON2 0x00000100L #define MB_DEFBUTTON3 0x00000200L #define MB_DEFBUTTON4 0x00000300L

  42. Simple Windows Program MessageBox Function: Buttons: • can also use a constant that indicates the appearance of an icon in the message box: #define MB_ICONHAND 0x00000010L #define MB_ICONQUESTION 0x00000020L #define MB_ICONEXCLAMATION 0x00000030L #define MB_ICONASTERISK 0x00000040L

  43. Simple Windows Program MessageBox 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

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

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

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

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

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

More Related