Docsity

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

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.