From 58faccf18272fc0d7a5ead98d47fd1f93754298d Mon Sep 17 00:00:00 2001 From: "John P (Dgby714)" Date: Thu, 23 Dec 2010 09:00:57 -0500 Subject: [PATCH 1/2] Simba: TProc, TProcArr, SetTarget, and GetProcesses. --- Units/MMLAddon/PSInc/Wrappers/other.inc | 10 +++++ Units/MMLAddon/PSInc/pscompile.inc | 3 ++ Units/MMLAddon/PSInc/psexportedmethods.inc | 2 + Units/MMLCore/iomanager.pas | 4 +- Units/MMLCore/mufasatypes.pas | 8 ++++ Units/MMLCore/os_linux.pas | 15 ++++++- Units/MMLCore/os_windows.pas | 48 ++++++++++++++++++---- 7 files changed, 81 insertions(+), 9 deletions(-) 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); From 82e1036aa53826c8858919dd98d71c098a26cac4 Mon Sep 17 00:00:00 2001 From: "John P (Dgby714)" Date: Thu, 23 Dec 2010 11:24:18 -0500 Subject: [PATCH 2/2] Simba: TProc(Arr) rename to TSysProc(Arr) --- Units/MMLAddon/PSInc/Wrappers/other.inc | 4 ++-- Units/MMLAddon/PSInc/pscompile.inc | 4 ++-- Units/MMLAddon/PSInc/psexportedmethods.inc | 4 ++-- Units/MMLCore/iomanager.pas | 4 ++-- Units/MMLCore/mufasatypes.pas | 4 ++-- Units/MMLCore/os_linux.pas | 8 ++++---- Units/MMLCore/os_windows.pas | 13 +++++++------ 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Units/MMLAddon/PSInc/Wrappers/other.inc b/Units/MMLAddon/PSInc/Wrappers/other.inc index 2286c93..e0b4f54 100644 --- a/Units/MMLAddon/PSInc/Wrappers/other.inc +++ b/Units/MMLAddon/PSInc/Wrappers/other.inc @@ -285,12 +285,12 @@ begin end; end; -function ps_GetProcesses: TProcArr; +function ps_GetProcesses: TSysProcArr; begin Result := CurrThread.Client.IOManager.GetProcesses; end; -procedure ps_SetTarget(Proc: TProc); +procedure ps_SetTarget(Proc: TSysProc); begin CurrThread.Client.IOManager.SetTargetEx(Proc); end; diff --git a/Units/MMLAddon/PSInc/pscompile.inc b/Units/MMLAddon/PSInc/pscompile.inc index 85d6c56..cf2ab55 100644 --- a/Units/MMLAddon/PSInc/pscompile.inc +++ b/Units/MMLAddon/PSInc/pscompile.inc @@ -65,5 +65,5 @@ 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;'); +AddTypes('TSysProc', 'record Title: string; Handle: integer; Pid: integer; Width, Height: integer; end;'); +AddTypes('TSysProcArr', 'array of TSysProc;'); diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index f7f81f5..4c109c7 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -195,8 +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);'); +AddFunction(@ps_GetProcesses, 'function GetProcesses: TSysProcArr;'); +AddFunction(@ps_SetTarget, 'procedure SetTarget(Proc: TSysProc);'); {$ENDIF} {string} diff --git a/Units/MMLCore/iomanager.pas b/Units/MMLCore/iomanager.pas index b38ad03..03e68d1 100644 --- a/Units/MMLCore/iomanager.pas +++ b/Units/MMLCore/iomanager.pas @@ -317,8 +317,8 @@ interface procedure FreeTarget(idx: integer); procedure SetState(val: Boolean); - function GetProcesses: TProcArr; virtual; abstract; - procedure SetTargetEx(Proc: TProc); virtual; abstract; + function GetProcesses: TSysProcArr; virtual; abstract; + procedure SetTargetEx(Proc: TSysProc); 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 e21cb46..7580d0b 100644 --- a/Units/MMLCore/mufasatypes.pas +++ b/Units/MMLCore/mufasatypes.pas @@ -106,13 +106,13 @@ type x1, y1, x2, y2: Integer; end; - TProc = record + TSysProc = record Title: string; Handle: integer; Pid: integer; Width, Height: integer; end; - TProcArr = array of TProc; + TSysProcArr = array of TSysProc; const TMDTMPointSize = 5*SizeOf(integer)+Sizeof(boolean); diff --git a/Units/MMLCore/os_linux.pas b/Units/MMLCore/os_linux.pas index dba76b1..e202a60 100644 --- a/Units/MMLCore/os_linux.pas +++ b/Units/MMLCore/os_linux.pas @@ -97,8 +97,8 @@ interface function SetTarget(target: TNativeWindow): integer; overload; procedure SetDesktop; override; - function GetProcesses: TProcArr; override; - procedure SetTargetEx(Proc: TProc); overload; + function GetProcesses: TSysProcArr; override; + procedure SetTargetEx(Proc: TSysProc); overload; private procedure NativeInit; override; procedure NativeFree; override; @@ -513,12 +513,12 @@ implementation SetBothTargets(TWindow.Create(display, screennum, target)) end; - function TIOManager.GetProcesses: TProcArr; + function TIOManager.GetProcesses: TSysProcArr; begin raise Exception.Create('GetProcesses: Not Implemented.'); end; - procedure TIOManager.SetTargetEx(Proc: TProc); + procedure TIOManager.SetTargetEx(Proc: TSysProc); begin raise Exception.Create('SetTargetEx: Not Implemented.'); end; diff --git a/Units/MMLCore/os_windows.pas b/Units/MMLCore/os_windows.pas index 99b56ca..e2fd07d 100644 --- a/Units/MMLCore/os_windows.pas +++ b/Units/MMLCore/os_windows.pas @@ -97,8 +97,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; + + function GetProcesses: TSysProcArr; override; + procedure SetTargetEx(Proc: TSysProc); overload; protected DesktopHWND : Hwnd; procedure NativeInit; override; @@ -444,11 +445,11 @@ end; end; threadvar - ProcArr: TProcArr; + ProcArr: TSysProcArr; function EnumProcess(Handle: HWND; Param: LPARAM): WINBOOL; stdcall; var - Proc: TProc; + Proc: TSysProc; I: integer; pPid: DWORD; begin @@ -466,14 +467,14 @@ end; end; end; - function TIOManager.GetProcesses: TProcArr; + function TIOManager.GetProcesses: TSysProcArr; begin SetLength(ProcArr, 0); EnumWindows(@EnumProcess, 0); Result := ProcArr; end; - procedure TIOManager.SetTargetEx(Proc: TProc); + procedure TIOManager.SetTargetEx(Proc: TSysProc); begin SetTarget(Proc.Handle); end;