You should be able to swap them though they may be a few things you should be aware of.
1) the compaq's bios will accept the larger drive. In 99.9% of cases there will be no problem.
2)It will be very unlikley that the compaq will boot up from the emachines hard drive. Although it will have the operating system on the hard drive, all the changes may make windows throw a woobley.
3) If you do manage to get windows running. If you ever need to reinstall the operating system from the recovery disk, it won't work. You will be trying to restore a compaq system from an emachines disk or vice versa.
What may be the easiest and best way would be to go to the larger hard drives web site and download there software. You might then be able to clone the system from the small hard drive over to the larger hard drive.
if you are interested in doing that, post back with details of both hard drives. You will be able to identify them through control panel - system -device manager-disk drives