""" Utility: Dump control identifiers of on-screen windows. Use this to discover the control identifiers of a dialog we don't have mapped yet — e.g. the drawer-selection box that FCCS shows when you search a base ID that clashes with a longer one (02218 -> 02218A). USAGE ----- 1. In FCCS, get the target screen on-screen (e.g. type the clashing base ID and click Go so the selection box is showing). 2. From another cmd window (with the venv active), run: python fccs_dump_controls.py This lists every visible top-level window and writes the full control identifiers of each to control_dump.txt. To narrow it down, filter by title or class: python fccs_dump_controls.py --title Select python fccs_dump_controls.py --class #32770 3. Open control_dump.txt, find the selection box, and copy its identifiers into the references folder (like references/send_to_file_dialog.txt). Notes: - Run from 32-bit Python (same as the rest of the tool). - Running this from a separate cmd window means the FCCS dialog stays open; this script does not need focus. """ import argparse import sys from pywinauto import Desktop def main(): ap = argparse.ArgumentParser(description=__doc__) ap.add_argument("--title", default=None, help="only dump windows whose title contains this text") ap.add_argument("--class", dest="cls", default=None, help="only dump windows with this exact class name") ap.add_argument("--out", default="control_dump.txt", help="output file (default: control_dump.txt)") args = ap.parse_args() targets = [] for w in Desktop(backend="win32").windows(): try: if not w.is_visible(): continue title = w.window_text() cls = w.class_name() except Exception: continue if args.title and args.title.lower() not in title.lower(): continue if args.cls and args.cls != cls: continue targets.append(w) print(f"Found {len(targets)} matching visible window(s):") for w in targets: print(f" handle={w.handle} class={w.class_name()!r} " f"title={w.window_text()!r}") if not targets: print("Nothing to dump. Is the target window visible? " "Try without filters, or adjust --title/--class.") return with open(args.out, "w", encoding="utf-8") as f: old_stdout = sys.stdout sys.stdout = f try: for w in targets: print("=" * 72) print(f"WINDOW handle={w.handle} class={w.class_name()!r} " f"title={w.window_text()!r}") print("=" * 72) try: w.print_control_identifiers() except Exception as e: print(f" (could not dump this window: {e})") print() finally: sys.stdout = old_stdout print(f"\nControl identifiers written to: {args.out}") if __name__ == "__main__": main()