Results 1 to 10 of 10

Thread: Get position of a window

  1. #1
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Question Get position of a window

    Porting some really old scripts/code snippets of mine over from SCAR and got hung up on this. Was using api calls at the time in SCAR but that doesn't seem to be available in Simba?

    Poking around at what is available I see there are lots of routines/examples for finding a specific window and getting its width and height, but don't see anything on how to get its position.

    Any ideas on how to accomplish this? Ideally something that uses what is built into Simba and/or SRL without relying on someone's custom plugin that may or may not be maintained in the future.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  2. #2
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    Was using api calls at the time in SCAR but that doesn't seem to be available in Simba?
    Impossible to know. You didn't say which API.

    Quote Originally Posted by Bixby Sayz View Post
    but don't see anything on how to get its position.
    http://docs.villavu.com/simba/script...clientposition

    Quote Originally Posted by Bixby Sayz View Post
    someone's custom plugin that may or may not be maintained in the future.
    I don't think a call to GetClientRect followed by a call to MapWindowPoints would require much maintenance. You could do this in Simba with the same functions if you really wanted, by invoking them directly from the WIN32 API.

  3. #3
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Tried that first. There is one case (that I know of) that it returns the wrong coordinates (looks like height/width rather than left/top): If using SMART it returns incorrect values.

    I was porting over a routine that grabs a client screenshot from the desktop rather than the client itself, which requires knowing the top left position of the window. Just for completeness was attempting to make it work properly when using SMART. That particular use case would likely never come up but it bothers me to leave something incomplete.

    Quote Originally Posted by the bank
    I don't think a call to GetClientRect followed by a call to MapWindowPoints would require much maintenance. You could do this in Simba with the same functions if you really wanted, by invoking them directly from the WIN32 API.
    I will look into that. Thanks.

    Edit: Doesn't appear to work in Simba 1.1; Requires Simba 1.2 perhaps? Too bad that was basically exactly what I was looking for. Just wasn't sure how to invoke WinAPI calls in Simba.

    Edit2: Yup WinAPI calls work fine in Simba 1.2, but not the current version. Now if I could just remember where I saw the post with the link to the Simba 1.2 compatible version of SRL-6.
    Last edited by Bixby Sayz; 05-06-2017 at 11:45 PM.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    Tried that first. There is one case (that I know of) that it returns the wrong coordinates (looks like height/width rather than left/top): If using SMART it returns incorrect values.

    I was porting over a routine that grabs a client screenshot from the desktop rather than the client itself, which requires knowing the top left position of the window. Just for completeness was attempting to make it work properly when using SMART. That particular use case would likely never come up but it bothers me to leave something incomplete.



    I will look into that. Thanks.

    Edit: Doesn't appear to work in Simba 1.1; Requires Simba 1.2 perhaps? Too bad that was basically exactly what I was looking for. Just wasn't sure how to invoke WinAPI calls in Simba.

    Edit2: Yup WinAPI calls work fine in Simba 1.2, but not the current version. Now if I could just remember where I saw the post with the link to the Simba 1.2 compatible version of SRL-6.

    SRL-6 should already work with Simba 1.2 out of the box.
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    SRL-6 should already work with Simba 1.2 out of the box.
    Not true. But for the life of me cannot find the thread with the link to the github repo with the Simba 1.2 compatible SRL-6.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  6. #6
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    Tried that first. There is one case (that I know of) that it returns the wrong coordinates (looks like height/width rather than left/top): If using SMART it returns incorrect values.
    Then you didn't set it as your client properly. http://docs.villavu.com/simba/script...pecific-window

    Quote Originally Posted by Bixby Sayz View Post
    Not true.
    Works for me.

  7. #7
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by the bank View Post
    Then you didn't set it as your client properly. http://docs.villavu.com/simba/script...pecific-window
    I must be doing something wrong. You don't need to set your client when using SMART. And the function you quoted gives the width and height. I have found about 12 different ways to easily get the width and height of a window, but not the (x,y) of the top left corner of the window relative to the desktop when using the SMART client. Easy to do using windows api functions but windows api functions don't work in the current stable client. And SRL-6 completely fails to compile using the dev version of Simba.

    Quote Originally Posted by the bank View Post
    Works for me.
    Again I must be doing something wrong because SRL-6 fails to compile generating tons of compile errors using the dev version of Simba. You using 32-bit windows??? The windows api functions work, but not SRL. SRL works with the stable client but windows api functions don't. And around and around in circles we go lol.

    Edit: Not completely losing my mind at least. There is a branch of SRL-6 that is compatible with the release candidate version of Simba 1.2:https://github.com/SRL/SRL-6/tree/Simba1.2. "main" branch of SRL-6 doesn't work for me on a 64-Bit machine. Now has issues with finding the new version of tesserect but closer to actually getting Simba 1.2 to actually compile something.
    Last edited by Bixby Sayz; 05-07-2017 at 05:48 PM.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  8. #8
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    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.
    Last edited by Citrus; 05-07-2017 at 06:02 PM.

  9. #9
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    I must be doing something wrong. You don't need to set your client when using SMART. And the function you quoted gives the width and height.
    Whenever you see anything with "Client" in it, it's talking about your active target.

  10. #10
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    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;
    Never ever approach a computer saying or even thinking "I will just do this quickly".

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •