I'm currently trying to give my listings nice captions, so I decided to use something like this :
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
Which gives nice results. However, I would like the gray box not to be displayed when I don't specify a caption for a listing, which is not currently the case. I have a big ugly empty rectangle... Do you have any idea how I could achieve this ?