windows programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
WINDOWS PROGRAMMING PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 56

WINDOWS PROGRAMMING - PowerPoint PPT Presentation

  • Uploaded on

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

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'WINDOWS PROGRAMMING' - johana

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
windows programming



the fun


windows 98 win32 programming



With Application Programming Interface (API) and C++

key features of windows 98
Key Features of Windows 98
  • 1. The 32-bit programming environment
  • 2. Thread-based multitasking
  • 3. The call-based interface
  • 4. Dynamic Link Libraries
32 bit operating system
32-bit Operating System
  • Windows 3.1 - 16 bit
  • Windows NT, 95, 98 - 32 bit
thread based multitasking
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.
call based interface api
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).
dynamic link libraries dlls
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
two ways to program for window 98
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.
windows programming languages
  • C C++
c windows programming
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!
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.
windows data types
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
windows data types1
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
code online
Code Online
  • Please refer to the following web site for code examples:
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.
  • 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
new data types










New Data Types
new files
New Files
  • #include <windows.h>
  • Resource Files *.rc
  • Custom Header Files *.h
new classes
New Classes
  • structure declaration (data type) in windows.h
  • contains members and pointers to functions for a basic window.
visual c

Visual C++

Windows Programming

visual c1
Visual C++
  • Can call any Win 32 function
  • Code generated by wizards
components of visual c
Components of Visual C++
  • ATL Active Template Library
  • MFC Microsoft Foundation Class Library
  • WFC Windows Foundation Class Library
windows programming1
Windows Programming
  • It is more important to know C++ than it is to know the Win 32 Application Programming Interface API
win32 vs win16
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
win 32 programming features
Win 32 Programming Features
  • COM Component Object Model
  • DAO Data Access Objects
  • ActiveX Controls
  • OLE/DB database programming
  • Dynamic HTML
gdi graphic device interface
GDI - Graphic Device Interface
  • Instead of addressing the hardware, the C program calls GDI functions that reference a data structure called a device context.
resource based programming
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.
resource files
Resource Files
  • Can include:
  • bitmaps, icons,
  • menu definitions,
  • dialog box layouts, strings
  • and even user defined custom resource formats
components of visual c1
Components of Visual C++
  • ATL Active Template Library
  • MFC Microsoft Foundation Class Library
  • WFC Windows Foundation Class Library
memory management
Memory Management
  • Past memory problems with older versions of Windows
  • locking memory handles
  • thunks
  • burgermasters
memory management win 32
Memory Management Win 32
  • Virtual Memory
  • Memory-Mapped Files
dll dynamic link libraries
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.
visual c files
Visual C++ Files
  • APS Supports resource view
  • BSC Browser information file
  • CLW Support class wizard
  • DEP Dependency file
  • DSP Project file
visual c files1
Visual C++ Files
  • DSW Workspace file
  • MAK External make file
  • NCB Support Class View
  • OPT Holds workspace configuration
  • PLG Builds log file
windows programming options in c
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
winmain function
WinMain Function
  • Windows requires your application to have a WinMain function.
single document interface sdi
Single Document Interface (SDI)
  • SDI applications only have 1 window
  • Windows Notepad is an example
multiple document interface mdi
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.
view user s standpoint
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.
view programmer s standpoint
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.
building an application
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.
resource file
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.
resource file1
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
resource file2
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.
resource file3
Resource File
  • Toolbar
    • The row of buttons immediately below the menu.
  • Version
    • Program description, version number, language, and so on.
  • 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.
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

BOOL InitApplication ( HANDLE hInstance )



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

bool initapplication handle hinstance
BOOL InitApplication ( HANDLE hInstance )
  • wc.lpszMenuName = NULL;
  • wc.lpszClassName = szAppName;
  • if ( !RegisterClass ( &wc ) )
  • return ( FALSE );
  • return ( TRUE );
  • }
step 2
  • Initialize an ‘Instance’ of the Application
    • Write a function to do the following:
      • Assign the current instance to a global variable for use by other windows and dialog boxes in the program.
      • Call the CreateWindow function, passing the App Name as specified in your class, the window’s position and size, handles to parent and child windows and the handle to the current instance.
      • If the window could not be created, return FALSE, otherwise call the ShowWindow function to display the window.
bool initinstance handle hinstance int ncmdshow
BOOL InitInstance ( HANDLE hInstance, int nCmdShow )
  • {hInst = hInstance; /* assign instance to global variable */
  • hWnd = CreateWindow ( szAppName, /* ClassName */
  • ”My Window", /* window title */
  • WS_OVERLAPPEDWINDOW, /* window style flag*/
  • 70, /* horizontal position */
  • 70, /* vertical position */
  • 500, /* window width */
  • 350, /* window height */
  • NULL, /* handle of parent window */
  • NULL, /* handle of child or menu */
  • hInstance, /* handle of app instance */
  • NULL ); /* window creation data */
  • if ( !hWnd ) /* If window could not be created, return "failure” */
  • return ( FALSE );
  • ShowWindow ( hWnd, nCmdShow ); /* Show the window */
  • return ( TRUE ); /* Returns the value from PostQuitMessage */
  • }
back in main
  • Make Calls to Your InitApplication and InitInstance Functions.
  • Write a Windows Message Loop that Continuously Checks for New Messages (such as the click of a mouse button or press of a key on the keyboard)
  • When a Message is Received, the WNDCLASS Window you Created will Call the Window Procedure it points to (MainWndProc).
step 3
  • Handle the Windows Messages Received
    • Write MainWndProc, which does the following:
      • Use nested switch constructs to handle valid windows messages expected by the main window.
      • Makes calls to other procedures such as Dialog Box procedures, when necessary for handling messages to other resources.
lresult callback mainwndproc hwnd hwnd uint message wparam wparam lparam lparam
LRESULT CALLBACK MainWndProc ( HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam )
  • {
  • switch ( message )
  • {
  • case WM_COMMAND: /* Menu Selection or Dialog Box Control */
  • switch (wParam)
  • { case CM_EXIT: /* ID of the EXIT menu item */
  • DestroyWindow ( hWnd );
  • case CM_MESSAGE_TO_SCREEN; /* another menu item */
  • MessageBox( hWnd, "Message Text", ”Message Title", MB_OK);
  • default:
  • return ( DefWindowProc ( hWnd, message, wParam, lParam ) );
  • }
  • default:
  • return ( DefWindowProc ( hWnd, message, wParam, lParam ) );
  • }
  • }