Super tired, here's some C++ relevant (I hope) code, ignore formatting I'm just pulling part of the code.
Code:
D3DXVECTOR3 pos; D3DXVECTOR3 screen;
D3DVIEWPORT9 viewport;
device->GetViewport(&viewport);
D3DXMATRIX world, projection, view;
device->GetTransform(D3DTS_WORLD, &world);
device->GetTransform(D3DTS_PROJECTION, &projection);
device->GetTransform(D3DTS_VIEW, &view);
D3DXVec3Project(&screen, &pos, &viewport, &projection, &view, &world);
if (screen.z >= 1.0f) //probably shouldn't show this stuff, it's generally stuff not visible (example in first person, stuff that is behind you)
return;