inkcog When I ran support groups, this was a problem attached to the specific issue involved but the rememdy works for most people.
Devise a mantra This can be anything from "I love my children" through to a religious utterance, or the line of a poem or favourite song.
It should be short and something with pleasant connotations.
Device a visual This is not always necesary but it seemed to help a lot of my clients.
Imagine a place where you are most at peace: a garden, on a beach, in a church, sitting in the park. Wherever you would find pleasure. It doesn't need to be an actual place but I found it easier, when I was practising, to keep a real, known-to-me place in my mind.
Having thus equipped yourself, when the dark thought come, middle of the night or anytime, this is what you think of and say, aloud or in your mind, repetitively.
What this does, is teach your brain that as soon as negative thoughts come in, you have a way of pushing them out. The brain learns this (it is the most amazing organ and can be taught and re-taught new pathways) and it click into 'positive' very quickly once you've practiced a few times.