Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSetWindowPosavec un paramètre
Screen.Monitors[2]juste avant l'appel de
OpenDialoget remettre l'écran par défaut après la fin de l'utilisation de
OpenDialog?
unit UWin2Monitor; interface const MONITOR_CENTER = $1; // center rect to monitor MONITOR_CLIP = $0; // clip rect to monitor MONITOR_WORKAREA = $2; // use monitor work area MONITOR_AREA = $0; // use monitor entire area procedure ClipOrCenterWindowToMonitor(hwnd: THandle; flags: Integer); implementation uses Windows, MultiMon, Math; //#include <windows.h> //#include "multimon.h" // // ClipOrCenterRectToMonitor // // The most common problem apps have when running on a // multimonitor system is that they "clip" or "pin" windows // based on the SM_CXSCREEN and SM_CYSCREEN system metrics. // Because of app compatibility reasons these system metrics // return the size of the primary monitor. // // This shows how you use the multi-monitor functions // to do the same thing. // procedure ClipOrCenterRectToMonitor(prc: PRect; flags: Integer); var MonitorRect : TRect; aWidth, aHeight : Integer; aMonitor : hMonitor; mi : MonitorInfo; begin aWidth := prc^.Right - prc^.Left; aHeight := prc^.Bottom - prc^.Top; // get the nearest monitor to the passed rect. MONITOR_DEFAULTTONEAREST // aMonitor := MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST); // // get the work area or entire monitor rect. // mi.cbSize := sizeof(mi); GetMonitorInfo(aMonitor, @mi); if (flags = MONITOR_WORKAREA) then MonitorRect := mi.rcWork else MonitorRect := mi.rcMonitor; // // center or clip the passed rect to the monitor rect // if (flags = MONITOR_CENTER) then begin prc^.left := MonitorRect.left + (MonitorRect.right - MonitorRect.left - aWidth) div 2; prc^.top := MonitorRect.top + (MonitorRect.bottom - MonitorRect.top - aHeight) div 2; prc^.right := prc^.left + aWidth; prc^.bottom := prc^.top + aHeight; end else begin prc^.left := max(MonitorRect.left, min(MonitorRect.right-aWidth, prc^.left)); prc^.top := max(MonitorRect.top, min(MonitorRect.bottom-aHeight, prc^.top)); prc^.right := prc^.left + aWidth; prc^.bottom := prc^.top + aHeight; end; end; procedure ClipOrCenterWindowToMonitor(hwnd: THandle; flags: Integer); var rc : TRect; begin GetWindowRect(hwnd, rc); ClipOrCenterRectToMonitor(@rc, flags); SetWindowPos(hwnd, 0, rc.left, rc.top, 0, 0, SWP_NOSIZE or SWP_NOZORDER or SWP_NOACTIVATE); end; end.
begin with TOpenDialog.Create(nil) do try ClipOrCenterWindowToMonitor(Handle, MONITOR_CENTER); Execute; finally Free; end; end;