Windows Programming: Assignment 3
Windows Programming: Assignment 3
Windows Programming: Assignment 3
WINDOWS PROGRAMMING
ASSIGNMENT 3
SUBMITTED TO:
ANS:
DestroyMenu Function
Destroys the specified menu and frees any memory that the menu occupies.
Syntax
Parameters
hMenu
HMENU
Return Value
DeleteMenu Function
Deletes an item from the specified menu. If the menu item opens a menu or
submenu, this function destroys the handle to the menu or submenu and frees the
memory used by the menu or submenu.
Syntax:
Parameters
hMenu [in]
HMENU
uPosition [in]
UINT
ANS:
WM_SYSCOMMAND
This message is sent to a window 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 or the minimize button.
Syntax
Parameters
uCmdType
Specifies the type of system command requested. It is one of the following values.
Value Description
yPos
WM_COMMAND
This message is sent when the user selects a command item from a menu, when a
control sends a message to its parent window, or when an accelerator keystroke is
translated.
Syntax
Parameters
wNotifyCode
wID
Value of the low-order word of wParam. Specifies the identifier of the menu
item, control, or accelerator.
hwndCtl
Handle to the control sending the message if the message is from a control.
Otherwise, this parameter is NULL.
ANS:
A Window's Childhood
After creating the main window, you can use it as a parent for other windows. To
specify that a window is a child of another window, when creating it with either the
CreateWindow() or the CreateWindowEx() function, pass the handle of the parent as
the hWndParent argument. Here is an example:
// Create a window
CreateWindowEx(0, WndClassName, CaptionOrText,
ChildStyle, Left, Top, Width, Height,
hWndParent, NULL, hInstance, NULL);
If a window is a child of another window, to get a handle to its parent, you can call the
GetParent() function. Its syntax is:
The hWnd argument is a handle to the child window whose parent you want to find out.
Alternatively, you can also use the GetWindowLong() function, passing the second
argument as GWL_HWNDPARENT, to get a handle to the parent of a window.
The Borders of a Window
To distinguish a particular window from the other objects on a screen, a window can be
defined by surrounding borders on the left, the top, the right, and the bottom. One of the
effects the user may want to control on a window is its size. For example, the user may
want to narrow, enlarge, shrink, or heighten a window. To do this, a user would
position the mouse on one of the borders, click and drag in the desired direction. This
action is referred to as resizing a window. For the user to be able to change the size of a
window, the window must have a special type of border referred to as a thick frame. To
provide this border, apply or add the WS_THICKFRAME style:
CreateWindow(ClsName, WndName,
WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_THICKFRAME);
Because many windows will need this functionality, a special style can combine them
and it is called WS_OVERLAPPEDWINDOW. Therefore, you can create a resizable
window as follows:
If you cannot make up your mind for these four values, you can use the
CW_USEDEFAULT (when-Creating-the-Window-USE-the-DEFAULT-value) constant
for either one or all four arguments. In such a case, the compiler would select a value
for the argument. Here is an example:
RegisterClassEx(&WndClsEx);
The hWnd argument is a handle to the window that you want to display. It could be the
window returned by the CreateWindow() or the CreateWindowEx() function.
The nCmdShow specifies how the window must be displayed. Its possible values are:
Value Description
SW_SHOW Displays a window and makes it visible
SW_SHOWNORMAL Displays the window in its regular size. In
most circumstances, the operating system
keeps track of the last location and size a
window such as Internet Explorer or My
Computer had the last time it was
displaying. This value allows the OS to
restore it.
SW_SHOWMINIMIZED Opens the window in its minimized state,
representing it as a button on the taskbar
SW_SHOWMAXIMIZED Opens the window in its maximized state
SW_SHOWMINNOACTIVE Opens the window but displays only its
icon. It does not make it active
SW_SHOWNA As previous
SW_SHOWNOACTIVATE Retrieves the window's previous size and
location and displays it accordingly
SW_HIDE Used to hide a window
SW_MINIMIZE Shrinks the window and reduces it to a
button on the taskbar
SW_MAXIMIZE Maximizes the window to occupy the whole
screen area
SW_RESTORE If the window was minimized or maximized,
it would be restored to its previous location
and size
To show its presence on the screen, the window must be painted. This can be done by
calling the UpdateWindow() function. Its syntax is:
This function simply wants to know what window needs to be painted. This window is
specified by its handle. Here is an example:
RegisterClassEx(&WndClsEx);
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
return 0;
PART:B
Q3.Suppose we click on upper left corner of the whole screen, it means we aren’t
restricting on the client area, we are clicking on non-client area’s upper left corner,
elaborate the action taken by windows. Also, elaborate the things necessary for
attaching that function in your window.
The system maintains an update region for the nonclient area. When an application
receives a WM_NCPAINT message, the wParam parameter contains a handle to a
region defining the dimensions of the update region. The application can use the
handle to combine the update region with the clipping region for the window
device context. The system does not automatically combine the update region
when retrieving the window device context unless the application uses GetDCEx
and specifies both the region handle and the DCX_INTERSECTRGN flag. If the
application does not combine the update region, only drawing operations that
would otherwise extend outside the window are clipped. The application is not
responsible for clearing the update region, regardless of whether it uses the region.
The nonclient-area mouse messages parallel almost exactly the client-area mouse
messages. The message identifiers include the letters "NC" to indicate "nonclient."
If the mouse is moved within a nonclient area of a window, the window procedure
receives the message WM_NCMOUSEMOVE. The mouse buttons generate these
messages:
The wParam and lParam parameters for nonclient-area mouse messages are
somewhat different from those for client-area mouse messages. The wParam
parameter indicates the nonclient area where the mouse was moved or clicked. It is
set to one of the identifiers beginning with HT (standing for "hit-test") that are
defined in the WINUSER.H.
The lParam parameter contains an x-coordinate in the low word and a y-coordinate
in the high word. However, these are screen coordinates, not client-area
coordinates as they are for client-area mouse messages. For screen coordinates, the
upper-left corner of the display area has x and y values of 0. Values of x increase as
you move to the right, and values of y increase as you move down the screen. (See
Figure 7-3.)
You can convert screen coordinates to client-area coordinates and vice versa with
these two Windows functions:
where pt is a POINT structure. These two functions convert the values stored in the
structure without preserving the old values. Note that if a screen-coordinate point is
above or to the left of the window's client area, the x or y value of the client-area
coordinate could be negative.
ANS:
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.
This message can be handled without declaring its event at the generating time
are as follows
An application can carry out any system command at any time by passing a
WM_SYSCOMMAND message to DefWindowProc.Any WM_SYSCOMMAND
messages not handled by the application must be passed to DefWindowProc. Any
command values added by an application must be processed by the application and
cannot be passed to DefWindowProc.
The menu items in a window menu can be modified by using the GetSystemMenu,
AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItemInfo
functions. Applications that modify the window menu must process
WM_SYSCOMMAND messages.
If password protection is enabled by policy, the screen saver is started regardless of
what an application does with the SC_SCREENSAVE notification—even if fails
to pass it to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are
translated into WM_SYSCOMMAND messages; all other accelerator keystrokes
are translated into WM_COMMAND messages.
If the wParam is SC_KEYMENU, lParam contains the character code of the key
that is used with the ALT key to display the popup menu. For example, pressing
ALT+F to display the File popup will cause a WM_SYSCOMMAND with
wParam equal to SC_KEYMENU and lParam equal to 'f'.