The Windows Operating System and applications are event-driven. Describe how a W
ID: 3876537 • Letter: T
Question
The Windows Operating System and applications are event-driven. Describe how a Windows application is decoding event messages in its main message procedure WndProc. How does the application decode a WM COMMAND message to call the DialogBox? Refer to the source code example below. Discuss how such an approach is beneficial for interactive applications. LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM 1Param) int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) case WM_COMMAND: wm1d LOWORD(wParam); wmEvent HIWORD(wParam); // Parse the menu selections switch (wmId) case IDM ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, About); break; case IDM_EXIT: Destroywindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; case WM_PAINT: hdc BeginPaint(hWnd, &ps;); TODO: Add any drawing code here... EndPaint(hwnd, &ps;); break; case WM_DESTROY PostQuitMessage(); break; default: return DefWindowProc(hwnd, message, wParam, 1Param) return 0;Explanation / Answer
Solution:
Windows Operating System and Applications:
Operating system and most applications that interact with hardware are event driven. Operating systems control the computer and its peripherals to make them available to the programs we want to run.
Event-handler in windows applications works as a GUI to interact with windows applications tools such as text boxes, tool icons menus etc. If any user presses keys from the keyboard or click on the mouse then event-handler trigger the windows-applications tools. Windows OS provide the event-driven program (as given in this question) using these event triggers. The code written for event-driven operating system in such a way that it interact with every event that arise through user interaction.
In a similar method, the code written in event-driven program can generate several events such as- Key down event, Key up event, mouse-click event. Some related issues such as- an open/read/write call are also an event.Operating Systems are written for event-driven feature.
In windows operating system, there are several ways that an OS could be referred to as an event driven application.
For example- the first event-driven is the start button at the bottom of the desktop is activated through a click event. If you click on the start button it generates a list of other functions. Another example is drag-and-drop feature on the desktop or any other place on the computer.
Decoding event messages in its main message procedure WndProc:
According to the code given in above program, WndProc function is an application-defined function which is used to process messages sent to a window. The WndProc type defines a pointer to this callback function. WindowProc is a placeholder for the application-defined function name.
The syntax of WndProc function is given as following:
WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
Here, HWND hwnd type is used to handle to the window, UINT message is for lists of the system-provided messages, WPARAM wParam and LPARAM lParam types are additional message information, and the contents of these parameters depend on the value of the UINT message parameter.
Decode a WM_COMMNAD message to call the DialogBox:
According to the code given in above program, WM_COMMAND is used to send a message when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. It contains wParam and lParam parameters.
If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.
WM_COMMAND contains the following parameters:
wNotifyCode:
It is the value of wParam type parameter. It is used to indicate the notification code if the message is from a control. This parameter is 1 when If the message is from an accelerator. This parameter is 0 when the message is from a menu.
wID:
It is also the value of wParam type parameter. This parameter is used to indicate the identifier of the menu item, control, or accelerator.
hwndCtl:
It is the value of lParam type parameter and Identifies the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
Return Values
If an application processes this message, it should return zero.
WM_PAINT Command:
The WM_PAINT command is used to send message when the system or another application makes a request to paint a portion of an application's window.
WM_DESTROY Command:
The WM_DESTROY command is used to send message when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
According to this command the message is sent first to the window being destroyed and after that to the child windows as they are destroyed. It can be implicit that all child windows still exist during the processing of the message.
A window receives WM_DESTROY message by its WindowProc function.
DefWindowProc Method:
This function is used to calls the default window procedure to provide default processing for any window messages that an application does not process. This function makes sure that every message is processed. DefWindowProc is called with the same parameters received by the window procedure.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.