REM RECT and MONITORINFO Structures _MONITOR_DEFAULTTONEAREST = &2 DIM rc{ Left%, Top%, Right%, Bottom% } DIM mi{cbSize%, rcMonitor{} = rc{}, rcWork{} = rc{}, \ \ dwFlags%, szDevice&(31)} mi.cbSize%=DIM(mi{}) REM WINDOWPLACEMENT structure for use with "GetWindowPlacement" DIM wp{length%, flags%, showcmd%, minpos{x%,y%}, \ \ maxpos{x%,y%}, normal{l%,t%,r%,b%}} wp.length% = DIM(wp{}) REM Get the monitor info REM Calculate where to place the picture in dialog box units REM Works with different DPI values SYS "GetWindowPlacement", @hwnd%, wp{} wxpos% = wp.normal.l% wypos% = wp.normal.t% $$device%=mi.szDevice&() monitor$=$$device% monitor%=VAL(RIGHT$(monitor$,1)) REM Calculate the position of the dialog IF monitor%=1 THEN IF wxpos%<(mi.rcMonitor.Right%-mi.rcMonitor.Left%)/2 THEN dxpos%=(mi.rcMonitor.Right%-mi.rcMonitor.Left%)/2-(wxpos%+xsize%/2) ELSE dxpos%=-(wxpos%-((mi.rcMonitor.Right%-mi.rcMonitor.Left%)-xsize%)/2) ENDIF IF wypos%<(mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)/2 THEN dypos%=(mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)/2-(wypos%+ysize%/2) ELSE dypos%=-(wypos%-((mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)-ysize%)/2) ENDIFSYS "MonitorFromWindow",@hwnd%,_MONITOR_DEFAULTTONEAREST \ \ TO hMonitor% SYS "GetMonitorInfo", hMonitor%, mi{} TO ret% IF ret%=0 ERROR 100,"GetMonitorInfo failed" ELSE IF wxpos%<(mi.rcMonitor.Right%-mi.rcMonitor.Left%)/2+mi.rcMonitor.Left% THEN dxpos%=(mi.rcMonitor.Right%-mi.rcMonitor.Left%)/2+mi.rcMonitor.Left%-(wxpos%+xsize%/2) ELSE dxpos%=-(wxpos%-((mi.rcMonitor.Right%-mi.rcMonitor.Left%)+mi.rcMonitor.Left%-xsize%)/2) ENDIF IF wypos%<(mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)/2 THEN dypos%=(mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)/2-(wypos%+ysize%/2) ELSE dypos%=-(wypos%-((mi.rcMonitor.Bottom%-mi.rcMonitor.Top%)-ysize%)/2) ENDIF ENDIF
SYS "MonitorFromWindow",@hwnd%,_MONITOR_DEFAULTTONEAREST \ \ TO hMonitor% SYS "GetMonitorInfo", hMonitor%, mi{} TO ret% IF ret%=0 ERROR 100,"GetMonitorInfo failed"