tags:

views:

257

answers:

1

This is a follow up to http://stackoverflow.com/questions/967327/how-can-i-get-the-delphi-ides-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?

+4  A: 

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;
Craig Peterson
Thanks. What is IDEForm in this context? I don't know the name or have access to the Object Inspector handle. That's the base of my question, how to get a handle to the Object Inspector.
Jeremy Mullin
Sorry, I skimmed your message a bit too quickly. Edited with proper code that will find the property inspector if it's floating and falls back to the main form if it's docked.
Craig Peterson
Thanks Craig, this works well. In the interest of teaching a man to fish... :) I'm interested in how you found out the class name was TPropertyInspector. Did you use a Windows message spy to find the name of the class?
Jeremy Mullin
Yep. I used Winspector (http://www.windows-spy.com).
Craig Peterson
You could also do it the Delphi way, e.g. enumerate Screen.Forms and check ClassNameIs('TPropertyInspector') or use Application.FindComponent('PropertyInspector').
TOndrej