Q2. Three main components of Microsoft Windows
Answer:
- Kernel
- GDI (Graphics Device Interface)
- User
Q3. Function to convert a message into character messages
Answer: Translate Message
Q4. If WS_CAPTION style is passed to Create Window, which style is included automatically?
Answer: WS_BORDER
Q5. WM_PAINT purpose
Answer: Informs the window procedure that the client area must be repainted.
Q6. Define PAINTSTRUCT structure
Answer: Holds information about the client area to paint, including:
- Device context handle
- Whether background is erased
- Rectangle region to update
- Other status flags
Q7. Define a window according to Microsoft
Answer: A window is a graphical interface element in Microsoft Windows, allowing applications to display output and receive input. Introduced in Windows 1.0 in 1983.
Q8. Macro types with example
Answer:
- Object-like macro: Acts like a variable
- Function-like macro: Acts like a function call
Example: #define min(X, Y) ((X)>(Y) ? (X):(Y))
Q9. CreateWindow structure and parameters
Answer: Used to create a window. Parameters include:
- Class name
- Window caption
- Style (e.g., WS_BORDER, WS_CAPTION)
- Position and size
- Parent window handle
- Menu handle
- Instance handle
- Optional parameters
Q10. Virtual-key message
Answer: Identifies which key was pressed (device-independent). TranslateMessage converts it into a character message.
Q11. Typedef
Answer: Creates a synonym for a type (not a new type). Example: typedef int LENGTH;
Q12. Clipboard
Answer: Temporary storage for cut, copy, and paste operations. Managed by user32.dll. Cleared when Windows shuts down.
Q13. Responsibilities of GDI (2 main)
Answer:
- Display text and images on screen
- Send output to printers
Q14. System window classes for user vs system
Answer:
- User process: Button, ScrollBar
- System only: DDEMLEvent, Message, ComboBox
Q15. Selecting specific messages from message queue
Answer: Use GetMessage with message filters.
Q16. Conditions when WM_PAINT is sent
Answer:
- Hidden part of window becomes visible
- Window is resized
- Application scrolls its window
- InvalidateRect or InvalidateRgn is called
Q17. SendMessage function
Answer: Sends a message to a window procedure and waits for it to process immediately. Used for communication between parent and child windows.
Q18. Two types of implicit type casting
Answer:
- Promotion
- Demotion
Q19. Superclassing/Subclassing
Answer: After implementing, always call the window procedure.
Q20. Types of brushes
Answer:
- Logical brush: Defined in code, ideal combination of color/pattern
- Physical brush: Created by device driver based on logical brush
Q21. Variable pointer to constant data
Answer: Pointer can change, but the data it points to is constant. Example:
const char *ptr;
Q22. Multi-dimensional array declaration
Answer: Example: int provinces[50][500][1000];
Q23. Translate GetLastError() into string
Answer: Use GetLastError to retrieve extended error info.
Q24. Adding gradient to tab control
Answer: Use GradientFill in GDI or GDI+ for smooth background gradients.
Q25. Argument to macros
Answer: Macros can take arguments using #define with parentheses. Example:
#define min(X, Y) ((X)>(Y) ? (X):(Y))
Q26. Handling messages in subclassed window
Answer: Three options when message is received:
- Pass message to original procedure
- Modify message and pass it
- Do not pass the message
Q27. Steps to handle message generated by action
Answer: Use message loop, GetMessage, TranslateMessage, and DispatchMessage.
Q28. Program execution check (C++ code incomplete)
Answer: Code will not execute because of syntax errors (wrong void and const usage).
Q29. Multiplication program with macro
Answer: Use #define for multiplication of four integers. Example:
#define mul(a,b) (c=a*b)
Q30. Window components
Answer: Microsoft Windows consists of three components:
- Kernel
- GDI
- User