






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 10
This page cannot be seen from the preview
Don't miss anything!







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 );
Following are the characteristics of child windows.
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”.
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.
The Window classes used in this application are:
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; }
wc .lpfnWndProc = popupWindowProc; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hCursor = LoadCursor(NULL, IDC_HELP); wc.lpszClassName = "PopupWindowClass";
if(!RegisterClass(&wc)) { return 0; }
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.
Create a Main Window of the Application.
hWndMain = CreateWindow("MainWindowClass", "Virtual University",
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
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; }
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; }
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;
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);
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.