简体   繁体   中英

How can I tell what monitor the Delphi IDE Object Inspector is on?

This is a follow up to How can I get the Delphi IDE's Main Form? which I now have working.

I'd like to go one step further and place my designer on the same form as the Object Inspector, for those who use the classic undocked desktop layout and may have the Object Inspector on a different screen than the main Delphi IDE form.

Any ideas on how I find which monitor the Object Inspector is on from inside my design time package?

This should work whether the property inspector is docked or not, since it falls back to the main form for the docked case:

function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Integer; stdcall;
var
  ClassName: string;
  PID: Cardinal;
begin
  Result := 1;
  GetWindowThreadProcessId(hwnd, PID);
  if PID = GetCurrentProcessId then 
  begin
    SetLength(ClassName, 64);
    SetLength(ClassName, GetClassName(hwnd, PChar(ClassName), Length(ClassName)));
    if ClassName = 'TPropertyInspector' then 
    begin
      PHandle(lParam)^ := hwnd;
      Result := 0;
    end;
  end;
end;

function GetPropertyInspectorMonitor: TMonitor;
var
  hPropInsp: HWND;
begin
  hPropInsp := 0;
  EnumWindows(@EnumWindowsProc, LPARAM(@hPropInsp));
  if hPropInsp = 0 then
    hPropInsp := Application.MainFormHandle;
  Result := Screen.MonitorFromWindow(hPropInsp);
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM