Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to delete duplicate windows?
#1
I wrote a function which is to delete duplicate windows with "ABC" in the window text.

It usually works but sometimes the wrong windows are closed (maybe due to spe=0 ? or something else? or coding error? Note I want the function to run as fast as possible)

Is there a simple way to delete duplicate windows quickly with a function?

Thank you in advance

Macro Macro16
Code:
Copy      Help
/ function

ARRAY(str) close
ARRAY(int) a; int i j;str sn sm


win("" "" "" 0 0 0 a)
close.create(a.len)
,

for(i 0 a.len)
,
,sn=""
,sn.getwintext(a[i])
,err
,,out "ERROR getwintext(a[i])"

,for j 0 a.len
,,
,,sm=""
,,sm.getwintext(a[j])
,,err
,,,out "ERROR getwintext(a[j])"
,,,
,,if i<>j and (sn=sm) and (find(sn,"ABC")<>-1) and (close[i]<>"yes")
,,,,
,,,out "duplicate window"
,,,out sn
,,,out sm
,,,close[j]="yes"
,,,

for(i 0 a.len)
,if close[i]="yes"
,,clo a[i]
,,err
,,,out "clo a[i] error"
,,out "duplicate window now closed"

ret
#2
closes duplicate windows containing "Notepad" in name
Macro Macro2693
Code:
Copy      Help
ARRAY(int) a; int i j;str sn sm

win("Notepad" "" "" 0 0 0 a)
for i 1 a.len ;;don't close a[0]
,clo a[i]
,
#3
Thank you but your code will not fix my problem.

if there are 3 windows with the getwintext

"Notepad 1"
"Notepad 1"
"Notepad 2"

Then I would only want to delete only one window with "Notepad 1" in the wintext.

Also I cannot hard code the wintext to match in advance as I do not know all the windows and wintexts in advance so the code must read them all first and perform exact matches on all of the wintext.
#4
Gintaras thank you as always for your excellent help.

I think I solved the problem.

As my macro is running very fast and opening and closing lots of windows very quickly the variable a.len used in the 3 loops in my code was actually not a constant number and was actually changing during the course of executing the loops in the function and so did not work as intended.

The code only works if a.len is a fixed constant number (i.e. no windows opening and closing) during the execution of the function - I run my macros a bit too quickly!

Problem hopefully solved.

Thank you again.
#5
To make faster, at first get all window names into an ARRAY(str) variable, and in the loops use the variable, don't call getwintext. Now your code calls getwintext a.len*a.len times, eg 10000 times for 100 windows.
#6
Thank you I appreciate your good help.


Forum Jump:


Users browsing this thread: 1 Guest(s)