I think you are doing it the right way. DirectX is very low-level so it doesn't contain any mouseover functions. You can retrieve the mouse-position using DirectInput but you can also use the default Delphi-Events or WINAPI functions, it doesn't matter. I use the standard delphi events to retrieve mouse coords.

So i guess your code is the way to go. If it works for you, it's OK