Windows Programming Lecture 13

Slides:



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

1 Windows Programming CIS 577 Bruce R. Maxim UM-Dearborn.
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)
Building a Win32API Application Raw access to the API.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
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.
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.
CSE3AGT Paul Taylor Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.
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.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
Presentation Outline Introduction Painting and Repainting GDI.
Bitmap (Chapter 15).
Chapter2: Drawing a Window. Review: Introducing MFC.
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
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
Introduction to OpenGL
Learning Programming Windows API Morpheus Feb-28, 2008.
Drawing in Windows. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Interface, abbreviated as GDI. – It is.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
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.
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.
Programming windows with MFC Chapter 2 - Drawing in a Window
Presentation Outline Introduction Painting and Repainting GDI.
5/23/2018 Additional Features of WordPad
Windows Programming Lecture 10.
Visual Programming Lecture 1 & 2
Windows Programming Lecture 09.
Window.
Building a Win32API Application
Windows Programming Model
Aspect-Oriented Programming
CSC461 Lecture 8: Input Devices
Graphics and Multimedia
Chapter 1 Editing a Photo
Windows Programming using Dev C++
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Queued and Nonqueued Messages
The program in traditional OS
Windows Controls & Concepts
Made by Aistė Augustinaitė Software Engineering 3 group
Graphic Device Interface
Windows Programming Lecture 12
CS 1253 Visual Programming Unit I Windows Environment
Windows Programming Lecture 15
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
GUI Socket Application
Chapter 14 Drawing in a Window
Chapter 16 Drawing in a Window
Presentation transcript:

Windows Programming Lecture 13

Super-classing Super-classing defines a class that adds new functionality to a predefined window class, such as the button or list box controls. Defines a class with partly modified behavior of a pre-defined window class.

Class Name Class Data

GetClassLong() LONG GetClassLong( HWND hWnd, // handle to window int nIndex // offset of value to retrieve );

Super-classing DLGPROC oldWindowProc; // Global variable WNDCLASS wndClass; GetClassInfo(hInstance, “BUTTON”, &wndClass); wndClss.hInstance = hInstance; wndClass.lpszClassName = “BEEPBUTTON”; OldWindowProc = wndClas.lpfnWndProc; wndClas.lpfnWndProc = myWindowProc; RegisterClass( &wndClass ); hWnd = CreateWindow(“BEEPBUTTON", "Virtual University", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 50, 50, 200, 100, NULL, NULL, hInstance, NULL); oldWindowProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)myWindowProc); while(GetMessage(&msg, NULL, 0, 0) > 0) { if(msg.message == WM_LBUTTONUP) DispatchMessage(&msg); } return msg.wParam;

Super-classing LRESULT CALLBACK myWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) case WM_LBUTTONDOWN: MessageBeep(0xFFFFFFFF); default: return CallWindowProc(oldWindowProc, hWnd, message, wParam, lParam); } return 0;

GDI (Graphics Device Interface) The Windows subsystem responsible for displaying text and images on display devices and printers. The GDI processes graphical function calls from a Windows-based application. It then passes those calls to the appropriate device driver, which generates the output on the display hardware. By acting as a buffer between applications and output devices, the GDI presents a device-independent view of the world for the application while interacting in a device-dependent format with the device. Because of the smaller memory footprint of Windows CE–based devices, Windows CE supports only a subset of the standard Win32 GDI.

Device Context A GDI structure containing information that governs the display of text and graphics on a particular output device. A device context stores, retrieves, and modifies the attributes of graphic objects and specifies graphic modes. The graphic objects stored in a device context include a pen for line drawing, a brush for painting and filling, a font for text output, a bitmap for copying or scrolling, a palette for defining the available colors, and a region for clipping. Device context is released, when Painting is finished.

GDI manages Text printing/drawing Color: foreground and background Font size Font face

Steps involved in output of a text string in the client area of the application Get the handle to the Device Context for the window’s client area from the GDI. Use this Device Context for writing / painting in the client area of the window. Release the Device context.

Printing a text string HDC =hDC; hDC = GetDC(hWnd); TextOut(hDC, 0, 0, "Our First GDI Call",18); ReleaseDC(hWnd, hDC); while(GetMessage(&msg, NULL, 0, 0) > 0) { … … … }

GetDC() hDC = GetDC( hWnd ); The GetDC() function retrieves a handle to a display device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. hDC = GetDC( hWnd );

TextOut() The TextOut() function writes a character string at the specified location, using the currently selected font, background color, and text color.

TextOut() Parameters hdc nXStart nYStart lpString cbString [in] Handle to the device context. nXStart [in] Specifies the logical x-coordinate. nYStart [in] Specifies the logical y-coordinate. lpString [in] Pointer to the string to be drawn. cbString [in] Specifies the length of the string. For the ANSI function it is a BYTE count and for the Unicode function it is a WORD count.

ReleaseDC() int ReleaseDC( The ReleaseDC() function releases a device context (DC), freeing it for use by other applications. int ReleaseDC( HWND hWnd, // handle to window HDC hDC // handle to DC );

WM_PAINT When a minimized window is maximized, Windows requests the application to repaint the client area. Windows sends a WM_PAINT message for repainting a window.

WM_PAINT The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow() or RedrawWindow() function is called, or by the DispatchMessage() function when the application obtains a WM_PAINT message by using the GetMessage() or PeekMessage() function. A window receives this message through its Window Procedure function.

WM_PAINT The WM_PAINT message is generated by the system and should not be sent by an application The DefWindowProc() function validates the update region The system sends this message when there are no other messages in the application's message queue.

WM_PAINT A WM_PAINT message is sent when: Some hidden part of a window becomes visible A window is resized and the window class style has the CS_REDRAW and CS_VREDRAW bits set. Programm scrolls its window InvalidateRect() is called to invalidate some part of a window.

BeginPaint() The BeginPaint() function prepares the specified window for painting and fills a PAINTSTRUCT structure with information about the painting. BeginPaint() first erases the background of window’s client area by sending WM_ERASEBKGND message. BeginPaint() reserves a device context whose handle is returned to the application.

BeginPaint() WM_PAINT message. HDC BeginPaint( HWND hwnd, // handle to window LPPAINTSTRUCT lpPaint // paint information ); If the function succeeds, the return value is the handle to a display device context for the specified window.

EndPaint() EndPaint() is used to free the system resources reserved by the BeginPaint(). This function is required for each call to the BeginPaint() function, but only after painting is complete.

EndPaint() BOOL EndPaint( HWND hWnd, // handle to window CONST PAINTSTRUCT *lpPaint // paint data );

WM_SIZING Repainting when the window is resized Whenever a window is resized, system sends WM_SIZING message to the application that owns the window.

WM_SIZING case WM_SIZING: hDC = GetDC(hWnd); TextOut(hDC, 0, 0, "Our First GDI Call", 18); ReleaseDC(hWnd, hDC); break;

DefWindowProc() erases background of the window using class brush specified while registering the window class.

WM_PAINT To send WM_PAINT message whenever a window is resized, we specify CS_HREDRAW, CS_VREDRAW class styles in WNDCLASS structure while registering the class.