Download presentation
Presentation is loading. Please wait.
1
Visual Programming Lecture 1 & 2
2
Features of DOS Programming
It ”owns” the system: DOS programs generally expect themselves to be the only program running on your computer, so they will directly manipulate the hardware, such as writing to the disk or displaying graphics on the screen. Direct device access: You have full access to the hardware. Your program can directly talk to the hardware i.e. you have full control of the machine. No multitasking/ No multithreading: DOS was designed to perform a single task at a time. A program was loaded from storage to memory, executed to perform a task, and then exited..
3
Features of Windows Programming
Resource sharing Device independent programming Message driven operating system GDI (Graphics Device interface) Multitasking Multithreading
4
Brief History of Win32 1983(?) Windows is announced
Work begins on Word for Windows 1.0 November 1985: Windows 1.0 launched. April 1987: Windows 2.0
5
Brief History of Win32 1988: Windows/286 + /386 Windows goes up to version 2.04 then splits into Windows/286 and Windows/386, the latter supporting multiple DOS boxes. November 1989: Winword 1.0 finally ships: four years after the original scheduled date. May 1990 : Windows 3.0 ships. It operates in 3 modes real (8086 mode as for Windows 2.x) protected ('286) enhanced ('386, with multiple DOS boxes and virtual memory
6
Brief History of Win32 Late 1991: Windows 3.1. Multimedia extensions become part of the standard build Late 1992: Preliminary Win32 API published as NT beta released Win32 on NT offers pre-emptive multitasking Summer 1993: NT 3.1 Launches As well as x86 CPUs, NT becomes available for MIPS and Alpha CPUs.
7
Brief History of Win32 Summer 1994: NT3.5 launches
August 1995: Windows 95 ships September 1995: Windows NT3.51 Still regarded by many as the most solid version of NT for servers Summer 1996: NT4.0 MIPS and PowerPC support is dropped: Alpha becomes the only non-x86 CPU to support Win32 .
8
Brief History of Win32 June 1998: Win98 Ships IE4 is built in
September 1998: Visual Studio 6.0 Feb 2000: Windows 2000 The most significant windows release since Win95. Windows 2000 finally grows up.
9
WYSIWYG (what you see is what you get)
Pronounced wizzy-wig, stands for what you see is what you get. A WYSIWYG application is one that enables you to see on the display screen exactly what will appear when the document is printed. This differs, for example, from word processors that are incapable of displaying different fonts and graphics on the display screen even though the formatting codes have been inserted into the file. WYSIWYG is especially popular for desktop publishing.
10
Multitasking The ability to execute more than one task at the same time, a task being a program. In multitasking, only one CPU is involved, but it switches from one program to another. There are two basic types of multitasking: Preemptive Cooperative/ Non-Preemptive In preemptive multitasking, the operating system parcels out CPU time slices to each program In cooperative multitasking, each program can control the CPU for as long as it needs it, before explicitly returning control to the kernel. This means that a malicious or malfunctioning program may not only prevent any other programs from using the CPU, but it can hang the entire system if it enters an infinite loop.
11
Windows Components Kernel GDI User
12
Kernel The kernel is the inner core of the Windows operating system.
The kernel's primary purpose is to manage the computer's resources and allow other programs to run and use these resources. The kernel is responsible for scheduling and synchronizing threads, processing exceptions and interrupts, loading applications, and managing virtual memory.
13
GDI (Graphics Device interface)
It is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. GDI is responsible for tasks such as drawing lines and curves, rendering fonts and handling palettes. Applications direct output to a specified device by creating a device context for the device. The device context is a GDI-managed structure containing information about the device. An application creates a device context by calling device context functions. GDI returns a device context handle used to identify the device. Using GDI functions, you can draw lines, curves, closed figures, text, and bitmapped images. The color and style of the items you draw depends on the drawing objects you create. GDI provides three drawing objects you can use to create graphics: pens to draw lines and curves, brushes to fill the interiors of closed figures, and fonts to write text.
14
User It is a component of the Microsoft Windows operating system that provides core functionality for building simple user interfaces. Includes functionality for window management, message passing, input processing and standard controls:- Causing windows to be drawn Obscuring overlapping windows behind others Window size and positioning Providing all the standard window management controls (such as close boxes or title bars) Providing the standard Windows menu bar Providing of standard controls (such as button, List box or Edit Box) Providing dialog box management (short-cut keys, tab key processing) Processing all user input from the mouse and keyboard The desktop background image Drawing all standard visual elements Inter-process communication using Dynamic Data Exchange Mouse pointer cursor display and management Data transfer (Clipboard)
15
Win32 Data types Handles in windows
HANDLE data types are some of the most important data objects in Win32 programming. Windows maintains a table of all the different objects that the kernel is responsible for. Windows, buttons, icons, mouse pointers, menus, and so on, all get an entry in the table, and each entry is assigned a unique identifier known as a HANDLE. If you want to pick a particular entry out of that table, you need to give Windows the HANDLE value, and Windows will return the corresponding table entry. HANDLEs are defined as being unsigned 32-bit quantities in <windows.h> HANDLEs are generally prefixed with an “h” A handle is actually a pointer to a pointer to a memory location. In simple words, “Handles are unsigned integers that window used internally to keep track of object in memory”.
16
HWND hwndChild1, hwndChild2...
HWND data types are "Handles to a Window“ They are used to keep track of the various objects that appear on the screen. To communicate with a particular window, you need to have a copy of the window's handle. HWND variables are usually prefixed with the letters "hwnd", just so the programmer knows they are important. Main windows are defined as: HWND hwnd Child windows are defined as: HWND hwndChild1, hwndChild2... Dialog Box handles are defined as: HWND hDlg Although you are free to name these variables whatever you want in your own program, readability and compatibility suffer when an idiosyncratic naming scheme is chosen - or worse, no scheme at all.
17
HINSTANCE These variables are handles to a program instance.
Each program gets a single instance variable, and this is important so that the kernel can communicate with the program. If you want to communicate with another program, it is frequently very useful to have a copy of that program's instance handle. HINSTANCE variables are usually prefixed with an "h", and furthermore, since there is frequently only one HINSTANCE variable in a program, it is canonical to declare that variable as such: HINSTANCE hInstance It is usually a benefit to make this HINSTANCE variable a global value, so that all your functions can access it when needed.
18
Our first Win32 program #include <windows.h>
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, "This is our first Windows Programming Application.", ”Islamic International University", MB_OK); return 0; }
19
The WinMain() Function
Windows calls WinMain() WinMain() function, where execution of the program begins Basic initialization for the rest of the program is also carried out here. To allow Windows to pass data to it, WinMain() has four parameters and a return value of type int. First is instance of the current application. Second parameter is also an instance of this application which is used for the previous application of the same type that is already running. It is used only in Window 16bit editions or Windows 3.1. Windows 32bit editions do not support this parameter. It is here just for compatibility. lpCmdLine, is a pointer to a string containing the command line that started the program.
20
nCmdShow the 4rth parameter is windows style.
It indicates how the window is to look when it is created. It could be displayed normally or it might need to be minimized; This argument can take one of a fixed set of values that are defined by symbolic constants such as SW_SHOWNORMAL SW_SHOWMINNOACTIVE SW_HIDE SW_SHOWMAXIMIZED. There are a number of other constants like these which define the way a window is to be displayed and they all begin SW_. You can study the complete list of the ten possible values for this on WinMain in the MSDN
21
Arguments to WinMain()
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state );
22
The MessageBox() API function
int MessageBox( HWND hWnd, // handle to owner window LPCTSTR lpText, // text in message box LPCTSTR lpCaption, // message box title UINT uType // message box style );
23
The MessageBox() styles
WINUSER.H included in Windows.h #define MB_OK x L #define MB_OKCANCEL x L #define MB_ABORTRETRYIGNORE x L #define MB_YESNOCANCEL x L #define MB_YESNO x L #define MB_RETRYCANCEL x L
24
Example 2: Command Line arguments
#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, GetCommandLine(), ”Islamic International University", MB_OK); return 0; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.