Why are windows not attached directly to the studs of a house?

When installing windows, it is important to remember that houses move over time. Whether from foundation settling, or swaying in the wind, houses are not totally stationary. As a consequence, if you were to attach a new window rigidly to wooden framing, the glass in the window, which is rigid and brittle, might experience cracking or warping. Additionally, the components of the window, such as the seals and hardware that allows the window to open and close, might break down. Window installers will use a combination of shims and flexible sealing materials such as caulk, along with proper flashing, vapor barriers, and siding to make sure windows are water and air tight, and will operate properly for many years into the future.