The joke is a pun. To do something 'vainly' is to do it with an excessively high opinion of one's appearance, abilities, or worth.  A 'weather vane' is a device typically on roofs of buildings that turns to show the direction of the wind.
' ' I can tell which way the wind blows , ' ' said Tom vainly .