Your programs are always running in virtual memory all the time. (Windows' terminology in that dialog where you set the pagefile size is grossly misleading.)
What you are asking for is the ability to force a program to be paged out. There is no way to do that directly.
so it eventually becomes really slow by trying to keep pieces of every program on memory and swapping other pieces to virtual memory.
That doesn't happen. Memory pages that are not being accessed are always available to be released for other uses (and written to disk as necessary); the OS doesn't "try to keep pieces of every program" in memory regardless of whether they're being accessed. If they're not being accessed, which is normally the case for private pages of an idle program, they will only stay in memory until there's pressure caused by other programs' needs. (Until then there's no point in paging them out, right?)
Through Windows XP, minimizing an app's Windows would force a working set purge, but I think XP was the last where this was true.
If you really want to do this, though, you can use the VMmap
tool from SysInternals. When it starts up it will ask you to select a process. Do that, then select View | Empty Working Set.
Note however that this only releases pages to the modified or standby page list. (And that only for pages that aren't in the working sets of any other processes.) Pages dropped to the modified list will be written to the pagefile and then moved to the standby list. Pages on the standby list are considered "available" but until they are repurposed for some other use they will still contain the contents from the original process.
The net result is exactly the same as what Windows will do if there is pressure for available memory - you're just doing it sooner, before such demands actually exist.
Full details are of course in the Memory Management chapter of Windows Internals by Solomon, Russinovich, and Ionescu.