gluPickMatrix problem

The routine works just fine, but if i add a menu bar or i run the application in windowed mode, the y axis is out of range, i.e. is not anymore 768 pixels (i run the app at 1024x768). I should apply the picking to 768 - menubar y size - window border ? How can i solve this ?
Hope this make sense …