Maybe, depends on a few things.
What you're trying is a "physical-to-virtual" or P2V. It basically involves taking the OS already installed on one PC and try to make it run on different hardware. As you could guess this is somewhat Frankenstien-ish, "take the brain out and try it in a different body" sort of stuff. Unusual things may happen. However it has been done.
First caveat: I don't know if Compaq tied their OS's to the hardware of the PC like Dell does. If they did, this P2V is probably dead in the water. Others may know better. If the original physical PC can be booted still, you might try DMIdecode to get the hardware signatures then try to use the DMI commands in Virtualbox to fake the hardware signatures in the Virtualbox guest. It might work, maybe. If Compaq did not tie to their hardware, then you may be OK.
See
How to migrate existing Windows installations to VirtualBox. You will note that running a utility called MergeIDE is recommended for XP when P2V-ing. If you have the original computer still able to boot than you should be OK to get that utility and run it on the physical PC first.
If you still can boot the old PC you should use this tool to get the virtual copy of the physical drive:
Disk2vhd. Save the VHD on a USB drive larger than the original 40GB disk. Do not use VHDX, that format is not compatible with Virtualbox.
If you cannot start or no longer have the original PC, you will not be able to run MergeIDE on the XP OS. You can attach the physical disk to another working computer using a USB adapter or through the cables inside the other PC. Then you can use Disk2VHD on that other PC to image the XP drive to a VHD. However you will probably have problems booting the VHD because you could not run MergeIDE on it. You may have to use the original XP install CD to do a repair on the guest OS to get it to boot. There may be a way to run MergeIDE after the VHD has been made, try these links:
https://www.andysblog.de/windows-mergei ... h-mergeide
https://www.andysblog.de/windows-mergeide-v3-0
https://www.andysblog.de/windows-eine-r ... -erstellen
(Yes, they're in German; your browser may offer to translate, my Chrome did.)
One other thing, if you're wanting to run programs & games, maybe the programs themselves did not have intense installers that pepper the registry with entires, and you might be able to copy them over to a fresh XP guest. Maybe not.