handling mouse events in c++

hi folks,
I want to be able to detect mouse cursor position when it's been dragged or pressed(not in any particular window, but on the screen), how can this be done? Can someone provide me with some sample code/links?
any guidance is appreciated