Oh, grammar can be such fun! It keeps us busy on dark winter nights. ;)
You could see this window issue this way:
The writer is telling us in the story that there is a window (Not all rooms have windows, this one does). This fact is not already known to the listener, reader, or maybe even to the speaker or writer. So he informs us that there is a window.
When the presence of a window is known to the listener, reader, etc. then we use the definite article. We no longer talk about a window, because we already know there is one. So it is the window.
When you are looking out of the window, it is already clear that there is a window in the room to look out from. So now that becomes the window. When you look outside, what do you see? Something we didn't know of before: a green car.
I hope this helps a little.