Search code examples
c++positiondragarea

Function to retrieve the size of an element


What I need is a function to retrieve the size of an element, be it a Java Applet window in a browser, text boxes in programs, applications window and so on.

Now I don't know what this kind of function is called, but I uploaded an example from an application that had that functionality.

<a href="http://img408.imageshack.us/img408/9638/placementbox.png">Example (The red box)</a>

What I need to be able to with this is get its size and its coordinates on the screen. This needs to be in C++.

So ff anyone could give an example, or atleast the name of that kind of function, I would be grateful.

I found a program that has the function I seek: It is called Scar Divi, which is a scriptable tool to perform repetitive actions, mostly uses for cheating in a game called Runescape it seems. Unfortunately it is closed source.


Solution

  • I found the solution!

    POINT p;
    HWND wnd;
    RECT rec;
    
    GetCursorPos(&p);
    wnd = WindowFromPoint(p);
    GetWindowRect(wnd, &rec);
    

    This will give you the coordinates for the box (extract from rec).