9 Lecture
CS410
Midterm & Final Term Short Notes
Windows Creation and Message Handling
Windows creation and message handling are fundamental aspects of graphical user interfaces. In Windows OS, programs generate windows to display content and interact with users. Message handling involves processing events (messages) like mouse cl
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
1. What is a window in the context of graphical user interfaces?
a) A type of mouse pointer
b) A borderless frame
c) A region on the screen that displays content and can interact with the user
d) A computer peripheral
Solution: c) A region on the screen that displays content and can interact with the user
2. Which API is commonly used to create windows in Windows OS?
a) JVM
b) OpenGL
c) DirectX
d) WinAPI
Solution: d) WinAPI
3. What is the primary function of the Window Procedure in Windows programming?
a) To create a new window
b) To handle messages and events for a window
c) To manage the position of the window on the screen
d) To close an existing window
Solution: b) To handle messages and events for a window
4. Which message is sent to a window when the user clicks a mouse button?
a) WM_PAINT
b) WM_LBUTTONDOWN
c) WM_CLOSE
d) WM_KEYDOWN
Solution: b) WM_LBUTTONDOWN
5. What is the role of the WM_PAINT message in Windows message handling?
a) It requests the window to be repainted.
b) It closes the window.
c) It resizes the window.
d) It moves the window to a new position.
Solution: a) It requests the window to be repainted.
6. The WM_CLOSE message is generated when:
a) The window is minimized.
b) The window is closed by the user or system.
c) The window is moved.
d) The window is resized.
Solution: b) The window is closed by the user or system.
7. Which message is sent to a window when the user presses a key on the keyboard?
a) WM_MOUSEMOVE
b) WM_KEYUP
c) WM_CHAR
d) WM_SIZE
Solution: c) WM_CHAR
8. Which Windows function is used to create a new window?
a) CreateWindowEx
b) DrawWindow
c) NewWindow
d) OpenWindow
Solution: a) CreateWindowEx
9. What is the purpose of the LPARAM and WPARAM parameters in the Window Procedure?
a) They hold the window's position and size information.
b) They hold the message-specific information and additional data.
c) They are used to set the window's title.
d) They are used to close the window.
Solution: b) They hold the message-specific information and additional data.
10. When handling a message in the Window Procedure, what should be returned after processing the message?
a) The window handle (HWND)
b) The wParam parameter
c) The message itself
d) 0 (zero)
Solution: d) 0 (zero)
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
1. Question: What is a window class in Windows programming, and why is it essential?
Answer: A window class is a blueprint for creating windows with similar attributes and behavior. It defines the window procedure and style. It is essential because it allows multiple windows with similar characteristics to be created efficiently.
2. Question: Explain the process of creating a new window using the WinAPI.
Answer: To create a new window, you need to register a window class, create a window using the registered class, and handle messages in the window procedure. Use functions like `RegisterClassEx` and `CreateWindowEx` to achieve this.
3. Question: What is the purpose of the Window Procedure in message handling?
Answer: The Window Procedure is a callback function that handles messages sent to a window. It processes various events like mouse clicks, keyboard input, and repaint requests to maintain the window's behavior.
4. Question: How does a window process messages in a message queue?
Answer: When a message is sent to a window, it is placed in the window's message queue. The window processes messages one at a time in the order they were received, calling the appropriate Window Procedure for each message.
5. Question: What is the significance of the WPARAM and LPARAM parameters in the Window Procedure?
Answer: The WPARAM and LPARAM parameters carry additional information along with the message. WPARAM holds message-specific data, and LPARAM carries additional data or handles.
6. Question: How does a window handle the WM_PAINT message for updating its content?
Answer: When a window receives the WM_PAINT message, it should use the `BeginPaint` and `EndPaint` functions to start and finish the painting process. The actual painting logic lies within the code between these functions.
7. Question: What are the typical steps involved in handling user input, such as a mouse click, in a window?
Answer: To handle a mouse click, the window should process the WM_LBUTTONDOWN or WM_RBUTTONDOWN messages and extract the mouse position from the LPARAM parameter. Then, the appropriate action can be taken based on the mouse's location.
8. Question: Explain the concept of message propagation in Windows message handling.
Answer: Message propagation refers to how messages are passed from a child window to its parent window and then to the ancestor windows until a suitable Window Procedure processes the message.
9. Question: How can you prevent a window from being closed when the user clicks the close button (X)?
Answer: To prevent the window from being closed, the window procedure should handle the WM_CLOSE message and, instead of closing the window, return zero (0) from the message processing.
10. Question: Why is it essential to clean up resources when destroying a window?
Answer: Cleaning up resources is essential to avoid memory leaks and ensure proper system resource management. When destroying a window, you should release any allocated memory, unregister the window class, and free any other resources associated with the window.