Windows Management: Creating and Managing Windows and Child Windows, Study notes of Computer Engineering and Programming

This chapter provides an in-depth look at windows management functions, focusing on creating and managing windows and child windows. Topics include the z-order, createwindow function, child windows characteristics, window procedure, notification codes, and user-defined messages. The chapter also covers creating main windows, creating child windows, and handling user interactions.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 15
15.1 Z-ORDER 2
15.2 WINDOWS REVIEW 2
15.2.1 CREATEWINDOW 2
15.2.2 CHILD WINDOWS 2
15.2.3 WINDOW PROCEDURE 3
15.2.4 NOTIFICATION CODE 3
15.2.5 WM_COMMAND NOTIFICATION CODE 3
15.3 EXAMPLE APPLICATION 3
15.3.1 DESCRIPTION 3
15.3.2 OBJECTIVES 4
15.3.3 WINDOWS MANAGEMENT FUNCTIONS 4
15.3.4 WINDOW CLASSES 5
15.3.4.1 Main Window class 5
15.3.4.2 Popup Window class 5
15.3.4.3 System Window classes 5
15.3.5 CREATING MAIN WINDOWS 5
15.3.6 CREATING CHILD WINDOWS 6
15.3.7 USER DEFINED MESSAGES 7
15.3.8 APPLICATIONS MAIN WINDOW PROCEDURE 7
15.3.8.1 Drawing in Popup Window- I 7
15.3.8.2 Drawing in Popup Window- II 8
15.3.8.3 Drawing in Popup Window- III 8
15.3.9 INFORMING BACK TO MAIN WINDOW 9
15.3.10 QUIT APPLICATION VIA CONTROL IN POPUP WINDOW 9
SUMMARY 10
EXERCISES 10
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Windows Management: Creating and Managing Windows and Child Windows and more Study notes Computer Engineering and Programming in PDF only on Docsity!

  • Chapter
  • 15.1 Z-ORDER
  • 15.2 WINDOWS R EVIEW
  • 15.2.1 CREATE W INDOW
  • 15.2.2 CHILD W INDOWS
  • 15.2.3 W INDOW P ROCEDURE
  • 15.2.4 NOTIFICATION CODE
  • 15.2.5 WM_COMMAND NOTIFICATION CODE
  • 15.3 EXAMPLE APPLICATION
  • 15.3.1 DESCRIPTION
  • 15.3.2 OBJECTIVES
  • 15.3.3 W INDOWS M ANAGEMENT F UNCTIONS
  • 15.3.4 W INDOW CLASSES
  • 15.3.4.1 Main Window class
  • 15.3.4.2 Popup Window class
  • 15.3.4.3 System Window classes
  • 15.3.5 CREATING M AIN W INDOWS
  • 15.3.6 CREATING CHILD W INDOWS
  • 15.3.7 USER DEFINED M ESSAGES
  • 15.3.8 APPLICATION ’ S M AIN W INDOW P ROCEDURE
  • 15.3.8.1 Drawing in Popup Window- I
  • 15.3.8.2 Drawing in Popup Window- II
  • 15.3.8.3 Drawing in Popup Window- III
  • 15.3.9 I NFORMING BACK TO M AIN W INDOW
  • 15.3.10 QUIT APPLICATION VIA CONTROL IN P OPUP WINDOW
  • SUMMARY
  • EXERCISES

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.

And Edit child window or edit control in its client area. Floating popup window with caption bar and one push button bearing a name”QUIT APPLICATION”.

15.3.2 Objectives

  • Parent-child communication
  • Message Routing
  • Use of GDI function calls

15.3.3 Windows Management Functions

Building our application, we will use following windows management functions in our application.

Windows management function - I

HWND GetParent ( HWND hWnd // handle to child window );

GetParent function returns the parent handle of the specified child. This function will be useful when the parent of the child window to use.

Windows management function - II

HWND GetDlgItem ( HWND hDlg, // handle to dialog box int nIDDlgItem // control identifier );

GetDlgItem function returns the handle of a dialog item. Using this function we can easily get the handle of the edit control, displayed on dialog box.

HWND FindWindow ( LPCTSTR lpClassName, // class name LPCTSTR lpWindowName // window name );

FindWindow function finds the window with the given class name or window name.

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",

15.3.7 User defined Messages

System defined messages are already defined in WINUSER.H

#define WM_LBUTTONDOWN 0x0201 (513) #define WM_DESTROY 0x0002 (2) #define WM_QUIT 0x0012 (18) #define WM_USER 0x0400 (1024) These message are already defined, user don’t need to define them again.

Here, we will define our own messages.

#define WM_DRAW_FIGURE WM_USER+ //user defined message are in valid range, in our case it is WM_USER + 786

15.3.8 Application’s Main Window Procedure

Message send to main window will be received and processed in mainWndProc function. In windows procedure we will process WM_COMMAND message. In WM_COMMAND message we check the LOWORD and HIWORD parameters of the messages. In LOWORD we have the control ID, always and in HIWORD we have notification code. Using control id we identify a window.

case WM_COMMAND: wControlID = LOWORD(wParam); wNotificationCode = HIWORD(wParam); if(wNotificationCode == BN_CLICKED) { switch(wControlID) { case 5: SendMessage(hWndPopup, WM_DRAW_FIGURE, RECTANGLE, 0); break; case 6: SendMessage(hWndPopup, WM_DRAW_FIGURE, CIRCLE, 0); break; case 7: SendMessage(hWndPopup, WM_DRAW_FIGURE, TEXT_MESSAGE, 0); break; }

15.3.8.1 Drawing in Popup Window- I

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

Summary

This chapter uses Windows management functions whose details have been discussed in our previous lectures. These functions are very helpful to interact with windows and hierarchy of windows and also with windows handling, windows manipulation and windows management. Our main objective in this application was to create a full fledge application. Before continue, we overviewed all the functions that we had to use. Function includes GetParent, GetDlgItem, CreateWindow and notification codes that are sent to window by controls or other child windows. Controls are normally considered are child windows, because these can be placed in any windows and become the part of the window but controls can be main window. Notification messages are considered to transfer informations to parent window by child windows. Child windows can send notification message to parent windows which aim only to inform about some events to parent window. The notification events could be e.g. in case of edit control is selection change i.e. EN_SELCHANGE or EN_CLICKED in case of button. Finally we wrote a code for our application. This code displays a window and three child windows including button that contains text like rectangle, messages etc. we also make a popup window, popup window is not a child window. Popup windows are very useful when to show message on screen or working in full screen modes in Microsoft Windows Operating systems.

Exercises

  1. Create a full screen popup window and then create another popup window with a caption box, system menu and with no close style.
  2. Create your own status bar and show it in a window at its proper location. This status bar should display current time.