







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








The basic building block for displaying information in the MicrosoftÂŽ Windows⢠graphical environment is the window. Microsoft Windows manages how each window relates to all other windows in terms of visibility, ownership, and parent/child relationship. Windows uses this relationship information when creating, painting, destroying, sizing or displaying a window. A window can have many childrenâs and may or may not have one parent. An example of windows is Notepad, calculator, word pad etc, are all windows.
A window shares the screen with other windows, including those from other applications. Only one window at a time can receive input from the user. The user can use the mouse, keyboard, or other input device to interact with this window and the application that owns it.
A thread is basically a path of execution through a program. It is also the smallest unit of execution that Win32 schedules. A thread consists of a stack, the state of the CPU registers, and an entry in the execution list of the system scheduler. Each thread shares all of the processâs resources.
A process consists of one or more threads and the code, data, and other resources of a program in memory. Typical program resources are open files, semaphores, and dynamically allocated memory. A program executes when the system scheduler gives one of its threads execution control. The scheduler determines which threads should run and when they should run. Threads of lower priority may have to wait while higher priority threads complete their tasks. On multiprocessor machines, the scheduler can move individual threads to different processors to âbalanceâ the CPU load.
Each thread in a process operates independently. Unless you make them visible to each other, the threads execute individually and are unaware of the other threads in a process. Threads sharing common resources, however, must coordinate their work by using semaphores or another method of inter process communication.
So a thread is a process that is part of a larger process or application. A thread can execute any part of an application's code, including code that is currently being executed by another thread. All threads share the
9 Virtual Address space 9 Global variables 9 Operating system resources of their respective processes.
Threads are two types of threads.
In Windows, a thread that handles user input and responds to user events independently is User-Interface Thread. User-interface thread own one or more windows and have its own message queue. User-interface threads process messages, received from the system.
A worker thread is commonly used to handle background tasks. Tasks such as calculation and background printing are good examples of worker threads.
In a graphical MicrosoftÂŽ WindowsÂŽ-based application, a window is a rectangular area of the screen where the application displays output and receives input from the user. Therefore, one of the first tasks of a graphical Windows-based application is to create a window.
A window shares the screen with other windows, including those from other applications. Only one window at a time can receive input from the user. The user can use the mouse, keyboard, or other input device to interact with this window and the application that owns it.
A Window may further contain more windows inside it. For example lets take a calculator, A calculator contains more windows in forms of buttons, radio buttons and check boxes.
When you start the system, it automatically creates the desktop window. The desktop window is a system-defined window that paints the background of the screen and serves as the base for all windows displayed by all applications.
The desktop window uses a bitmap to paint the background of the screen. The pattern created by the bitmap is called the desktop wallpaper. By default, the desktop window uses the bitmap from a .bmp file specified in the registry as the desktop wallpaper.
The GetDesktopWindow function returns a handle to the desktop window.
A system configuration application, such as a Control Panel item, changes the desktop wallpaper by using the SystemParametersInfo function with the wAction parameter set to
The client area is the part of a window where the application displays output, such as text or graphics. For example, a desktop publishing application displays the current page of a document in the client area. The application must provide a function, called a window procedure, to process input to the window and display output in the client area. For more information, see Window Procedures.
The title bar, menu bar, window menu, minimize and maximize buttons, sizing border, and scroll bars are referred to collectively as the window's nonclient area. The system manages most aspects of the nonclient area; the application manages the appearance and behavior of its client area.
The title bar displays an application-defined icon and line of text; typically, the text specifies the name of the application or indicates the purpose of the window. An application specifies the icon and text when creating the window. The title bar also makes it possible for the user to move the window by using a mouse or other pointing device.
Most applications include a menu bar that lists the commands supported by the application. Items in the menu bar represent the main categories of commands. Clicking an item on the menu bar typically opens a pop-up menu whose items correspond to the tasks within a given category. By clicking a command, the user directs the application to carry out a task.
The window menu is created and managed by the system. It contains a standard set of menu items that, when chosen by the user, set a windowâs size or position, closes the application, or performs tasks.
The buttons in the upper-right corner affect the size and position of the window. When you click the maximize button , the system enlarges the window to the size of the screen and positions the window, so it covers the entire desktop, minus the taskbar. At the same time, the system replaces the maximize button with the restore button. When you click the restore button , the system restores the window to its previous size and position. When you click the minimize button , the system reduces the window to the size of its taskbar button, positions the window over the taskbar button, and displays the taskbar button in its normal state. To restore the application to its previous size and position, click its taskbar button. By clicking the close button , application exits.
The sizing border is an area around the perimeter of the window that enables the user to size the window by using a mouse or other pointing device.
The horizontal scroll bar and vertical scroll bar convert mouse or keyboard input into values that an application uses to shift the contents of the client area either horizontally or vertically. For example, a word-processing application that displays a lengthy document
typically provides a vertical scroll bar to enable the user to page up and down through the document.
An application must provide the following information when creating a window. (With the exception of the Window Handle, which the creation function returns to uniquely identify the new window.)
These window attributes are described in the following sections.
Every window belongs to a window class. An application must register a window class before creating any windows of that class. The window class defines most aspects of a window's appearance and behavior. The chief component of a window class is the window procedure , a function that receives and processes all input and requests sent to the window. The system provides the input and requests in the form of messages. For more information, see Window Classes, Window Procedures , and Messages and Message Queues.
A window name is a text string that identifies a window for the user. A main window, dialog box, or message box typically displays its window name in its title bar, if present. A control may display its window name, depending on the control's class. For example, buttons, edit controls, and static controls displays their window names within the rectangle occupied by the control. However, list boxes, combo boxes, and static controls do not display their window names.
To change the window name after creating a window, use the SetWindowText function. This function uses the GetWindowTextLength and GetWindowText functions to retrieve the current window-name string from the window.
pixels to the right of the upper left corner of the screen and 10 pixels down from it. A child window having the coordinates (10,10) is placed 10 pixels to the right of the upper left corner of its parent window's client area and 10 pixels down from it.
The WindowFromPoint function retrieves a handle to the window occupying a particular point on the screen. Similarly, the ChildWindowFromPoint and ChildWindowFromPointEx functions retrieve a handle to the child window occupying a particular point in the parent window's client area. Although ChildWindowFromPointEx can ignore invisible, disabled, and transparent child windows, ChildWindowFromPoint cannot.
A window's size (width and height) is given in pixels. A window can have zero width or height. If an application sets a window's width and height to zero, the system sets the size to the default minimum window size. To discover the default minimum window size, an application uses the GetSystemMetrics function with the SM_CXMIN and SM_CYMIN flags.
An application may need to create a window with a client area of a particular size. The AdjustWindowRect and AdjustWindowRectEx functions calculate the required size of a window based on the desired size of the client area. The application can pass the resulting size values to the CreateWindowEx function.
An application can size a window so that it is extremely large; however, it should not size a window so that it is larger than the screen. Before setting a window's size, the application should check the width and height of the screen by using GetSystemMetrics with the SM_CXSCREEN and SM_CYSCREEN flags.
A window can have a parent window. A window that has a parent is called a child window. The parent window provides the coordinate system used for positioning a child window. Having a parent window affects aspects of a window's appearance; for example, a child window is clipped so that no part of the child window can appear outside the borders of its parent window. A window that has no parent, or whose parent is the desktop window, is called a top-level window. An application uses the EnumWindows function to obtain a handle to each of its top-level windows. EnumWindows passes the handle to each top-level window, in turn, to an application-defined callback function, EnumWindowsProc.
A window can own, or be owned by, another window. An owned window always appears in front of its owner window, is hidden when its owner window is minimized, and is destroyed when its owner window is destroyed. For more information, see Owned Windows.
A child window can have a child-window identifier, a unique, application-defined value associated with the child window. Child-window identifiers are especially useful in applications that create multiple child windows. When creating a child window, an application specifies the identifier of the child window. After creating the window, the application can change the window's identifier by using the SetWindowLong function, or it can retrieve the identifier by using the GetWindowLong function.
Every window, except a child window, can have a menu. An application can include a menu by providing a menu handle either when registering the window's class or when creating the window.
Every application has an instance handle associated with it. The system provides the instance handle to an application when the application starts. Because it can run multiple copies of the same application, the system uses instance handles internally to distinguish one instance of an application from another. The application must specify the instance handle in many different windows, including those that create windows.
Every window can have application-defined creation data associated with it. When the window is first created, the system passes a pointer to the data on to the window procedure of the window being created. The window procedure uses the data to initialize application-defined variables.
After creating a window, the creation function returns a window handle that uniquely identifies the window. A window handle has the HWND data type; an application must use this type when declaring a variable that holds a window handle. An application uses this handle in other functions to direct their actions to the window.
An application can use the FindWindow function to discover whether a window with the specified class name or window name exists in the system. If such a window exists, FindWindow returns a handle to the window. To limit the search to the child windows of a particular application, use the FindWindowEx function.
The IsWindow function determines whether a window handle identifies a valid, existing window. There are special constants that can replace a window handle in certain functions. For example, an application can use HWND_BROADCAST in the SendMessage and SendMessageTimeout functions, or HWND_DESKTOP in the MapWindowPoint s function.
inside it or presses the TAB key. After it is selected, the edit control displays its text (if any) and a flashing caret that indicates the insertion point. The user can then enter text, move the insertion point, or select text to be edited by using the keyboard or the mouse. An edit control can send notification messages to its parent window in the form of WM_COMMAND messages.
Example of static control is a text in message box.
A window in a Win32ÂŽ-based application can display a data object, such as a document or a bitmap that is larger than the window's client area. When provided with a scroll bar, the user can scroll a data object in the client area to bring into view the portions of the object that extend beyond the borders of the window. Scroll bar is of two types. Horizontal Scroll bars and Vertical Scroll bar.
The common controls are a set of windows that are implemented by the common control library, which is a dynamic-link library (DLL) included with the MicrosoftÂŽ WindowsÂŽ operating system. Like other control windows, a common control is a child window that an application uses in conjunction with another window to perform I/O tasks.
Common controls are of these types.
The following are the user interface elements used in Windows.
The following are the some of the windows messages
A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
wParam: This parameter specifies the type of system command requested. This parameter can be one of the following values.
SC_MAXIMIZE SC_MINIMIZE SC_CLOSE SC_RESTORE SC_MAXIMIZE
lParam This parameter is the low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used. The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the
In this lecture, we learnt more about windows, its hierarchy and types. We learnt about windows types, these are owned windows and child windows. We must keep this point in mind that owned windows and child windows have different concepts. Owned windows have the handle of their owner windows, these handle make a chain of owned windows. We read about the behavior of owned windows and owner windows. We knew that if we bring some change to owner window then the owned windows will response on some changes like minimize and destroying operations. We also knew about child windows that these are the part of its parentâs client area. After we knew about threads and their types, threads are two types one is User interface thread and second is working thread. UI (User interface) thread is attached with user interfaces like windows, messages and dialog boxes. We gained a little knowledge about controls. And after that we learnt how to make a windows procedure with responses system menu including close, maximize and minimize button.