Windows Programming Notes
1. #include <Windows.h>
#include <Windows.h> se hum Windows OS ke Win32 APIs ko access kar sakte hain, jaise
CreateWindow() aur MessageBox() , jo GUI aur system-level programming ke liye use hote hain.
Professional Version:
“Windows.h include karne se Windows Operating System ke Win32 APIs available ho jaate
hain, jisse hum window creation, message handling aur system services jaise
CreateWindow() aur MessageBox() use kar sakte hain.”
2. WndProc Function
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
• WndProc ek Windows callback function hai jo window ke liye aane wale saare messages ko
handle karta hai.
• Example: WM_DESTROY → window close, WM_PAINT → redraw window.
• Baaki messages → DefWindowProc() ke through default action.
Parameters with Examples
Parameter Type Description Example
Agar multiple windows hain, OS hwnd batata
Unique identifier of
HWND hwnd Handle hai ki kaunsa window message receive kar raha
the window
hai
Message ID
Unsigned iMsg = WM_KEYDOWN → user ne key press
UINT iMsg (WM_PAINT,
int kiya
WM_DESTROY, etc.)
WM_KEYDOWN → wParam = 0x41 (key 'A'
WPARAM Word Message-specific
pressed); WM_LBUTTONDOWN → wParam =
wParam param additional info
MK_LBUTTON (left mouse button)
WM_KEYDOWN → lParam contains repeat
LPARAM Long Detailed message count, scan code; WM_LBUTTONDOWN →
lParam param info lParam contains x, y coordinates of mouse
click
1
Interview Ready Explanation
“WndProc takes hwnd as the window handle, iMsg as the message ID, wParam as extra
info (like key code or mouse button), and lParam as detailed info (like coordinates or flags)
about the message.”
3. WinMain Function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpszCmdLine, int iCmdShow)
{
// Entry point code
}
• WinMain is the entry point for a Windows GUI application.
Parameters with Examples
Parameter Type Description Example / Use
HINSTANCE Pass to CreateWindow() to
Handle Current application instance
hInstance identify resources
Previous instance (always
NULL in Win32, because each
HINSTANCE process has its own virtual
Handle hPrevInstance == NULL
hPrevInstance address space and cannot
detect other running
instances)
User runs: [Link]
LPSTR Long Command line arguments as a [Link] [Link] →
lpszCmdLine Pointer single string lpszCmdLine = "[Link]
[Link]"
SW_SHOW → normal,
SW_MINIMIZE → minimized,
int iCmdShow int Initial window show option
passed to ShowWindow(hwnd,
iCmdShow)
Interview Ready Explanation
“WinMain is the entry point for a Windows GUI application. hInstance is the current app
instance, hPrevInstance is always NULL in Win32 because each process has its own virtual
address space and cannot detect other running instances, lpszCmdLine contains
command line arguments, and iCmdShow tells how the window should be displayed.”