diff --git a/Units/MMLAddon/PSInc/Wrappers/other.inc b/Units/MMLAddon/PSInc/Wrappers/other.inc index 80b40a7..2286c93 100644 --- a/Units/MMLAddon/PSInc/Wrappers/other.inc +++ b/Units/MMLAddon/PSInc/Wrappers/other.inc @@ -284,3 +284,13 @@ begin mDebugLn('Exception in GetClipBoard: ' + e.message); end; end; + +function ps_GetProcesses: TProcArr; +begin + Result := CurrThread.Client.IOManager.GetProcesses; +end; + +procedure ps_SetTarget(Proc: TProc); +begin + CurrThread.Client.IOManager.SetTargetEx(Proc); +end; diff --git a/Units/MMLAddon/PSInc/pscompile.inc b/Units/MMLAddon/PSInc/pscompile.inc index 0b6e29a..85d6c56 100644 --- a/Units/MMLAddon/PSInc/pscompile.inc +++ b/Units/MMLAddon/PSInc/pscompile.inc @@ -64,3 +64,6 @@ AddTypeS('TSP_Property','(SP_WriteTimeStamp,SP_OnTerminate)'); AddConstantN('mouse_Right','integer').SetInt(ps_mouse_right); //0 AddConstantN('mouse_Left','integer').SetInt(ps_mouse_left);//1 AddConstantN('mouse_Middle','integer').SetInt(ps_mouse_middle);//2 + +AddTypes('TProc', 'record Title: string; Handle: integer; Pid: integer; Width, Height: integer; end;'); +AddTypes('TProcArr', 'array of TProc;'); diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index 2aa055c..f7f81f5 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -195,6 +195,8 @@ AddFunction(@ps_messageBox,'function MessageBox(Text, Caption: string; Flags: Lo AddFunction(@ps_MessageDlg,'function MessageDlg(const Caption, Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons) : integer;'); AddFunction(@ps_SetClipBoard, 'procedure SetClipBoard(const Data: string);'); AddFunction(@ps_GetClipBoard, 'function GetClipBoard: string;'); +AddFunction(@ps_GetProcesses, 'function GetProcesses: TProcArr;'); +AddFunction(@ps_SetTarget, 'procedure SetTarget(Proc: TProc);'); {$ENDIF} {string} diff --git a/Units/MMLCore/iomanager.pas b/Units/MMLCore/iomanager.pas index 78eff7b..b38ad03 100644 --- a/Units/MMLCore/iomanager.pas +++ b/Units/MMLCore/iomanager.pas @@ -316,7 +316,9 @@ interface procedure SetKeyMouseTarget(idx: integer); procedure FreeTarget(idx: integer); procedure SetState(val: Boolean); - + + function GetProcesses: TProcArr; virtual; abstract; + procedure SetTargetEx(Proc: TProc); virtual; abstract; protected function SetImageTarget(target: TTarget): integer; function SetKeyMouseTarget(target: TTarget): integer; diff --git a/Units/MMLCore/mufasatypes.pas b/Units/MMLCore/mufasatypes.pas index 982c153..e21cb46 100644 --- a/Units/MMLCore/mufasatypes.pas +++ b/Units/MMLCore/mufasatypes.pas @@ -106,6 +106,14 @@ type x1, y1, x2, y2: Integer; end; + TProc = record + Title: string; + Handle: integer; + Pid: integer; + Width, Height: integer; + end; + TProcArr = array of TProc; + const TMDTMPointSize = 5*SizeOf(integer)+Sizeof(boolean); type diff --git a/Units/MMLCore/os_linux.pas b/Units/MMLCore/os_linux.pas index f17d0ed..dba76b1 100644 --- a/Units/MMLCore/os_linux.pas +++ b/Units/MMLCore/os_linux.pas @@ -96,6 +96,9 @@ interface constructor Create(plugin_dir: string); function SetTarget(target: TNativeWindow): integer; overload; procedure SetDesktop; override; + + function GetProcesses: TProcArr; override; + procedure SetTargetEx(Proc: TProc); overload; private procedure NativeInit; override; procedure NativeFree; override; @@ -509,5 +512,15 @@ implementation begin SetBothTargets(TWindow.Create(display, screennum, target)) end; - + + function TIOManager.GetProcesses: TProcArr; + begin + raise Exception.Create('GetProcesses: Not Implemented.'); + end; + + procedure TIOManager.SetTargetEx(Proc: TProc); + begin + raise Exception.Create('SetTargetEx: Not Implemented.'); + end; + end. diff --git a/Units/MMLCore/os_windows.pas b/Units/MMLCore/os_windows.pas index 2be3b44..99b56ca 100644 --- a/Units/MMLCore/os_windows.pas +++ b/Units/MMLCore/os_windows.pas @@ -27,7 +27,7 @@ unit os_windows; interface uses - Classes, SysUtils, mufasatypes, windows, graphics, LCLType, bitmaps, IOManager, WinKeyInput; + Classes, SysUtils, mufasatypes, windows, graphics, LCLType, LCLIntf, bitmaps, IOManager, WinKeyInput; type @@ -80,7 +80,7 @@ interface keyinput: TKeyInput; procedure ValidateBuffer(w,h:integer); protected - function WindowRect(out Rect : TRect) : Boolean;virtual; + function WindowRect(out Rect : TRect) : Boolean; virtual; end; { TDesktopWindow } @@ -97,6 +97,8 @@ interface constructor Create(plugin_dir: string); function SetTarget(target: TNativeWindow): integer; overload; procedure SetDesktop; override; + function GetProcesses: TProcArr; override; + procedure SetTargetEx(Proc: TProc); overload; protected DesktopHWND : Hwnd; procedure NativeInit; override; @@ -422,9 +424,9 @@ end; inherited Create(plugin_dir); end; - procedure TIOManager.NativeInit; + procedure TIOManager.NativeInit; begin - self.DesktopHWND:= GetDesktopWindow; + self.DesktopHWND:= GetDesktopWindow; end; procedure TIOManager.NativeFree; @@ -441,6 +443,41 @@ end; SetBothTargets(TWindow.Create(target)); end; + threadvar + ProcArr: TProcArr; + + function EnumProcess(Handle: HWND; Param: LPARAM): WINBOOL; stdcall; + var + Proc: TProc; + I: integer; + pPid: DWORD; + begin + Result := (not ((Handle = 0) or (Handle = null))); + if ((Result) and (IsWindowVisible(Handle))) then + begin + I := Length(ProcArr); + SetLength(ProcArr, I + 1); + ProcArr[I].Handle := Handle; + SetLength(ProcArr[I].Title, 255); + SetLength(ProcArr[I].Title, GetWindowText(Handle, PChar(ProcArr[I].Title), Length(ProcArr[I].Title))); + GetWindowSize(Handle, ProcArr[I].Width, ProcArr[I].Height); + GetWindowThreadProcessId(Handle, pPid); + ProcArr[I].Pid := pPid; + end; + end; + + function TIOManager.GetProcesses: TProcArr; + begin + SetLength(ProcArr, 0); + EnumWindows(@EnumProcess, 0); + Result := ProcArr; + end; + + procedure TIOManager.SetTargetEx(Proc: TProc); + begin + SetTarget(Proc.Handle); + end; + { TDesktopWindow } constructor TDesktopWindow.Create(DesktopHandle: HWND); @@ -450,9 +487,6 @@ begin self.handle:= DesktopHandle; end; - - - function TDesktopWindow.WindowRect(out Rect : TRect) : Boolean; begin Rect.Left:= GetSystemMetrics(SM_XVIRTUALSCREEN);