Not to worry - problem solved.
Anyone who encounters the same problem, this is how to convert mouseposx (the mouse coordinates relative to the desktop) into mousex (the mouse coordinates relative to the directx screen):
#include "gui.dba"
startBlue "***","******"
desktop=creategadgetfromwindow(desktopwindow())
desktopwidth=gadgetwidth(desktop)
desktopheight=gadgetheight(desktop)
deletegadget desktop
sw#=screen width()
sh#=screen height()
ratiox#=desktopwidth/sw#
ratioy#=desktopheight/sh#
do
cls
mpx#=mouseposx()
mpy#=mouseposy()
text 0,0,"x:"+str$(mousex())
text 0,20,"y:"+str$(mousey())
text 0,80,"mousex:"+str$(int(mpx#/ratiox#))
text 0,100,"mousey:"+str$(int(mpy#/ratioy#))
loop