How can I get Windows 7 to switch audio from a monitor (with built-in speakers) to headphones when they are plugged in?

If it is possible at all, then you might look into the sound settings. It's not in the standard windows settings but in those of the sound chip.

I usually have external speakers connected (via green speakers jack at the back of my PC). When I plugin headphones into the front headphone jack, the rear speakers are automatically shut off. This behavior can be configured within the sound settings.

My current PC behaves like this, and my two laptops before did, too. However, I am only using those headphone jacks, not HDMI. I don't know, if the sound driver would support this, too.