You draw AOOs in two ways:
1. Movement: By moving *out* of (leaving) a threatened square, you provoke an AOO
2. Action: Some actions inherently are more risky and "lower your guard". For example, casting a spell, sundering, beginning a grapple, or firing a bow (there are many other examples) in an area that is threatened by an enemy, you provoke an AOO.
Exceptions:
1. If your only movement for the round is a 5 ft step, you do not draw attacks of opportunity due to movement.
2. If all you do during your turn is move, enemies do not get an AOO against you when you leave the square *you started at*. If you leave another threatened square during your turn (besides the one you started at), you still provoke an AOO. (This represents a "fighting withdrawal" where you are carefully backing away from an enemy.)
3. Creatures that have 50% cover or better generally do not provoke AOOs.
4. Some feats can negate AOOs that you would normally provoke or can give you an AOO in a situation where you normally wouldn't be allowed one. For example, Spring Attack denies the defender AOOs against your movement when you use the feat, and Hold the Line gives you an AOO against a charging opponent (where you normally wouldn't get one).
Unless you have the Combat Reflexes feat, you get only one AOO per round.
So, in your example, as Aliensex pointed out, just closing with and attacking an enemy who has a normal (5 ft reach) weapon does not provoke an AOO because you do not leave a threatened square.
If an enemy has a reach weapon like a longspear, he threatens at a distance of 10 ft, so if you move into his range (at 10 ft) and then move another square to close to within normal melee range (at 5 ft), you provoke an AOO because you left the square he threatened 10 ft away.