11-22-2024, 04:33 AM
Function FindElmWithColor.
The example script finds the selected item in a folder window.
The example script finds the selected item in a folder window.
var w1 = wnd.find(1, "Test - File Explorer", "CabinetWClass");
w1.Activate();
var list = w1.Elm["LIST", "Items View", "class=DirectUIHWND"].Find(1);
var a = list.Elm["LISTITEM"].FindAll();
int i = C.FindElmWithColor(a, list, 0xCDE8FF);
if (i < 0) { print.it("not found"); return; }
print.it(i, a[i]);
class C {
/// <summary>
/// In elm array finds elm that contains given color or image.
/// </summary>
/// <param name="a"></param>
/// <param name="area">wnd, elm or RECT that contains all elms.</param>
/// <param name="color">Color or image.</param>
/// <returns>0-based index, or -1 if not found.</returns>
/// <remarks>
/// Most parameters are the same as with <see cref="uiimage.find"/>.
/// </remarks>
public static int FindElmWithColor(elm[] a, IFArea area, IFImage color, IFFlags flags = IFFlags.WindowDC, int diff = 0) {
//in area find pixel with color. To create code can be used tool "Find image".
var im1 = uiimage.find(area, color, flags, diff);
if (im1 == null) return -1; //color not found
var rect = im1.RectInScreen;
//in array find elm whose rectangle contains rect
for (int i = 0; i < a.Length; i++) {
if (a[i].Rect.Contains(rect)) return i;
}
return -1;
}
}