How can I structure this sentence correctly?
Solution 1:
To rephrase without losing any of the meaning and disregarding the pragmatics of the questioner’s sentiment, I might say:
Of all the times that hearing news of a pregnancy has made me happy, yours ranks second.
But I think this formulation casts more light on the awkwardness of the sentiment than the questioner would have wanted.
I agree with the other answerers that although your intentions are kind, this is going to be an uncomfortable thing to hear, no matter how unawkwardly you phrase it.
Solution 2:
Some people refer to the couple as being pregnant and not just the woman. If you find that usage acceptable, you could have said "I've never been happier to hear that another couple is pregnant".
Or you could have said "Except for my wife's pregnancy, I've never been happier to hear that someone is pregnant!"
I think if you try to say "second-most" or not mention your wife you are always going to have a sentence that sounds too stilted or make the compliment sound back-handed.
Solution 3:
Of course you were happier at the birth of your own child, but that goes without saying.
In other words almost everyone prefers an inaccurate pleasantry to something accurate but less effusive.
It would be lovely to hear "I've never been happier..." from a friend, accurate or not.
Years ago my mother used to say to me, she'd say, "In this world, Elwood, you must be" -- she always called me Elwood -- "In this world, Elwood, you must be oh so smart or oh so pleasant." Well, for years I was smart. I recommend pleasant. You may quote me.
James Stewart as Elwood P. Dowd,
Elwood P. Dowd's 'Philosophy' of Life