Z Order-Windows Programming-Lecture Notes, Study notes of Windows Programming

This lecture handout is for Windows Programming course. It was provided by Prof. Jaimini Chinmay at Ambedkar University, Delhi. It includes: Order, Windows, Review, Child, Client, Area, Client, Parent, Int, Function, Height, Popup, Overlapped

Typology: Study notes

2011/2012

Uploaded on 08/07/2012

anishay
anishay 🇮🇳

4.2

(25)

118 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Windows Management 2
15.1 Z-Order
The Z order of a window indicates the window's position in a stack of overlapping
windows. This window stack is oriented along an imaginary axis, the z-axis,
extending outward from the screen.
The window at the top of the Z order overlaps all other windows.
The window at the bottom of the Z order is overlapped by all other windows.
15.2 Windows Review
15.2.1 CreateWindow
CreateWindow function have been discussing in our previous lectures. Much of its details
including styles, class name, parent handles, instance handle and coordinates, etc have
been discussed in chapter 11.
CreateWindow Function is used to create window. CreateWindow function can create
parent, child, popup and overlapped windows with dimensions x, y, width and height.
HWND CreateWindow
(
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // window-creation data
);
15.2.2 Child Windows
Following are the characteristics of child windows.
A child window always appears within the client area of its parent window.
Child windows are most often as controls.
A child window sends WM_COMMAND notification messages to its parent
window.
docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Z Order-Windows Programming-Lecture Notes and more Study notes Windows Programming in PDF only on Docsity!

15.1 Z-Order

  • The Z order of a window indicates the window's position in a stack of overlapping windows. This window stack is oriented along an imaginary axis, the z-axis, extending outward from the screen.
  • The window at the top of the Z order overlaps all other windows.
  • The window at the bottom of the Z order is overlapped by all other windows.

15.2 Windows Review

15.2.1 CreateWindow

CreateWindow function have been discussing in our previous lectures. Much of its details including styles, class name, parent handles, instance handle and coordinates, etc have been discussed in chapter 11. CreateWindow Function is used to create window. CreateWindow function can create parent, child, popup and overlapped windows with dimensions x, y, width and height.

HWND CreateWindow ( LPCTSTR lpClassName, // registered class name LPCTSTR lpWindowName, // window name DWORD dwStyle, // window style int x, // horizontal position of window int y, // vertical position of window int nWidth, // window width int nHeight, // window height HWND hWndParent, // handle to parent or owner window HMENU hMenu, // menu handle or child identifier HINSTANCE hInstance, // handle to application instance LPVOID lpParam // window-creation data );

15.2.2 Child Windows

Following are the characteristics of child windows.

  • A child window always appears within the client area of its parent window.
  • Child windows are most often as controls.
  • A child window sends WM_COMMAND notification messages to its parent window.
  • When a child window is created a unique identifier for that window is specified in hMenu parameter of CreateWindow()

15.2.3 Window Procedure

LRESULT CALLBACK WindowProc ( HWND hwnd, // handle to window UINT uMsg, // WM_COMMAND WPARAM wParam, // notification code and identifier LPARAM lParam // handle to control (HWND) );

15.2.4 Notification code

Common controls are normally taken as child windows that send notification messages to the parent window when events, such as input from the user, occur in the control. The application relies on these notification messages to determine what action the user wants it to take. Except for trackbars, which use the WM_HSCROLL and WM_VSCROLL messages to notify their parent of changes, common controls send notification messages as WM_NOTIFY messages.

15.2.5 WM_COMMAND Notification code

  • The wParam parameter of Window Procedure contains the notification code and control identifier.
  • low word: ID of the control n high word: notification code
  • BUTTON BN_CLICKED
  • EDIT EN_CHANGE etc

15.3 Example Application

For demonstration purpose we are going to create an example application.

15.3.1 Description

Our application will be parent-child window application. This application will consist of three push buttons of names:

  • RECTANGLE
  • CIRCLE
  • MESSAGE”

15.3.4 Window classes

The Window classes used in this application are:

  • mainWindowClass
  • popupWindowClass
  • System Window Classes

15.3.4.1 Main Window class

wc.lpfnWndProc = mainWindowProc; wc.hInstance = hAppInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_UPARROW); wc.hbrBackground= (HBRUSH)GetStockObject (GRAY_BRUSH); wc.lpszClassName= "MainWindowClass";

if(!RegisterClass(&wc)) { return 0; }

15.3.4.2 Popup Window class

wc .lpfnWndProc = popupWindowProc; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hCursor = LoadCursor(NULL, IDC_HELP); wc.lpszClassName = "PopupWindowClass";

if(!RegisterClass(&wc)) { return 0; }

15.3.4.3 System Window classes

System window classes are pre-registered. They do not need to register in our application. In this application, we will only used to create them not to register them.

15.3.5 Creating Main Windows

Create a Main Window of the Application.

hWndMain = CreateWindow("MainWindowClass", "Virtual University",

WS_OVERLAPPEDWINDOW | WS_VISIBLE,

NULL, NULL, hInstance, NULL );

// check the returned handle, don’t need to proceed if the returned handle is NULL if(!hWnd) { MessageBox(NULL,”Cannot Create Main Window”,”Error”, MB_ICONHAND|MB_OK); return 0; }

Now create a popup window with caption and visible style bit on.

hWndPopup = CreateWindow("PopupWindowClass", //window name (optional) "Popup Window", //class name WS_POPUP | WS_CAPTION | WS_VISIBLE, 250, 250, 300, 250, hWndMain, NULL, hInstance, NULL );

15.3.6 Creating Child Windows

Create a button window bearing a text “Rectangle”.

hWndButton=CreateWindow("BUTTON", "Rectangle", WS_CHILD | WS_VISIBLE, 10, 10, 100, 50, hWndMain, 5, hInstance, NULL );

Create an Edit Window bearing a text “Message”

CreateWindow("EDIT", "Message", WS_CHILD | WS_VISIBLE n | ES_LOWERCASE, 10, 190, 200, 25, hWndMain, 8, hInstance, NULL );

here we check the button if button rectangle is pressed then draw a rectangle with Light Gray stock brush.

case WM_DRAW_FIGURE:

hDC = GetDC(hWndPopup); switch(wParam) { case RECTANGLE: SelectObject(hDC,GetStockObject( LTGRAY_BRUSH)); Rectangle(hDC, 50, 10, 230, 150); break; }

15.3.8.2 Drawing in Popup Window- II

In case of Circle, we create hatch brush, we created a hatch brush which has a style of diagonal cross lines. After creating a hatch brush we select it on device context to draw a figure. After drawing, brush must be deleted.

case CIRCLE:

hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(170, 150, 180)); SelectObject(hDC, hBrush); Ellipse(hDC, 70, 10, 210, 150); DeleteObject(hBrush); break;

15.3.8.3 Drawing in Popup Window- III

By pressing the button a text must be display with the stock object Ansi variable fonts and background brush. Text are displayed using TextOut GDI function.

case TEXT_MESSAGE: { TextOut(hDC, 50, 100, "Virtual University", 18); SelectObject(hDC, GetStockObject( ANSI_VAR_FONT)); SetBkColor(hDC, RGB(10, 255, 20)); TextOut(hDC, 50, 115, "knowledge Beyond Boundaries", 27); break; }

ReleaseDC(hWndPopup, hDC);

15.3.9 Informing back to Main Window

case WM_DRAW_FIGURE:

hDC = GetDC(hWndPopup); hwndEdit = GetDlgItem(GetParent(hWnd), 8);

switch(wParam) { case RECTANGLE: SelectObject(hDC,GetStockObject(LTGRAY_BRUSH)); Rectangle(hDC, 50, 10, 230, 150); SendMessage(hwndEdit, WM_SETTEXT, 0, "Rectangle DrAwN!"); break; }

15.3.10 Quit Application via control in Popup window

Main window is destroyed through button’s notification message BN_CLICKED. Main Window can be destroyed using DestroyWindow Function.

WM_CREATE: CreateWindow("BUTTON", "Quit Application", WS_CHILD | WS_VISIBLE, n 75, 155, 150, 40, hWnd, 1234, hAppInstance, NULL); break;

case WM_COMMAND: wControlID = LOWORD(wParam); wNotificationCode = HIWORD(wParam); if(wNotificationCode == BN_CLICKED) { switch(wControlID) { case 1234: DestroyWindow(GetParent(hWnd)); break; }

}