Windows delivers the address in memory represented by HINSTANCE(tell the winmain where should execute), szCmdline (what the cmdline )and iCmdShow (how to show the window) to WinMain function then WinMain(main thread) executes your code.Register a window class ,create a window using it and involve the message loop and so forth.
Later,Windows call window procedure associated with the main thread by passing MSG structure,that is to say Windows sends message to the window ,then your code is executed again by system(not by itself).
Many messages is handled by the DefWindowProc ,that is to say ,You let Windows does it not you.You task is only take care what you want ,such as WM_KDOWN message,WM_CHAR message ,and let your own code to repond the message ,this is Windows programing.haha!!!!
Do what you like in window procedure!!!