You probably will lose friends if you go around making big, obnoxious announcements about how you want to be treated. Instead, set an example by how you treat your friends, and by speaking up at the moment -- saying "No, thank you" or "I'm sorry, I don't really like that" when you need to. If you say "No, thank you" several times, then, gently tell the person you don't like what they're doing, that it makes you uncomfortable, and they still don't get it, then you need to sit them down and tell them you will not allow them to do that to you.
For example, if your ex, shows up unannounced, or changes schedules a lot, you can say, gently, "It's important to me that we stick to the schedule," or "Please don't show up when you're not invited." If that doesn't work, then have a talk -- say, "I think you're taking advantage of my time, and I can't be your friend if the situation doesn't improve. So, I'm sorry, but I'm not going to let you in if you just show up without calling first, and I'm not going to let you change my schedule without a good reason."
If that doesn't improve matters, then you'll need to give that person a "time out" -- withdraw from personal contact, and just be very polite when you do happen to see him or her. He or she will get the message loud and clear. Perhaps your ex will ask "Are you mad at me?" and then you can describe what the problem is.
If you feel "used" or taken advantage of -- you haven't set boundaries. If you just decided you had enough and started setting boundaries, it's not necessary to tell your ex about your boundaries in most cases. Just learning to say "No, thank you" or "Please don't do that" is enough.