Originally Posted by
Citrus
Works with Simba 1.1:
Simba Code:
program new;
{$DEFINE SMART}
{$i srl-6/srl.simba}
var
x, y: integer;
procedure getSMARTClientPosition(var left, top: Integer);
var
KMTarget, ITarget, i: Integer;
pp: TSysProcArr;
begin
KMTarget := getKeyMouseTarget();
ITarget := getImageTarget();
pp := client.getIOManager.getProcesses;
for i := 0 to high(pp) do
begin
if pos('SMART', pp[i].title) then
begin
setTarget(pp[i]);
getClientPosition(left, top);
break;
end;
end;
setKeyMouseTarget(KMTarget);
setImageTarget(ITarget);
end;
begin
smartShowConsole := false;
setupSRL();
getSMARTClientPosition(x, y);
writeln(x, ' ', y);
end.
Trying to get client/mouse position won't work with SMART. You have to change the target, get the info, then change it back.
Ty, ty, ty. That worked like a charm. If you are curious this is the final result:
Code:
//-----------------------------------------------------------------------------
// myGetClientBitmapFromDesktopEx()
// 2017-05-08 - Bixby Sayz, Citrus - RS3 Build 880 1
// - Ty to Citrus for finding (x,y) of SMART client window.
//-----------------------------------------------------------------------------
function myGetClientBitmapFromDesktopEx(const captureArea: TBox = ENTIRE_CLIENT): Integer;
var
currentImageClient: Integer; // Current image target.
currentKeyMouseClient: Integer; // Current mouse/keyboard target.
clientPos: TPoint; // Desktop coordinates of client upper left corner.
clientBounds: TBox; // Bounds of client area.
tmpBox: TBox; // Unadjusted area to capture.
actualArea: TBox; // Actual area to capture.
{$IFDEF SMART}
windowList: TSysProcArr; // List of windows.
hiWindowList: Integer; // Size of windows array.
windowIdx: Integer; // Loop counter - Current window.
{$ENDIF}
begin
result := INVALID_BITMAP;
// Validate capture area.
clientBounds := getClientBounds();
if tmpBox.equals(ENTIRE_CLIENT) then
tmpBox := clientBounds
else
tmpBox := captureArea;
tmpBox.normalize();
tmpBox.setLimit(clientBounds);
if tmpBox.equals(INVALID_BOX) then
exit(result);
// Save current targets for later.
currentImageClient := getImageTarget();
currentKeyMouseClient := getKeyMouseTarget();
// Use position of client window on desktop to adjust capture area.
{$IFNDEF SMART}
getClientPosition(clientPos.X, clientPos.Y);
{$ELSE}
windowList := client.getIOManager().getProcesses();
hiWindowList := high(windowList);
for windowIdx := 0 to hiWindowList do
with windowList[windowIdx] do
if (pos('SMART', title) > 0) then
if (pos(intToStr(__smartCurrentPid), title) > 0) then
begin
setTarget(windowList[windowIdx]);
break;
end;
if (windowIdx > hiWindowList) then
exit(result);
getClientPosition(clientPos.X, clientPos.Y);
// Adjust for titlebar.
clientPos.myIncEx(3, 26);
{$ENDIF}
with clientPos do
with tmpBox do
actualArea := IntToBox((X + X1), (Y + Y1), (X + X2), (Y + Y2));
// Set target to desktop and capture client window from desktop. Remember to
// restore original target.
{$IFNDEF SMART}
activateClient();
{$ENDIF}
setDesktopAsClient();
result := bitmapFromClient(actualArea);
setImageTarget(currentImageClient);
setKeyMouseTarget(currentKeyMouseClient);
exit(result);
end;