Windows Programming: Super-classing, GDI, and Text Output, Slides of Windows Programming

An introduction to super-classing in windows programming, where a new class is defined to add functionality to a predefined window class. The text also covers the graphics device interface (gdi) and the process of outputting text in a window's client area. Additionally, the document explains the concept of device contexts and the steps involved in printing a text string.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

parasad
parasad 🇮🇳

4.5

(56)

131 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Windows Programming
Lecture 13
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Windows Programming: Super-classing, GDI, and Text Output and more Slides Windows Programming in PDF only on Docsity!

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.

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; }

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.

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 the Device Context for writing /

painting in the client area of the window.

  • Release the Device context.

GetDC()

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.

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 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.
  • Program scrolls its window
  • InvalidateRect() is called to invalidate some part of a window.

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.