X-ray standing waves (XSW) generated by the interference of the scattered x-rays from parallel surfaces of a thin film, the so-called waveguide effect, can be used to enhance the scatterings from certain depths of the film. Used in combination with grazing-incidence small-angle x-ray scattering (GISAXS), this resonance effect provides depth sensitivity to extract buried structures in thin films of polymer and polymer/nanoparticle nanocomposite, which are not readily accessible by most surface techniques, such as scanning probe microscopy. We developed a rigorous theory of the diffuse scattering in the framework of the distorted-wave Born approximation (DWBA) using a discretization method analogous to Parratt's recursive formalism. In such a case, the distortion of the electric field of the unperturbed state from the nanostructures of interest is considered in a selfconsistent manner. This theory allows a quantitative determination of the buried nanostructures when the x-ray waveguide enhancement is present or the size of the nanostructures of interest is comparable to or larger than the spatial frequency of electric field intensity distribution. A unique capability afforded by this theory is that a nanometer or even subnanometer spatial resolution can be achieved in the depth information of the buried nanostructures.