One might wonder why they would need to strike someone with a handgun rather than just shoot with it. The fact remains that many fights start at contact distance, or end up at contact distance. If at contact distance before your gun comes out you should rely on combative skills to get yourself into a position that facilitates getting the gun into play, if needed. If your gun is already in hand and you end up entangled with an adversary, having the hand skills to deal with that becomes necessary.
Why would we strike with the gun rather than shoot? What if there are innocents behind the adversary and gunfire would pose a risk to them? What if the gun has just run dry or malfunctioned right as we get tied up with the opponent? There are feasible reasons we might need to do this. Whatever the case, knowing how to strike with the gun is a skill to have.
When it comes to actually hitting an opponent with the gun itself, consider what you would target. Obviously, head shots will be the most effective; in particular, the ocular cavity, the temple, and the jaw line. Hitting these targets with an aggressive strike while holding a metal block in your hand can impart significant impact and gain the desired effect.
Now, concerning what part of the gun to hit with, there are quite a few techniques, but some of them are not very practical as applied to using a modern, polymer framed gun. For example, hitting someone over the head with the butt of the gun worked good when people carried all-steel revolvers, or 1911s, but do that with your Glock and the base pad might sheer off the magazine and dump your rounds to the ground. Also, I am not a fan of hitting with the bottom of the frame with a polymer gun; while this strike is unlikely to hurt the gun, with such a light weapon the strike simply does not transfer as much power as other options.
The two weapon strikes I favor are the in-line strike, hitting the ocular cavity with the muzzle of the gun, and the roundhouse strike which hits the opponent on the jaw line or temple with the top of the slide. Each of these strikes imparts considerable force and both are safe for the gun. The muzzle strike may very well take the gun out of battery, but doing a malfunction clearance tap-rack after hitting somebody with the gun should be the immediate response anyway.
To strike with the muzzle simply punch with the gun in your hand directly to the ocular cavity. This straight shot will be devastating if it lands. Be sure to retract the gun back to a guarded position immediately so as not to hand it to the opponent and make a disarm attempt easier. To hit with the top of the slide, strike with a roundhouse motion to the temple or jaw line, striking the target hard with the top edge of the slide.
See the demonstration of each of these strikes: