Compiling DirectX programs with MinGW is possible:
g++ program.cpp -ld3d9
MinGW versions of DirectX include files are bundled with MinGW, so you shouldn't include anything from the DirectX SDK. There are files in the SDK that hasn't been converted to MinGW, notably the D3DX utility library (d3dx9.h and others). You will have to make do without them.
Again, do not link to the libraries installed with DirectX, MinGW comes with a set of DirectX libraries.
// aspect: Aspect ratio, defined as view space height divided by width.
// zn: Z-value of the near view-plane.
// zf: Z-value of the far view-plane.
// h is the view space height.
// w is the view space width.
float aspect = 4.0f / 3.0f;
float fovY = 0.785398f;
float h = cot(fovY/2);
float w = h / aspect;
float zn = 1, zf = 1000;
D3DMATRIX projectionMatrix = {w, 0, 0, 0,
0, h, 0, 0,
0, 0, zf/(zf-zn), 1,
0, 0, -zn*zf/(zf-zn), 0};
d3dDevice->SetTransform(D3DTS_PROJECTION,&projectionMatrix);