Gaining altitude with the Wing Cap can be accomplished several ways.
Your initial height is achieved by launching yourself with a triple-jump or by firing yourself from a cannon; the cannon can naturally get you much higher than a triple-jump can. You may also be able to use whirlwinds in certain stages, but it's been long enough that I can't recall.
Once you're airborne, you can gain addition height by swooping. Push forward on the stick in order to dive, then pull back again once you've built up a little speed. It takes some practice, but once you've gotten used to diving and then smoothly ascending again, you'll find you can gradually increase your altitude. The real trick is gaining enough altitude before the Wing Cap runs out of time.
Practice makes perfect! Good luck!