Technology trees don't work that way...
anyhow, as others have pointed out, where you have guns you will have handguns. They are actually easier to make than the big kind. That doesn't necessarily mean they will come to be widespread, but ultimately, it is likely that they will because they work very well, and not just against knights. So in the end, if you want to remove handguns, you will have to remove guns.
As to what can replace them. I don't think there is any known technology that matches their performance, otherwise we'd be using that.
- Bows are powerful, strong versions can exceed the hitting power of modern handguns. They are also accurate, a properly made bow made to medieval specifications can, again, beat modern shortarms in that respect (not all, but some standard issue ones). They certainly outclassed most muzzleloading guns in history in terms of both accuracy and rate of fire. But they are big and difficult to use. Most people don't have the time to become competent archers.
- crossbows are powerful, they can easily beat firearms in that respect, and they are easy to use. Thewy can also be extremely accurate. Problem is, they're bulky, and unlike with firearms, you have a direct tradeoff between power and rate of fire with which there is no sweet spot. Powerful crossbows will be very slow to use, and fast ones will be both weak and inaccurate, more so than bows. There were pistol-sized crossbows powerful enough to kill with a single shot, but they were demanding pieces of craftsmanship far more delicate than a gun, and still slow.
- rockets give you significantly less accuracy and hitting power for the equivalent weight of ammunition, and are risky because of backwash. They also don't accelerate as quickly and you need a fairly large one to match the power of even a medium-sized gun or crossbow.
- pressurised-air weaponry is powerful, fast, and accurate, but it is a very demanding technology. In order to reach even the average performance of a gun made with similar materials and tools, you have to push the tech envelope to the point of foolhardiness. Repressurising also takes time, care and attention to detail, not to mention complex and finicky tools. Steam-powered weaponry is similar.
- torsion, coiled-spring or rubber-band powered weapons can't safely pack the required punch unless they are too large to comfortably carry.
A world where guns were either unknown or uncommon would use a combination of these in the roles the modern West used guns for, but you would either neede a good social explanation or the moment they are invented, guns will take over. Have a world in which civilian identity contains a strong pacifist streak and military men are highly trained professionals and you might get there. Assassins, bodyguards and criminals can get their hands on high-end miniaturised crossbows or the rare custom-made gun while soldiers will prefer bows. but that's nothing like medieval Europe, so there's a bit of a problem there.