Mesostructured films deposited on glass substrates by spin coating are studied by X-ray diffraction, small angle X-ray scattering using grazing incidence (GISAXS) and high resolution electron microscopy. The films generally present a gradient of ordering from the air/sol interface to the interior of the film, with a 3D-hexagonal mesophase near the surface and a disordered micellar structure at the interior. However, the 3D-hexagonal ordering and the texturing can be extended over all the film thickness by adjusting the composition of the deposited solution. In particular, critical values are clearly observed both for the size of silica units forming the walls in the mesophase and for the film thickness. All these results can be understood from the competition between structuration and gelation of the films during alcohol removal.