CS 1253 Visual Programming Unit I Windows Environment

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Advertisements

Computer Graphics1 Windows NT Graphics Interface.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
1 CS1253 VISUAL PROGRAMMING UNIT I WINDOWS PROGRAMMING Windows environment – a simple windows program – windows and messages – creating the window – displaying.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
Windows Programming Text and Fonts This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep.
Introduction to the Windows API n API - Application Programming Interface n an API is the software interface for things such as the OS n an API is the.
Microsoft Foundation Classes. What is MFC? Set of C++ classes written by MS Simplifies writing complex programs Covers many areas: – GUI – I/O – O/S interfaces.
Chapter2: Drawing a Window. Drawing with the GDI.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Presentation Outline Introduction Painting and Repainting GDI.
Chapter2: Drawing a Window. Review: Introducing MFC.
Windows Environment History of Windows: Windows was announced by microsoft in november 1983 and was released in november Advantage: Windows 1.0.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
Chapter2: Drawing a Window
Learning Programming Windows API Morpheus Feb-28, 2008.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
W indows Programming Lecture 08. Brief History of Win Windows is announced 1984 Work begins on Word for Windows 1.0 November 1985: Windows 1.0.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Microsoft Foundation Classes MFC
Programming windows with MFC Chapter 2 - Drawing in a Window
Presentation Outline Introduction Painting and Repainting GDI.
Windows Programming Lecture 11
Windows Programming Lecture 10.
Visual Programming Lecture 1 & 2
Chapter 2 – Introduction to the Visual Studio .NET IDE
An Introduction to Computers and Visual Basic
Windows Programming Lecture 09.
Window.
Windows Programming Model
Aspect-Oriented Programming
An Introduction to Computers and Visual Basic
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Advanced Menuing, Introduction to Picking
Queued and Nonqueued Messages
The program in traditional OS
Chapter 2 – Introduction to the Visual Studio .NET IDE
Windows Controls & Concepts
Made by Aistė Augustinaitė Software Engineering 3 group
Graphic Device Interface
Windows Programming Lecture 12
Windows Programming Lecture 13
Teaching slides Chapter 6.
An Introduction to Computers and Visual Basic
Windows Programming Lecture 15
Topics Graphical User Interfaces Using the tkinter Module
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
CS 1253 Visual Programming Unit I Topic 4
Graphics Laboratory Korea University
Chapter 14 Drawing in a Window
Presentation transcript:

CS 1253 Visual Programming Unit I Windows Environment

Visual Programming It allows programming with visual expressions, spatial arrangement of text and grahical symbols. It allows the users to manipulate the programming elements graphically WIN 32 Application Application Framework MFC AppWizard(exe) 17-Feb-19 Shyamala devi.M

Overview of syllabus Windows Programming Visual C++ Programming – Introduction Document and View Architecture ActiveX Controls and Object Linking and Embedding Advanced Concepts in VC++ 17-Feb-19

Unit I - Presentation Outline Windows environment Windows and messages Creating the window Displaying the window Message loop Window procedure Message processing Text output Introduction to GDI Device context Basic drawing Child window controls 17-Feb-19 Shyamala devi.M

Windows environment History of windows Aspects of windows Dynamic linking 17-Feb-19

History of windows Windows was announced by Microsoft Corporation in November 1983 (post-Lisa, pre-Macintosh) – drivers for video display and printers Windows 2.0 (1987) – keyboard and mouse interface, running in real mode and access 1MB of memory. Windows 3.0 (1990) – protected mode and access 16 MB and has GPM and provides GUI Windows version 3.1 (1992) – TTFT, OLE , Multimedia Windows NT, introduced in 1993 - Networking Windows 95 (1995) –lacks security and portability Windows 98 (1998) – H/W support and integrated to Internet Windows 98 and Windows NT are 32-bit preemptive multitasking. 17-Feb-19

Aspects of windows Earlier versions of Windows are nonpreemptive - no timeslicer Graphical user interface (GUI) - "visual interface" or "graphical windowing environment.“ WYSIWYG (what you see is what you get). In GUI - the video display itself becomes a source of user input. Interaction between the user and a program becomes more intimate. All applications have the same fundamental look and feel. Window - usually a rectangular area on the screen. Programs running in Windows can share routines that are located in other files called "dynamic-link libraries." 17-Feb-19 Shyamala devi.M

Dynamic linking Exported functions are implemented in dynamic-link libraries, DLLs. When we run a Windows program, it interfaces to Windows through a process called "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, which are also loaded into memory. When we link a Windows program to produce an executable file, we must link with special "import libraries". These import libraries contain the dynamic-link library names and reference information for all the Windows function calls. 17-Feb-19

Windows and messages A window is a rectangular area on the screen that receives user input and displays output in the form of text and graphics. The window receives the user input in the form of "messages" to the window. TWO PARTS Window class Window procedure 17-Feb-19 Shyamala devi.M

Window class Window is always created based on the features called "window class." The window class sends the messages to the window procedure. Multiple windows on the same window class use same window procedure. Main subsystem of windows Kernel - HInstance User - Hwnd GDI - Hdc 17-Feb-19

Window procedure Every window has an associated window procedure. It is a function that could be either in the program itself or in a dynamic-link library. Window procedure process the message given by the window class. Two types of messages Queued messages Non queued messages 17-Feb-19

Window Flow Diagram Messages Window class Message loop Window procedure Processed message 17-Feb-19

Hungarian Notation Hungarian notation system is the process of prefacing the variable name with a short prefix that indicates the data type of the variable. For example, the sz prefix in szCmdLine stands for "string terminated by zero." The h prefix in hInstance and hPrevInstance stands for "handle;" The i prefix in iCmdShow stands for "integer." 17-Feb-19

For example, in the WinMain function, the msg variable is a structure of the MSG type; wndclass is a structure of the WNDCLASS type. typedef struct tagMSG { HWND hwnd ; UINT message ; WPARAM wParam ; LPARAM lParam ; DWORD time ; POINT pt ; } 17-Feb-19

Creating the window hwnd = CreateWindow (szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters 17-Feb-19

Creating the Window –Overlapped window #define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \ WS_CAPTION | \ WS_SYSMENU | \ WS_THICKFRAME | \ WS_MINIMIZEBOX | \ WS_MAXIMIZEBOX) In WINUSER.H, this style is a combination of several bit flag The CreateWindow call returns a handle to the created window. 17-Feb-19

Registering the window class if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } 17-Feb-19

Displaying the window After the CreateWindow call returns, the window has been created internally in Windows. Windows has allocated a block of memory to hold all the information about the window. Two calls are needed to make the window for dispaly. ShowWindow (hwnd, iCmdShow) ;  The ShowWindow function puts the window on the display. UpdateWindow (hwnd) ;  causes the client area to be painted this by sending the window procedure a WM_PAINT message. 17-Feb-19 Shyamala devi.M

Message Loop while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } Windows maintains a "message queue" for each Windows. When an input event occurs, Windows translates the event into a "message" and it is placed in the program's message queue. A program retrieves these messages from the message queue by executing a block of code known as the "message loop“ TranslateMessage (&msg) ; passes the msg structure back to Windows for some keyboard translation. DispatchMessage (&msg) ; again passes the msg structure back to Windows. Windows then sends the message to the appropriate window procedure for processing 17-Feb-19 Shyamala devi.M

Window procedure The window procedure determines what the window displays in its client area and how the window responds to user input. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) Window procedure gets the messages from the window class and processes it. It identifies the messages by its message id. 17-Feb-19 Shyamala devi.M

Message processing Every message that a window procedure receives is identified by a number, which is the message parameter to the window procedure. The Windows header file WINUSER.H defines identifiers beginning with the prefix WM ("window message") for each type of message. When a window procedure processes a message, it should return 0 from the window procedure. All unprocessed messages must be passed to a Windows function DefWindowProc. 17-Feb-19 Shyamala devi.M

[process WM_CREATE message] return 0 ; case WM_PAINT : switch (iMsg) { case WM_CREATE : [process WM_CREATE message] return 0 ; case WM_PAINT : [process WM_PAINT message] case WM_DESTROY : [process WM_DESTROY message] } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; 17-Feb-19 Shyamala devi.M

17-Feb-19 Shyamala devi.M

Program Entry Point int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) HEADER FILES : 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. PROGRAM MESSAGE BOX FUNCTION: MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0) ; Body of the message box Caption bar 17-Feb-19

Overall window creation Window Main Variable declarations Window class registration Checking the registration Creating the window Displaying the window Message loop Window procedure WM_CREATE WM_PAINT WM_DESTROY DefWindowProc Program 17-Feb-19

Text output Painting and repainting WM_PAINT Valid and In-valid rectangles 17-Feb-19 Shyamala devi.M

Painting and Repainting When a program displays text or graphics in its client area, it is said to be "painting" its client area. Windows informs a window procedure that the client area needs painting by sending a WM_PAINT message. WM_PAINT Message When the Windows call the function UpdateWindow during initialization in WinMain, it calls WM_PAINT message. This message informs the window procedure that the client area must be painted. Then the window procedure should be ready at any time to process additional WM_PAINT messages and even to repaint the entire client area. 17-Feb-19

Previously hidden area of the window is brought into view A window procedure receives a WM_PAINT message whenever one of the following events occurs: Previously hidden area of the window is brought into view when a user moves a window or uncovers a window. The user resizes the window. The program uses the ScrollWindow or ScrollDC function to scroll part of its client area. The program uses the InvalidateRect or InvalidateRgn function to explicitly generate a WM_PAINT message. Windows removes a dialog box or message box that was overlaying part of the window. A menu is pulled down and then released. A tool tip is displayed. The mouse cursor is moved across the client area. An icon is dragged across the client area. 17-Feb-19

Valid and Invalid rectangles Window procedure should be prepared to update the entire client area whenever it receives a WM_PAINT message It needs to update only a smaller area, most often a rectangular area within the client area. Repainting is required only for the rectangular area uncovered when the dialog box is removed. That area is known as an "invalid region" or "update region.“ Windows internally maintains a "paint information structure" for each window. This structure contains the coordinates of the smallest rectangle that encompasses the invalid region. This is known as the "invalid rectangle.“ 17-Feb-19 Shyamala devi.M

Windows does not place multiple WM_PAINT messages in the message queue. A window procedure can invalidate a rectangle in its own client area by calling InvalidateRect. A program can also validate any rectangular area within the client area by calling the ValidateRect function. A window procedure can obtain the coordinates of the invalid rectangle when it receives a WM_PAINT message by calling GetUpdateRect. 17-Feb-19

INTRODUCTION TO GDI DEVICE CONTEXT Getting the device context – method one Paint information structure Getting the device context – method two Textmetric details 17-Feb-19

Device context Device Context ("DC") is a data structure maintained internally by GDI. A device context is associated with a particular display device, such as a video display or a printer. The values in the device context are graphics "attributes." These attributes defines how the GDI drawing functions work. When a program needs to paint, it must first obtain a handle to a device context. When we obtain this handle, Windows fills the internal device context structure with default attribute values. 17-Feb-19

Getting the device context – method one case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; [use GDI functions] EndPaint (hwnd, &ps) ; return 0 ; We use DrawText() to display the text on the client area of the window. Paint information structure: typedef struct tagPAINTSTRUCT { HDC hdc ; BOOL fErase ;  0 means already erased RECT rcPaint ;  Structure of type Rect (left, right, top, bottom ) BOOL fRestore ; BOOL fIncUpdate ; BYTE rgbReserved[32] ; } PAINTSTRUCT ; 17-Feb-19

Getting the device context – method two case WM_PAINT: { hdc = GetDC (hwnd) ; [use GDI functions] ReleaseDC (hwnd, hdc) ; } We use TextOut GDI function for displaying text and so we need textmetric details. TextOut (hdc, x, y, psText, iLength) ; 17-Feb-19

TEXTMETRIC typedef struct tagTEXTMETRIC { LONG tmHeight ; LONG tmAscent ; LONG tmDescent ; LONG tmInternalLeading ; LONG tmExternalLeading ; LONG tmAveCharWidth ; LONG tmMaxCharWidth ; [other structure fields] }TEXTMETRIC, * PTEXTMETRIC ; 17-Feb-19

Text Metric structure : 17-Feb-19

Basic Drawing Structure of GDI Device context Drawing dots and lines GDI mapping modes Rectangles, regions and clipping 17-Feb-19

Structure of GDI The primary goals of GDI is to support device-independent graphics. Windows programs should be able to run without problems on any graphics output device. Two groups of graphics output devices Raster devices Vector devices. Raster devices represent images as a rectangular pattern of dots. (video display adapters, dot-matrix printers, and laser printers.) Vector devices draw images using lines 17-Feb-19

GDI Function Calls GDI Primitives Functions that get (or create) and release (or destroy) a device context (GetDC and ReleaseDC ) Functions that obtain information about the device context (GetTextMetrics) Functions that draw something (TextOut) Functions that set and get attributes of the device context (SetTextColor) Functions that work with GDI objects (CreatePen) GDI Primitives Lines and curved Lines Filled areas Bitmaps Text 17-Feb-19

Device context hdc = BeginPaint (hwnd, &ps) ; [other program lines] EndPaint (hwnd, &ps) ; hdc =GetDC (hwnd) ; ReleaseDC (hwnd, hdc) ; hdc = GetWindowDC (hwnd) ; hdc =CreateDC (pszDriver, pszDevice, pszOutput, pData) ; DeleteDC (hdc) ; 17-Feb-19

Drawing Dots and Lines Setting Pixels Straight Lines Bounding Box Functions Stock Pens Creating, Selecting, and Deleting Pens Filling the Gaps Drawing Mapping Modes 17-Feb-19

Setting the pixel GetPixel SetPixel The GetPixel function returns the color of the pixel at the specified coordinate position: crColor = GetPixel (hdc, x, y) ; The SetPixel function sets the pixel at a specified x- and y-coordinate to a particular color: SetPixel (hdc, x, y, crColor) ; 17-Feb-19

Straight lines Windows can draw straight lines, elliptical lines and Bezier splines. Windows 98 supports seven functions that draw lines: LineTo Draws a straight line. Polyline and PolylineTo Draw a series of connected straight lines. PolyPolyline Draws multiple polylines. Arc Draws elliptical lines. PolyBezier and PolyBezierTo Draw Bezier splines. 17-Feb-19

Straight lines Five attributes of the device context affect the appearance of lines that we draw using these functions: current pen position (for LineTo, PolylineTo, PolyBezierTo, and ArcTo only), pen background mode background color and Drawing mapping mode. To draw a straight line, we must call two functions. MoveToEx (hdc, xBeg, yBeg, NULL) ; LineTo (hdc, xEnd, yEnd) ; PROGRAM MoveToEx sets the "current position" that specifies the point at which the line begins The LineTo function draws a straight line from the current position to the the end point of the line specified in Lineto function. 17-Feb-19