In my application I have to do like a drawing/painting of a custom polygon. For this purpose as long as the mouse button is pressed and the mouse is moving, the points of the mouse should be saved. After releasing the button the polygon will be painted.
The problem is that the mouse can go over the applications window. This points should be stored as well in order to shrink the whole polygon afterwards to fit in the window.

Now my question:
How can I get the mouse position on the whole screen? And how can I find out wheter the mouse button was released outside the applications window?
Or is there something like a global event filter?