Count the shapes in a grid

Given a 3x3 grid of squares, an interesting question arises. That is, how many squares can be found? This requires careful counting, but can be found quite easily. Then a natural question arises. What if there were nxn squares? This will require combinatorics, or at very least, an informal inductive argument. Going a bit further, what about a wxh square grid, where w is width and h is height? What about a wxhxd cuboid grid, with d being depth? How many cuboids would there be? Or even more difficult, how many squares? Does the reasoning extend to hypercuboids?

What if we started with a grid of equilateral triangles instead, maybe arranged in an equilateral triangle, isosceles trapezoid, or regular hexagon of any size?