The Third Man's iconic zither theme was chosen by the film's director Carol Reed because it compliments the dialogue without overpowering it; the tune is exotic yet local and matches the movie's atmosphere because it evokes the mood in post-war Vienna and is elusive, charming and mysterious just like the city and the titular character himself.
I wouldn't say Anton Karas's famous theme is happy; in fact, it's hard to define. Reviews from that time also struggled to define this unique tune - here's one from The New Statesman in 1949:
What sort of music it is, whether jaunty or sad, fierce or provoking, it would be hard to reckon... that little tune or another little tune sprung from the first, goes nipping away, indefinably. [...] At moments the plucked chords will instil a plangent horror.
So how did it come to be in the film? An article about the making of the film describes how the director came across a local man in Vienna who played the zither (a sort of Eastern European string instrument) and fell in love with the evocative theme:
Even though Vienna was the home of the Strauss family, Schubert and Beethoven, Reed was resistant to scoring the film with traditional waltzes. He stumbled upon the solution to his dilemma at a small cafe in Sievering, just outside the city. There, Anton Karas was playing a zither for (and being largely ignored by) the clientele. Impressed by the music, and pleased to observe that it didn't overpower the surrounding conversations, Reed invited Karas to his hotel room to record a sample. He took this recording back to England and played it against the film's dialogue and realized its dramatic potential.
Carol Reed chose well - the theme (as well as the movie) were big hits and are remembered to this day. So what about this tune fits the film so well? I think this article puts it well:
The sounds of Karas’ zither, with its 34 strings and unorthodox “Viennese tuning,” perfectly embody the ruined Austrian capital’s post-war days. The music captures that mixture of old world romance, naked opportunism, and quiet desperation that characterized the then-divided city. Like Vienna, the tune is immediately alluring and attractive, but despite that initial appeal, it hints that something very untoward, very wrong might be happening just out of sight.
And like it embodies the mood in Vienna, so does the tune (frequently called "The Harry Lime Theme") embody Harry Lime himself: an elegant, opportunistic rogue roaming the streets and eluding our grasp.
[P.S. Though it's only peripheral, here's a little tidbit about the actual recording:]
The recording of the "Harry Lime Theme" was overdubbed with additional layers of Karas's zither, giving the music more texture than a single performance could provide. Having experimented with the acoustic feel of Karas's music, Reed best liked the effect when the musician played beneath the director's kitchen table. According to the film's sound recordist, Barbara Hopkins, Reed's
table was brought to the studio to precisely recreate the desired sound.