As plouf said, you need to use DesktopScaledX(DesktopWidth(0)) with DPI aware switch on. Doc updated.
Code: Select all
EnableExplicit
Declare TimerProcedure()
Declare check_Screen(flg)
Declare Desktop_Zoomen()
Enumeration
#win
#tgadget
#tgadget1
#timer
EndEnumeration
Global xres,yres,pic1,pic,picgadget1,picgadget2,pcflg,ScreenXres,Screenyres
Global PcFlg, zugross, testzoom ;Tablet oder Handy
testzoom=1
pcflg=1
check_Screen(1)
OpenWindow(#win,0,0,xres,yres,"Window "+Str(xres)+" "+Str(yres))
TextGadget(#tgadget,10,10,200,30,"")
TextGadget(#tgadget1,320,10,200,30,"")
pic=CreateImage(#PB_Any,60,60,32,RGB(200,0,0))
pic1=CreateImage(#PB_Any,60,60,32,RGB(0,200,0))
picgadget1=ImageGadget(#PB_Any,50,yres-ImageHeight(pic)-50,ImageWidth(pic),ImageHeight(pic),ImageID(pic))
picgadget2=ImageGadget(#PB_Any,650,yres-ImageHeight(pic1)-50,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))
AddWindowTimer(#win,#timer,50)
BindEvent(#PB_Event_Timer,@TimerProcedure())
Procedure TimerProcedure()
Protected i,mx,my,gx,gy,gw,gh
If EventTimer()=#timer
SetGadgetText(#tgadget1,"")
mx=WindowMouseX(#win)
my=WindowMouseY(#win)
Define r
!v_r=window.devicePixelRatio
SetGadgetText(#tgadget,"x="+Str(mx)+" y= "+Str(my) + " ratio = "+r)
gx=GadgetX(picgadget1)
gy=GadgetY(picgadget1)
gw=GadgetWidth(picgadget1)
gh=GadgetHeight(picgadget1)
If mx>gx And mx<gx+gw
If my>gy And gy<gy+gh
SetGadgetText(#tgadget1,"Mouse in red box")
EndIf
EndIf
gx=GadgetX(picgadget2)
gy=GadgetY(picgadget2)
gw=GadgetWidth(picgadget2)
gh=GadgetHeight(picgadget2)
If mx>gx And mx<gx+gw
If my>gy And gy<gy+gh
SetGadgetText(#tgadget1,"Mouse in green box")
EndIf
EndIf
EndIf
EndProcedure
Procedure check_Screen(flg)
Protected width,height
If flg=1
Define r
!document.body.style.zoom = 1 / window.devicePixelRatio * 100 + "%"
!v_width=document.body.clientWidth;
!v_height=document.body.clientHeight;
!v_r=window.devicePixelRatio
Debug r
Else
xres=DesktopWidth(0)
yres=DesktopHeight(0)
ProcedureReturn
EndIf
xres=width
yres=height
Debug xres
Debug yres
EndProcedure