Q1. How to use CopyTo method of Windows Forms controls collection?
Answer: CopyTo copies all controls from a form into an array. You specify the array and starting position.
Q2. Difference between Pen & Brush
Answer:
- Pen: Used for drawing lines and borders.
- Brush: Used for filling shapes with color or pattern.
Q3. Draw in a window without WM_PAINT
Answer: Use GetDC or GetDCEx to get the device context and draw directly while processing keyboard or mouse messages. Release the device context afterward. Useful for immediate feedback like dragging or resizing.
Q4. How Windows keeps track of files
Answer: Windows assigns instance handles to all running modules, keeping track of each executable and DLL copy.
Q5. Can a class exist without a namespace?
Answer: Yes. It belongs to the global namespace. For commercial applications, it’s better to avoid global namespace.
Q6. Two working spaces in GDI environment
Answer: Logical and Physical.
Q7. Types of macros
Answer:
- Object-like (acts like a variable)
- Function-like (acts like a function call)
Q8. GDI environment working space names
Answer: Logical and Physical.
Q9. Predefined GDI objects
Answer: Pens, Brushes, Fonts, Palettes.
Q10. Macros with example
Answer: Macros are preprocessor commands.
- Object-like: act as data
- Function-like: act as functions
Example: Macro to find max of two numbers.
Q11. What is a process?
Answer: A process is a series of interrelated tasks executed to achieve a specific result.
Q12. Define Modal Loop
Answer: Modal loop is run by modal dialogs to process messages independently from the main application loop.
Q13. Windows programming control process
Answer: Edit Control and Static Control.
Q14. Pointer to constant vs constant pointer
Answer:
- Constant pointer: Address cannot change, data can.
- Pointer to constant: Address can change, data cannot.
Q15. GetParent function
Answer: Returns the handle of a child window’s parent.
Q16. Types of assertions
Answer:
- Preconditions – start of function
- Postconditions – end of function
- Invariants – conditions in a specific program region
Q17. Characteristics of child windows
Answer:
- Appears inside parent’s client area
- Often controls (button, textbox)
- Sends WM_COMMAND to parent
- Has unique ID
Q18. If GetUpdateRect returns zero
Answer: Do not call BeginPaint or EndPaint.
Q19. Client area
Answer: Part of window for displaying output (text, graphics).
Q20. WinMain function
Answer: Entry point for Win32 GUI programs. Parameters: instance handle, previous instance, command line, window style.
Q21. Message queues
Answer: Applications process messages posted to their thread’s queue.
Q22. Paint function usage
Answer: Prepares window for painting, fills PAINTSTRUCT, erases background, returns device context handle.
Q23. Desktop vs Application window
Answer:
- Desktop: System-created, paints background with bitmap.
- Application: User-created, has title bar, menu, icon, may contain child windows.
Q24. _cdecl calling convention
Answer: Caller cleans stack after function call; defines argument order and name decoration.
Q25. If GetUpdateRect returns zero
Answer: Do not call BeginPaint or EndPaint.
Q26. A window can contain other windows
Answer: A parent window can have child windows, e.g., a calculator with buttons and checkboxes.
Q27. Function of ws_paint in Windows class
Answer: Dispatches WM_PAINT messages to window procedure.
Q28. Message queuing
Answer: Each thread (UI or worker) has a message queue; messages are posted or sent via GDI functions.
Q29. Kernel tasks
Answer: Manages processes, memory, files, and system resources.
Q30. Difference between stdcall and cdec
Answer:
- stdcall: Called function cleans stack
- cdecl: Caller cleans stack
Q31. Erase window function
Answer: Uses GetClipBox to get area, fills area using FillRect.
Q32. Clipboard working
Answer: Enables data sharing across applications, e.g., copy text from Notepad, paste in Word.
Q33. GetDC function
Answer: Retrieves device context for drawing; release it using ReleaseDC after use.
Q34. Infinite recursion
Answer: Recursive function that never stops, may cause stack overflow.
Q35. Stack
Answer: Memory area for local variables and function call order.
Q36. Extern storage class
Answer: Declares global variable accessible in multiple modules; cannot initialize here.
Q37. Logical coordinate system setup
Answer: Use logical and physical brushes. Logical brush defined in code; physical brush created by device driver.
Q38. WM_ERASEBKGND not processed
Answer: Default window procedure erases background. Can define custom background brush for class.
Q39. Virtual-key message
Answer: Device-independent code representing key purpose. Keyboard sends message including virtual-key code and scan code.
Q40. Superclassing vs Subclassing
Answer:
- Superclassing: Create new class adding functionality to predefined window class (across process allowed).
- Subclassing: Override existing window procedure (only within process).