Just prior to getting pregnant with this child, a friend of mine had a miscarriage. Recently, I heard about another who just had one. I'm very sorry for their news and can understand it because it happened to me between kid 1 and 2.
I have another friend, actually two, that are having infertility challenges. Out of respect, I didn't know what to do when I announced my pregnancy. Well, one friend was easy... she wants to know regardless. The other one, I was afraid to say anything, but eventually told her and she was happy I told her.
From my own experience, I don't want people who have good news to avoid sharing it with me because of what happened. Sure, I might get jealous or feel a pang, but this person has the right to be happy and I am happy for her.
One friend was invited to another's baby shower. She had just miscarried and wasn't ready to go to the shower. Her friend was disrespectful saying that she should go, blah blah. Each person heals in her own time. I went to a baby shower within a couple of weeks after it happened to me. Yes, I was sad, but I wanted to be ther for my friend. It's not often that a friend has a baby.