I'm a bit late here, but if you still have this problem, there might be a solution.
First things first: as Thebluefish said, Source Games, and other games as well, center the cursor to the center of the game every other time unit. How much that is is Engine dependent, and I do not know how often it does that. If you move your mouse quickly enough within one frame, and click before it has time to reset, you click outside the frame of the window, onto the desktop or another window, and that application receives focus.
Games like Starcraft 2 fully capture the mouse within the boundaries of the game, so no matter how fast your mouse moves, you shouldn't be able to move outside of it. That is made worse the smaller your Gaming Window is. In my case however, I usually do not go lower than one resolution step below my native monitor.
Now, one option of course would be to play single-monitor full screen. That way, there is no "outside the window" you can click to.
Option two would be to decrease the sensitivity of your mouse in Windows, and up the mouse sensitivity in your game. Also, if you are still not using it raw input, I would recommend enabling Raw Mouse Input, if that option is available. In TF2 you can do that in your mouse options, or via console with the
m_rawinput command. You can change sensitivity via the console command/variable
sensitivity. If you don't want to change your mouse speed while working in Windows, you can use scripts to change System Mousepointer Speed, and change it back afterwards. Just look for it via Google. What this does is that it decreases the distance the mouse cursor travels for every refresh iteration, which makes it less likely for you to click outside your window.