1 / 56

WINDOWS PROGRAMMING

WINDOWS PROGRAMMING. Where the fun starts. WINDOWS 98 (Win32) PROGRAMMING. FROM THE GROUND UP With Application Programming Interface (API) and C++. Key Features of Windows 98. 1. The 32-bit programming environment 2. Thread-based multitasking 3. The call-based interface

johana
Télécharger la présentation

WINDOWS 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. WINDOWS PROGRAMMING Where the fun starts

  2. WINDOWS 98 (Win32) PROGRAMMING FROM THE GROUND UP With Application Programming Interface (API) and C++

  3. Key Features of Windows 98 • 1. The 32-bit programming environment • 2. Thread-based multitasking • 3. The call-based interface • 4. Dynamic Link Libraries

  4. 32-bit Operating System • Windows 3.1 - 16 bit • Windows NT, 95, 98 - 32 bit

  5. Thread-Based Multitasking • Multitasking operating system • Share CPU • process-based multitasking • thread-based multitasking • A thread is an individual unit of executable code within a process.

  6. Call-Based Interface (API) • The call-based interface is an extensive set of system-defined functions that provide access to operating system features. • Collectively these functions are called Application Programming Interface (API).

  7. Dynamic Link Libraries (DLLs) • The Win32 API functions are contained in Dynamic Link Libraries (DLLs). • Dynamic Linking provides: • 1. Disk space from being wasted • 2. Update link library routines • 3. No recompilation required

  8. Two Ways to Program for Window 98 • 1. Use the API functions defined by Win32. In this approach, your programs directly utilize the API and explicitly handle all of the details associated with a Windows 98 program.

  9. WINDOWS PROGRAMMING LANGUAGES • C C++ • BASIC VISUAL BASIC

  10. C++ Windows Programming • 2. The second way to program for Windows 98 uses a special C++ class library, which encapsulate the API. By far the most popular Windows programming class library is MFC (Microsoft Foundation Classes). • It is best employed after you have gained a firm foundation in Windows programming using API!

  11. WinMain( ) • Function must perform the following: • 1. Define a window class • 2. Register that class with Win98 • 3. Create a window of that class. • 4. Display the window • 5. Begin running the message loop.

  12. Windows Data Types • HANDLE is a value that identifies some resources • HWND is a 32-bit integer that is used as a window handle • UINT is an unsigned 32-bit integer • BYTE is an 8-bit unsigned character • WORD is a 16-bit unsigned short integer • DWORD is an unsigned long integer

  13. Windows Data Types • LPSTR is a pointer to a string • LPCSTR is a const pointer to a string • LONG is another name for long • BOOL is an integer

  14. Code Online • Please refer to the following web site for code examples: • http://www.osborne.com

  15. WINDOWS MESSAGES • WM_COMMAND - Sent as the result of a mouse click or key press. • Carries as part of its structure, ID’s of Menu Items, Buttons or Dialog Box Controls selected by the mouse or keyboard. • Other messages can be sent to a window or dialog box by a call to a function inside the program telling the object to behave a certain way.

  16. FLAGS • Determine Window Style or Behavior • Can Be Grouped in a Single Call to a Creation Function in Order to Add Functionality to a Window • hWnd = CreateWindow ( szAppName, /* ClassName */ • ”My Window", /* window title */ • WS_OVERLAPPEDWINDOW, /* window style flag*/ • 70, /* horizontal position */ • 70, /* vertical position */ • 500, /* window width */ etc……... • Flags are Names for an Underlying Number Created with #define in windows.h

  17. MSG BOOL HWND HANDLE WNDCLASS LRESULT WPARAM LPARAM CALLBACK UINT New Data Types

  18. New Files • #include <windows.h> • Resource Files *.rc • Custom Header Files *.h

  19. New Classes • WNDCLASS • structure declaration (data type) in windows.h • contains members and pointers to functions for a basic window.

  20. Visual C++ Windows Programming

  21. Visual C++ • Can call any Win 32 function • Code generated by wizards

  22. Components of Visual C++ • ATL Active Template Library • MFC Microsoft Foundation Class Library • WFC Windows Foundation Class Library

  23. Windows Programming • It is more important to know C++ than it is to know the Win 32 Application Programming Interface API

  24. Win32 vs. Win16 • 32-bit programming for • Microsoft Windows 95, 98, NT • using Win32 API • Compiled MFC programming interface will work on any of the above platforms

  25. Win 32 Programming Features • COM Component Object Model • DAO Data Access Objects • ActiveX Controls • OLE/DB database programming • Dynamic HTML

  26. GDI - Graphic Device Interface • Instead of addressing the hardware, the C program calls GDI functions that reference a data structure called a device context.

  27. Resource-Based Programming • When you program for Windows, you store data in a resource file using a number of established formats. • The linker combines this binary resource file with the C++ compiler’s output to generate an executable program.

  28. Resource Files • Can include: • bitmaps, icons, • menu definitions, • dialog box layouts, strings • and even user defined custom resource formats

  29. Components of Visual C++ • ATL Active Template Library • MFC Microsoft Foundation Class Library • WFC Windows Foundation Class Library

  30. Memory Management • Past memory problems with older versions of Windows • locking memory handles • thunks • burgermasters

  31. Memory Management Win 32 • Virtual Memory • Memory-Mapped Files

  32. DLL - Dynamic Link Libraries • Multiple applications share DLLs • Which saves memory and disk space • You can create your own Extension DLLs which built on the • MFC Microsoft Foundation Class Library.

  33. Visual C++ Files • APS Supports resource view • BSC Browser information file • CLW Support class wizard • DEP Dependency file • DSP Project file

  34. Visual C++ Files • DSW Workspace file • MAK External make file • NCB Support Class View • OPT Holds workspace configuration • PLG Builds log file

  35. Windows Programming Options in C • Program in C with the Win32 API • Write your own C++ Windows class library that uses Win32 • Use the MFC application framework • Use another Windows-based application framework such as Borland’s Object Windows Library OWL

  36. WinMain Function • Windows requires your application to have a WinMain function.

  37. Single Document Interface (SDI) • SDI applications only have 1 window • Windows Notepad is an example

  38. Multiple Document Interface (MDI) • An MDI application has multiple child windows, each of which corresponds to an individual document. • Microsoft Word is a good example.

  39. View - User’s Standpoint • A view is an ordinary window that the user can size, move and close in the same way as any other windows-based application window.

  40. View - Programmer’s Standpoint • A view is a C++ object of a class derived from the MFC library Cview class. • Like any C++ object, the view object’s behavior is determined by the member functions (and data members) of the class.

  41. Building an Application • 1. Run AppWizard to generate SDI application source code. • 2. Compile and link the generated code. • 3. Test the resulting application. • 4. Browse the application.

  42. Resource File • Although the application’s resource script is an ASCII file, modifying it with a text editor is not a good idea. • That’s the resource editors’ job.

  43. Resource File • Accelerator • Definitions for keys that simulate menu and toolbar selections • Dialog • Layout and content of dialog boxes • Icon • 16-by-16 and 32-by-32 pixels

  44. Resource File • Menu • The application’s top-level menu and associated pop-up menus. • String Table • Strings that are not part of the C++ source code.

  45. Resource File • Toolbar • The row of buttons immediately below the menu. • Version • Program description, version number, language, and so on.

  46. Encapsulation • Combining data and the functions that process the data into a single entity. • “Data” refers to the members of a structure or CLASS that hold data. • “Functions” refer to pointers to functions included as members of a structure or CLASS • Window and Dialog Classes Provided by C++ are Actually Structures Set up this Way.

  47. Writing a Windows Program

  48. STEP BY STEP APPROACH

  49. STEP 1 • Initialize the Application . . . • Write a function that does the following: • declare a variable of the WNDCLASS type • fill the members of that variable with values that “customize” your window • call the RegisterClass function, passing your class • return TRUE or FALSE (BOOL) to the main function, based upon whether RegisterClass was successful or not

  50. BOOL InitApplication ( HANDLE hInstance ) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon ( hInstance, IDI_APPLICATION ); wc.hCursor = LoadCursor ( NULL, IDC_ARROW ); wc.hbrBackground = GetStockObject ( WHITE_BRUSH

More Related