(as suggested by jabberwocky, I have moved the last part of my answer from here to this question)
People in my program complain a lot and usually not in good humor. How can I handle this socially and professionally?
I have experienced that "dissatisfaction" can also be very infectious. Dissatisfied people often and strongly complain to their co-workers and co-students, which, over time, gives those people the same sense of dissatisfaction. For instance, in my old lab, we had one office room of people that were constantly dissatisfied about our work environment (all the other students in other rooms felt differently). Any new student that would be seated in this office would, within weeks, also start to complain a lot. As such, I think your goal
In general I want to be respectful but not allow them to harangue me with complaints.
is very good. Try not to let other people convince you that life is terrible.
I am not sure whether entirely avoiding social outings is the right strategy, though. This will make you an outsider of your cohort, and you will have to spend a lot of time with these people in the next years. At parties, a usual strategy to avoid any topic that you do not want to talk about (politics, sports, or whether your life is terrible) is to avoid the groups that are currently talking about the annoying topics and focus your attention to people that are discussing something more interesting.
Sometimes, people will come directly to you to complain one-on-one about their problems. In such cases, one strategy is to acknowledge that they are feeling bad, but provide a more positive light on their case. When you do that regularly, two things may happen. In the best case, the complainer actually takes your words to heart and starts seeing things a bit brighter. If that does not happen, he will at least stop complaining to you specifically, because he is actually looking for somebody who echoes his feelings.