You could tap into the title
key-value and construct the listing caption the way you want to using the following approach:

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{listings}% http://ctan.org/pkg/listings
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{filecontents*}{foo_bar.c}
void main{}
\end{filecontents*}
\begin{document}
\newcommand{\mylisting}[2][]{%
\refstepcounter{lstlisting}%
\lstinputlisting[language=C,
breaklines=true,
basicstyle=\scriptsize\ttfamily,
numbers=none,
title={\colorbox{black!10}{\parbox{\dimexpr\linewidth-6pt\relax}{\centering \lstlistingname~\thelstlisting:\ \texttt{\detokenize{#2}}}}},
frame=none,#1]%
{#2}%
}%
\lipsum[1]
\noindent\mylisting{foo_bar.c}
\lipsum[2]
\noindent\mylisting{foo_bar.c}
\lipsum[3]
\noindent\mylisting{foo_bar.c}
\lipsum[4]
\end{document}
However, this will require you to manage the "List of Listings" (\lstlistoflistings
) by yourself, since no caption
is used. Not sure whether you require this though...
\documentclass
and the appropriate packages so that those trying to help don't have to recreate it.filecontents
package.