If you want to match the surface materials of door/window elements to those of the wall, the bottom surface of the elements should match the outside, and the top surface the inside of the wall. You can achieve this from your scripts using the WALL_MAT_A, WALL_MAT_B and WALL_MAT_EDGE global variables representing the surface materials of the wall into which the door/window is placed. In the 2D script, the WALL_SECT_PEN, WALL_FILL_PEN and WALL_FILL global variables can be useful, as these give you the pen numbers of the wall contour and fill plus the index number of the fill of the wall on the floor plan into which the door/window is placed. With composite walls, you have to use the corresponding global variables.
WALL_MAT_A should give you the the first layer of a composite wall and the material of a basic one I believe.